我刚刚更新了我的flutter项目包,使其符合零安全标准,现在Android希望我更新我的项目,以使用Kotling Gradle插件的最新版本。不过,我看不出该把它改在哪里。我试图将"org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
转换为"org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.6.10"
,但这没有任何效果。
我的build.grade
-file看起来如下:
def localProperties = new Properties()
def localPropertiesFile = rootProject.file('local.properties')
if (localPropertiesFile.exists()) {
localPropertiesFile.withReader('UTF-8') { reader ->
localProperties.load(reader)
}
}
def flutterRoot = localProperties.getProperty('flutter.sdk')
if (flutterRoot == null) {
throw new GradleException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.")
}
def flutterVersionCode = localProperties.getProperty('flutter.versionCode')
if (flutterVersionCode == null) {
flutterVersionCode = '1'
}
def flutterVersionName = localProperties.getProperty('flutter.versionName')
if (flutterVersionName == null) {
flutterVersionName = '1.0'
}
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"
def keystoreProperties = new Properties()
def keystorePropertiesFile = rootProject.file('key.properties')
if (keystorePropertiesFile.exists()) {
keystoreProperties.load(new FileInputStream(keystorePropertiesFile))
}
android {
compileSdkVersion 31
sourceSets {
main.java.srcDirs += 'src/main/kotlin'
}
lintOptions {
disable 'InvalidPackage'
}
defaultConfig {
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
applicationId "*********"
minSdkVersion 30
targetSdkVersion 30
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
signingConfigs {
release {
keyAlias keystoreProperties['keyAlias']
keyPassword keystoreProperties['keyPassword']
storeFile keystoreProperties['storeFile'] ? file(keystoreProperties['storeFile']) : null
storePassword keystoreProperties['storePassword']
}
}
buildTypes {
release {
signingConfig signingConfigs.release
}
}
}
flutter {
source '../..'
}
dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'
implementation 'com.google.firebase:firebase-analytics:17.2.2'
}
apply plugin: 'com.google.gms.google-services'
生成输出:
BUILD FAILED in 8s
[!] Your project requires a newer version of the Kotlin Gradle plugin.
Find the latest version on https://kotlinlang.org/docs/gradle.html#plugin-and-versions, then update project/android/build.gradle:
ext.kotlin_version = '<latest-version>'
Exception: Gradle task assembleDebug failed with exit code 1
发布于 2022-01-30 22:06:36
您需要更改android根项目projectName/android/build.gradle
中的kotlin版本,而不是projectName/android/app/build.gradle
。
更改ext.kotlin_version
行的版本:
buildscript {
ext.kotlin_version = '1.6.10' // Change here
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:4.1.0'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
更新
如果项目的android部分使用java,而依赖项使用kotlin,并且遇到以下错误,上述解决方案也会有效:
Incompatible classes were found in dependencies. Remove them from the classpath or use '-Xskip-metadata-version-check' to suppress errors
e: /home/user/.gradle/caches/transforms-3/36814238b86d8b6b6f9e4e1263bce879/transformed/jetified-kotlinx-coroutines-core-jvm-1.5.2.jar!/META-INF/kotlinx-coroutines-core.kotlin_module:
Module was compiled with an incompatible version of Kotlin.
The binary version of its metadata is 1.5.1, expected version is 1.1.15.
AndroidStudio或IntelliJ Idea将在项目build.grade
文件中给出提示,如果kotlin与在IDE中安装的kotlin不相同的话。
发布于 2022-03-01 09:20:10
将您的Kotlin更新为最新版本。您可以在这里看到最新版本。
ext.kotlin_version = '1.6.10' //
您可以从下面的链接https://kotlinlang.org/docs/gradle.html#plugin-and-versions中看到Kotlin的最新版本
发布于 2022-01-30 21:52:39
对此更改:
classpath 'com.android.tools.build:gradle:4.1.0'
然后把它包装起来:
distributionUrl=https\://services.gradle.org/distributions/gradle-6.7.1-bin.zip
https://stackoverflow.com/questions/70919127
复制相似问题