检查 AAR 元数据值时发现的一个或多个问题:

Posted

技术标签:

【中文标题】检查 AAR 元数据值时发现的一个或多个问题:【英文标题】:One or more issues found when checking AAR metadata values: 【发布时间】:2021-12-24 20:08:28 【问题描述】:

嘿,我正在尝试运行我的应用程序并收到此错误

build.gradle

plugins 
    id 'com.android.application'
    id 'kotlin-android'
    id 'kotlin-kapt'


android 
    compileSdk 30

    configurations.all 
        resolutionStrategy  force 'androidx.core:core-ktx:1.7.0-alpha01' 
    

    defaultConfig 

        applicationId "com.example.listadapter"
        minSdk 21
        targetSdk 30
        versionCode 1
        versionName "1.0"

        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    

    buildTypes 
        release 
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        
    
    compileOptions 
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    
    kotlinOptions 
        jvmTarget = '1.8'
    

    buildFeatures 
        viewBinding true
    


dependencies 

    implementation 'androidx.core:core-ktx:1.7.0'
    implementation 'androidx.appcompat:appcompat:1.3.1'
    implementation 'com.google.android.material:material:1.4.0'
    implementation 'androidx.constraintlayout:constraintlayout:2.1.1'
    testImplementation 'junit:junit:4.+'
    androidTestImplementation 'androidx.test.ext:junit:1.1.3'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'

    implementation "com.squareup.retrofit2:converter-moshi:2.5.0"
    implementation 'com.squareup.okhttp3:logging-interceptor:4.9.1'
    implementation 'com.squareup.retrofit2:retrofit:2.9.0'

    implementation "com.squareup.moshi:moshi:1.12.0"
    implementation "com.squareup.moshi:moshi-kotlin:1.12.0"

    implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:2.4.0"
    implementation "androidx.lifecycle:lifecycle-livedata-ktx:2.4.0"
    implementation "androidx.lifecycle:lifecycle-runtime-ktx:2.4.0"
    implementation "android.arch.lifecycle:extensions:1.1.1"
    implementation 'androidx.fragment:fragment-ktx:1.3.6'

我从link 尝试了这个所有示例,它不起作用

安装应用程序后出现错误。我刚刚创建了一个新应用程序。我不明白为什么会这样。有谁知道如何解决这个问题?提前致谢。

One or more issues found when checking AAR metadata values:

The minCompileSdk (31) specified in a
dependency's AAR metadata (META-INF/com/android/build/gradle/aar-metadata.properties)
is greater than this module's compileSdkVersion (android-30).
Dependency: androidx.lifecycle:lifecycle-viewmodel-ktx:2.4.0.
AAR metadata file: /Users/vmodi/.gradle/caches/transforms-3/b7f9608e476cb2e496993f185af8912c/transformed/jetified-lifecycle-viewmodel-ktx-2.4.0/META-INF/com/android/build/gradle/aar-metadata.properties.

The minCompileSdk (31) specified in a
dependency's AAR metadata (META-INF/com/android/build/gradle/aar-metadata.properties)
is greater than this module's compileSdkVersion (android-30).
Dependency: androidx.lifecycle:lifecycle-runtime-ktx:2.4.0.
AAR metadata file: /Users/vmodi/.gradle/caches/transforms-3/538fea46e89a6c8a3e3eec533224abb8/transformed/jetified-lifecycle-runtime-ktx-2.4.0/META-INF/com/android/build/gradle/aar-metadata.properties.

The minCompileSdk (31) specified in a
dependency's AAR metadata (META-INF/com/android/build/gradle/aar-metadata.properties)
is greater than this module's compileSdkVersion (android-30).
Dependency: androidx.lifecycle:lifecycle-livedata-ktx:2.4.0.
AAR metadata file: /Users/vmodi/.gradle/caches/transforms-3/6a1f77e99280b09902894e4ae8301047/transformed/jetified-lifecycle-livedata-ktx-2.4.0/META-INF/com/android/build/gradle/aar-metadata.properties.

The minCompileSdk (31) specified in a
dependency's AAR metadata (META-INF/com/android/build/gradle/aar-metadata.properties)
is greater than this module's compileSdkVersion (android-30).
Dependency: androidx.lifecycle:lifecycle-viewmodel:2.4.0.
AAR metadata file: /Users/vmodi/.gradle/caches/transforms-3/41cf6125c3fd7a33d28222cf07d20520/transformed/lifecycle-viewmodel-2.4.0/META-INF/com/android/build/gradle/aar-metadata.properties.

