我正在开发一个 Flutter 项目,并且面临与 Kotlin 版本相关的问题。当我尝试构建项目时,收到以下错误消息,指示 Kotlin 模块之间的版本不匹配:
e: C:/Users/digit/.gradle/caches/transforms-3/431ce31617111116ed092b20fb775fda/transformed/jetified-kotlin-stdlib-1.9.0.jar!/META-INF/kotlin-stdlib-jdk7.kotlin_module: Module was compiled with an incompatible version of Kotlin. The binary version of its metadata is 1.9.0, expected version is 1.7.1.
e: C:/Users/digit/.gradle/caches/transforms-3/431ce31617111116ed092b20fb775fda/transformed/jetified-kotlin-stdlib-1.9.0.jar!/META-INF/kotlin-stdlib-jdk8.kotlin_module: Module was compiled with an incompatible version of Kotlin. The binary version of its metadata is 1.9.0, expected version is 1.7.1.
e: C:/Users/digit/.gradle/caches/transforms-3/431ce31617111116ed092b20fb775fda/transformed/jetified-kotlin-stdlib-1.9.0.jar!/META-INF/kotlin-stdlib.kotlin_module: Module was compiled with an incompatible version of Kotlin. The binary version of its metadata is 1.9.0, expected version is 1.7.1.
e: C:/Users/digit/.gradle/caches/transforms-3/6327b6d5cbee3dd5c434505ea5de9c0a/transformed/jetified-firebase-analytics-ktx-22.0.1-api.jar!/META-INF/java.com.google.android.libraries.firebase.firebase_analytics_ktx_granule.kotlin_module: Module was compiled with an incompatible version of Kotlin. The binary version of its metadata is 1.9.0, expected version is 1.7.1.
e: C:/Users/digit/.gradle/caches/transforms-3/648640f83817e7438e3934ba83addfe2/transformed/jetified-play-services-measurement-api-22.0.1-api.jar!/META-INF/java.com.google.android.gmscore.integ.client.measurement_api_measurement_api.kotlin_module: Module was compiled with an incompatible version of Kotlin. The binary version of its metadata is 1.9.0, expected version is 1.7.1.
e: C:/Users/digit/.gradle/caches/transforms-3/c321e7444a5c731da2398570d6ef04f1/transformed/jetified-kotlin-stdlib-common-1.9.0.jar!/META-INF/kotlin-stdlib-common.kotlin_module: Module was compiled with an incompatible version of Kotlin. The binary version of its metadata is 1.9.0, expected version is 1.7.1.
t
此外,我收到此消息,表明需要更新版本的 Kotlin Gradle 插件:
[!] Your project requires a newer version of the Kotlin Gradle plugin.
Find the latest version on https://kotlinlang.org/docs/releases.html#release-details, then update C:\Users\digit\Documents\flutter projects\android\build.gradle:
ext.kotlin_version = '<latest-version>'
我当前的设置 以下是我的 android/build.gradle 和 android/app/build.gradle 文件的相关部分:
android/build.gradle:
buildscript {
ext.kotlin_version = '1.9.0' // Updated to the latest version
repositories {
google()
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:7.4.2' // Updated Gradle Plugin
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath 'com.google.gms:google-services:4.4.2'
classpath 'com.google.dagger:hilt-android-gradle-plugin:2.44'
}
}
allprojects {
repositories {
google()
mavenCentral()
}
}
rootProject.buildDir = '../build'
subprojects {
project.buildDir = "${rootProject.buildDir}/${project.name}"
}
subprojects {
project.evaluationDependsOn(':app')
}
tasks.register("clean", Delete) {
delete rootProject.buildDir
}
android/app/build.gradle:
plugins {
id 'com.android.application'
id 'kotlin-android'
id 'kotlin-kapt'
id 'com.google.gms.google-services'
id 'com.google.dagger.hilt.android'
id 'dev.flutter.flutter-gradle-plugin'
}
def localProperties = new Properties()
def localPropertiesFile = rootProject.file("local.properties")
if (localPropertiesFile.exists()) {
localPropertiesFile.withReader("UTF-8") { reader ->
localProperties.load(reader)
}
}
def flutterVersionCode = localProperties.getProperty("flutter.versionCode")
if (flutterVersionCode == null) {
flutterVersionCode = "1"
}
def flutterVersionName = localProperties.getProperty("flutter.versionName")
if (flutterVersionName == null) {
flutterVersionName = "1.0"
}
android {
namespace = "com.muhasebepro.muhasebe_pro_finall"
compileSdkVersion 34
ndkVersion = flutter.ndkVersion
compileOptions {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}
defaultConfig {
applicationId "com.muhasebepro.muhasebe_pro_finall"
minSdkVersion 24
targetSdkVersion 34
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
}
buildTypes {
release {
signingConfig signingConfigs.debug
}
}
}
flutter {
source = '../..'
}
dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
implementation platform('com.google.firebase:firebase-bom:31.2.3')
implementation 'com.google.firebase:firebase-analytics-ktx'
implementation 'com.google.dagger:hilt-android:2.44'
kapt 'com.google.dagger:hilt-compiler:2.44'
}
apply plugin: 'kotlin-kapt'
我尝试过的步骤 在 android/build.gradle 中将 Kotlin 版本更新为 1.9.0。 确保所有依赖项使用相同的 Kotlin 版本。 使用 flutter clean 和 flutter pub get 清理并重建项目。
请求 如何解决此版本不匹配问题并确保所有模块使用相同的 Kotlin 兼容版本?
我的尝试和期望 我正在做一个 Flutter 项目,在构建过程中遇到了与 Kotlin 版本相关的问题。这是我到目前为止所尝试过的:
更新了 Kotlin 版本:按照错误消息的建议,我在 android/build.gradle 文件中将 Kotlin 版本更新为 1.9.0。 同步依赖项:我确保 build.gradle 文件中的所有依赖项都使用相同版本的 Kotlin。 清理并重建项目:我使用 flutter clean 和 flutter pub get 再次清理并获取依赖项,希望能够解决任何冲突。 检查重复的依赖关系:我确认不存在可能导致冲突的重复依赖关系。
您可以尝试强制所有包使用相同的 kotlin 版本。
只需将以下内容添加到您的 app/build.gradle 中,就在应用插件之前和依赖项之后。
configurations.all {
resolutionStrategy { force 'androidx.core:core-ktx:1.13.1' }
}