kotlin版本升级为190 gradle的配置要怎么写
Kotlin版本升级到1.9.0后,Gradle的配置需要进行相应的更新。下面是一个示例的Gradle配置文件:
buildscript {
ext.kotlin_version = '1.9.0'
repositories {
google()
jcenter()
}
dependencies {
classpath "com.android.tools.build:gradle:7.0.0"
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
plugins {
id 'com.android.application'
id 'kotlin-android'
}
android {
compileSdkVersion 30
buildToolsVersion "30.0.3"
defaultConfig {
applicationId "com.example.myapp"
minSdkVersion 21
targetSdkVersion 30
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
kotlinOptions {
jvmTarget = "1.8"
}
}
dependencies {
implementation "androidx.appcompat:appcompat:1.3.1"
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
// 添加其他依赖项...
}
请注意,上述配置中的ext.kotlin_version变量指定了Kotlin的版本号为1.9.0。在dependencies部分,我们在implementation行中使用了Kotlin标准库的相应版本。
此外,还需要更新Android Gradle插件的版本为7.0.0,以支持新的Kotlin版本。在buildscript部分的dependencies中添加了相应的依赖项。
最后,为了确保与新的Kotlin版本兼容,我们在android部分的kotlinOptions中将jvmTarget设置为1.8。
记得在升级版本之前备份你的代码和配置文件,以防出现问题。
原文地址: https://www.cveoy.top/t/topic/i9jR 著作权归作者所有。请勿转载和采集!