【发布时间】:2021-12-02 21:26:31
【问题描述】:
我克隆了一个颤振项目,并尝试在安卓设备上运行它。但是我遇到了这个错误:
任务“:app:checkDebugAarMetadata”执行失败。 发生多个任务操作失败: 执行 com.android.build.gradle.internal.tasks.CheckAarMetadataWorkAction 时发生故障 > 指定的 minCompileSdk (31) 依赖项的 AAR 元数据(META-INF/com/android/build/gradle/aar-metadata.properties) 大于此模块的 compileSdkVersion (android-30)。 依赖:androidx.window:window-java:1.0.0-beta04。 AAR 元数据文件:C:\Users\Harshit.gradle\caches\transforms-2\files-2.1\ac98fb722099a50563f635966aedbe29\jetified-window-java-1.0.0-beta04\META-INF\com\android\build\gradle\a ar-metadata.properties。
错误提示当前compileSdkVersion是30,但是有些依赖只对31有效。
所以,我只是在我的应用级 build.gradle 中将 compileSdkVersion 和 targetSdkVersion 从 30 更改为 31,然后我尝试再次运行它,但又遇到了另一个错误:
任务:location:compileDebugKotlin e:在依赖项中发现不兼容的类。从类路径中删除它们或使用“-Xskip-metadata-version-check”来抑制错误 e: C:/Users/Harshit/.gradle/caches/transforms-2/files-2.1/1028a8ca100cbb0fda6fd6257a450fc1/jetified-window-1.0.0-beta04-api.jar!/META-INF/window_release.kotlin_module: 模块已编译使用不兼容的 Kotlin 版本。其元数据的二进制版本是 1.5.1,预期版本是 1.1.15。
在谷歌快速搜索后,我找到了一个修复,我需要在 android/build.gradle 文件中提及最新的 kotlin 版本,所以我改变了这个:
ext.kotlin_version = '1.3.50'
到这里:
ext.kotlin_version = '1.6.0'
并下载了相应的 kotlin 插件。然后我再次尝试运行项目,却遇到了这个错误:
任务“:google_maps_flutter:checkDebugUnitTestAarMetadata”执行失败。 发生多个任务操作失败: 执行 com.android.build.gradle.internal.tasks.CheckAarMetadataWorkAction 时发生故障 > 指定的 minCompileSdk (31) 依赖项的 AAR 元数据(META-INF/com/android/build/gradle/aar-metadata.properties) 大于此模块的 compileSdkVersion (android-29)。 依赖:androidx.window:window-java:1.0.0-beta04。 AAR 元数据文件:C:\Users\Harshit.gradle\caches\transforms-2\files-2.1\9d7a6c54f576894d03496d57f9d5a318\jetified-window-java-1.0.0-beta04\META-INF\com\android\build\gradle\a ar-metadata.properties。
这个错误和第一个错误是一样的,只是这里提到了当前的compileSdkVersion是29,尽管我在设置为31之后并没有改变它。
所以,出于某种原因,升级 kotlin 的版本会导致 compileSdkVersin 自动设置为 29,我不知道为什么。
我怎样才能摆脱这个错误,即当前的 compileSdkVersion 是 29,即使我将它设置为 31?
为什么更改 kotlin 版本会欺骗它相信 compileSdkVersion 是 29,即使它的值在 build.gradle 中设置为 31?
android/build.gradle:
buildscript {
ext.kotlin_version = '1.6.0'
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:4.1.0'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath 'com.google.gms:google-services:4.3.8'
}
}
allprojects {
repositories {
google()
jcenter()
}
}
rootProject.buildDir = '../build'
subprojects {
project.buildDir = "${rootProject.buildDir}/${project.name}"
project.evaluationDependsOn(':app')
}
task clean(type: Delete) {
delete rootProject.buildDir
}
app/build.gradle:
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"
android {
compileSdkVersion 31
sourceSets {
main.java.srcDirs += 'src/main/kotlin'
}
defaultConfig {
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
applicationId "com.pranshupandya.locus_stalker"
minSdkVersion 20
targetSdkVersion 31
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
multiDexEnabled true
}
buildTypes {
release {
// TODO: Add your own signing config for the release build.
// Signing with the debug keys for now, so `flutter run --release` works.
signingConfig signingConfigs.debug
}
}
}
flutter {
source '../..'
}
dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation platform('com.google.firebase:firebase-bom:28.2.0')
implementation 'com.google.firebase:firebase-analytics'
def multidex_version = "2.0.1"
implementation "androidx.multidex:multidex:$multidex_version"
}
apply plugin: 'com.google.gms.google-services'
【问题讨论】:
标签: android flutter kotlin gradle