Compose和kotlin版本对应关系:https://androidx.dev/storage/compose-compiler/repository
gradle版本和gradle插件版本对应关系:
https://developer.android.google.cn/studio/releases/gradle-plugin?hl=zh-cn
gradle最新版本在这里找:https://services.gradle.org/distributions/
第三方库依赖库版本在这里找:https://mvnrepository.com/
在File -> Project Structure这里都可以看到并配置gradle版本、gradle插件版本和kotlin版本
最初环境
classpath ‘com.android.tools.build:gradle:4.2.1’
distributionUrl=https://services.gradle.org/distributions/gradle-6.7.1-bin.zip
org.jetbrains.kotlin:kotlin-gradle-plugin:1.6.10
-> 环境升级
classpath ‘com.android.tools.build:gradle:7.0.2’
distributionUrl=https://services.gradle.org/distributions/gradle-7.0.2-bin.zip
org.jetbrains.kotlin:kotlin-gradle-plugin:1.6.10(1.7.10)(1.9.0)
修改内容:
之前maven仓库链接可以是http的,升级之后必须是https的
kotlin版本升级到1.7.10:修改两个地方:1.when() 添加branch 2.空安全处理
kotlin1.7.10升级到1.9.0:修改一个地方:
kotlinx.android.synthetic.** 这种通过 apply plugin: ‘kotlin-android-extensions’ 方式(插件)不能使用了
-> 环境升级
classpath ‘com.android.tools.build:gradle:7.1.0’
distributionUrl=https://services.gradle.org/distributions/gradle-7.2-bin.zip
org.jetbrains.kotlin:kotlin-gradle-plugin:1.9.0
思路方法:
gradlew compileDebugSource –stacktrace -info 命令查看解决方法
通过Upgrade Assistant 升级gradle插件(AGP)
修改内容:
sourceCompatibility JavaVersion.VERSION_11
compileSdkVersion 30
空安全处理
Gradle JDK成 11版本
-> 环境升级
classpath ‘com.android.tools.build:gradle:7.4.2’
distributionUrl=https://services.gradle.org/distributions/gradle-7.5-bin.zip
org.jetbrains.kotlin:kotlin-gradle-plugin:1.9.0
修改内容:
compileSdkVersion 31
类重复Duplicate class androidx.lifecycle.ViewModelLazy found in modules
Duplicate class androidx.lifecycle.ViewModelProviderKt found in modules
修改
configurations {
all {
exclude group: ‘androidx.lifecycle’, module: ‘lifecycle-viewmodel-ktx’
}
}
-> 环境升级
classpath ‘com.android.tools.build:gradle:8.0.0’
distributionUrl=https://services.gradle.org/distributions/gradle-8.0-bin.zip
org.jetbrains.kotlin:kotlin-gradle-plugin:1.9.0
修改内容:
namespace 每个module都要有namespace
org.greenrobot:greendao-gradle-plugin由3.3.0升级到3.3.1
Gradle JDK成 17版本
这个报错提示task (current target is 17) jvm target compatibility should be set to the same Java version
修改
module 的build.gradle修改
compileOptions {
sourceCompatibility JavaVersion.VERSION_17
targetCompatibility JavaVersion.VERSION_17
}
kotlinOptions {
jvmTarget = ‘17’
}
…????????????????????
-> 环境升级
classpath ‘com.android.tools.build:gradle:8.2.0-alpha10’
distributionUrl=https://services.gradle.org/distributions/gradle-8.2-bin.zip
org.jetbrains.kotlin:kotlin-gradle-plugin:1.9.0
新版本gradle的变化调整:
https://blog.csdn.net/sinat_38167329/article/details/123175556
https://developer.android.google.cn/studio/build/migrate-to-catalogs?hl=zh-cn
https://juejin.cn/post/7160337743552675847
https://juejin.cn/post/7222529227676385336
plugins {
id ‘com.android.application’ version ‘8.2.0-alpha10’ apply false
id ‘com.android.library’ version ‘8.2.0-alpha10’ apply false
id ‘org.jetbrains.kotlin.android’ version ‘1.9.0’ apply false
}
plugins {
alias(libs.plugins.androidApplication) apply false
alias(libs.plugins.kotlinAndroid) apply false
}