You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在Android Studio中将Kotlin从1.7.20降级至1.6.10以支持Compose 1.1.1

手动降级Kotlin至1.6.10适配Compose 1.1.1

直接通过修改Gradle配置文件完成降级,这是最可靠的操作方式:

1. 修改项目根目录的build.gradle(或build.gradle.kts)

找到Kotlin版本配置项,将其改为1.6.10,同时同步匹配Compose编译器版本:

Groovy语法示例:

buildscript {
    ext {
        kotlin_version = "1.6.10"
        compose_compiler_version = "1.1.1" // 与Compose 1.1.1强制匹配
    }
    dependencies {
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
        // ...其他插件依赖
    }
}

Kotlin DSL语法示例:

buildscript {
    extra["kotlin_version"] = "1.6.10"
    extra["compose_compiler_version"] = "1.1.1"
    dependencies {
        classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:${extra["kotlin_version"]}")
        // ...其他插件依赖
    }
}

2. 修改模块目录的build.gradle(或build.gradle.kts)

确保模块内Kotlin插件版本与项目根配置一致,同时锁定Compose核心依赖版本:

Groovy语法示例:

plugins {
    id 'com.android.application'
    id 'kotlin-android'
}

android {
    buildFeatures {
        compose true
    }
    composeOptions {
        kotlinCompilerExtensionVersion compose_compiler_version
    }
}

dependencies {
    // 固定Compose核心依赖版本为1.1.1
    implementation 'androidx.compose.ui:ui:1.1.1'
    implementation 'androidx.compose.material:material:1.1.1'
    // ...其他Compose依赖
}

Kotlin DSL语法示例:

plugins {
    id("com.android.application")
    id("kotlin-android")
}

android {
    buildFeatures {
        compose = true
    }
    composeOptions {
        kotlinCompilerExtensionVersion = extra["compose_compiler_version"].toString()
    }
}

dependencies {
    implementation("androidx.compose.ui:ui:1.1.1")
    implementation("androidx.compose.material:material:1.1.1")
    // ...其他Compose依赖
}

3. 同步并验证

  • 点击Android Studio右上角的Sync Now按钮,等待项目同步完成
  • 若同步出现缓存异常,执行File -> Invalidate Caches... -> Invalidate and Restart重启IDE

额外注意点

  • 所有模块(包括library模块)的Kotlin版本必须统一,避免版本冲突
  • 若项目使用Kotlin附属插件(如Serialization),需同步降级到适配1.6.10的版本(例如org.jetbrains.kotlin.plugin.serialization:1.6.10)

内容的提问来源于stack exchange,提问作者Ajay Prajapati

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.09 21:45:29