The minCompileSdk (31) specified in a
dependency's AAR metadata (META-INF/com/android/build/gradle/aar-metadata.properties)
is greater than this module's compileSdkVersion (android-30).
Dependency: androidx.lifecycle:lifecycle-runtime:2.4.0.
AAR metadata file: /Users/vmodi/.gradle/caches/transforms-3/655163560a267a5b16e2f66044d78641/transformed/lifecycle-runtime-2.4.0/META-INF/com/android/build/gradle/aar-metadata.properties.

The minCompileSdk (31) specified in a
dependency's AAR metadata (META-INF/com/android/build/gradle/aar-metadata.properties)
is greater than this module's compileSdkVersion (android-30).
Dependency: androidx.lifecycle:lifecycle-livedata:2.4.0.
AAR metadata file: /Users/vmodi/.gradle/caches/transforms-3/1ca84d966e72f2f06b580da1765a55a5/transformed/lifecycle-livedata-2.4.0/META-INF/com/android/build/gradle/aar-metadata.properties.

The minCompileSdk (31) specified in a
dependency's AAR metadata (META-INF/com/android/build/gradle/aar-metadata.properties)
is greater than this module's compileSdkVersion (android-30).
Dependency: androidx.lifecycle:lifecycle-livedata-core-ktx:2.4.0.
AAR metadata file: /Users/vmodi/.gradle/caches/transforms-3/3ed4d52253be7f6d85cbabee72c886d3/transformed/jetified-lifecycle-livedata-core-ktx-2.4.0/META-INF/com/android/build/gradle/aar-metadata.properties.

The minCompileSdk (31) specified in a
dependency's AAR metadata (META-INF/com/android/build/gradle/aar-metadata.properties)
is greater than this module's compileSdkVersion (android-30).
Dependency: androidx.lifecycle:lifecycle-livedata-core:2.4.0.
AAR metadata file: /Users/vmodi/.gradle/caches/transforms-3/4e8a32482e233cfbbc450e03aabed8dd/transformed/lifecycle-livedata-core-2.4.0/META-INF/com/android/build/gradle/aar-metadata.properties.

如果我更改我的compileSdk 31,它会给我另一个错误。

Could not resolve all files for configuration ':app:androidApis'.
Failed to transform android.jar to match attributes artifactType=android-mockable-jar, org.gradle.libraryelements=jar, org.gradle.usage=java-runtime, returnDefaultValues=false.
Execution failed for MockableJarTransform: /Users/vmodi/Library/Android/sdk/platforms/android-31/android.jar.
Cannot create mockable android.jar
/Users/vmodi/Library/Android/sdk/platforms/android-31/android.jar

【问题讨论】:

你能显示Project level build.gradle文件吗? 【参考方案1】:

将您的 compileSdk 30 更改为 31。

它对我有用!

   compileSdk 31

    defaultConfig 
        applicationId "com.example.lifecycle"
        minSdk 21
        targetSdk 30
        versionCode 1
        versionName "1.0"

        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    

【讨论】:

【参考方案2】:

compileSdk 和 targetSdk 都应该是 31。你试过了吗?

【讨论】:

正如目前所写,您的答案尚不清楚。请edit 添加其他详细信息,以帮助其他人了解这如何解决所提出的问题。你可以找到更多关于如何写好答案的信息in the help center。【参考方案3】:

这是因为您刚刚升级了 Kotlin。

打开SDK Manager,安装Android 12(API 31)或以上,然后将compileSdkVersion改为31(或以上),将targetSdkVersion改为31(或以上)。

那么你还需要将 minSdkVersion 更改为 19。

【讨论】:

【参考方案4】:

依赖:androidx.lifecycle:lifecycle-runtime-ktx:2.4.0。 问题在于这种依赖关系,可能存在一些传递依赖错误。我建议使用此依赖项的 alpha 版本,对我有用。 替换成这个依赖:androidx.lifecycle:lifecycle-*:2.4.0-alpha03

【讨论】:

以上是关于检查 AAR 元数据值时发现的一个或多个问题:的主要内容,如果未能解决你的问题,请参考以下文章

尝试构建默认 Android Studio 应用时出错

如何解决本机 Java 或 Kotlin 中的错误“在依赖项的 AAR 元数据中指定的 minCompileSdk (31)”? [复制]

用于 Java .aar 文件的 Xamarin Android 元数据

四元数绕轴旋转的分量

数据库笛卡尔积

将元数据传递给自定义损失函数