首页 > 解决方案 > 将生命周期更新到版本 2.4.0 后生成错误 AAR 元数据文件:**/aar-metadata.properties

问题描述

将生命周期版本更新到 2.4.0 后,我无法构建我的应用程序,错误代码是:

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: **/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-livedata-ktx:2.4.0.
AAR metadata file: **/transformed/jetified-lifecycle-livedata-ktx-2.4.0/META-INF/com/android/build/gradle/aar-metadata.properties.

添加了此代码,但对我不起作用

configurations.all {
        resolutionStrategy { force 'androidx.core:core-ktx:1.6.0' }
    }

标签: androidactivity-lifecycle

解决方案


将 compileSdk 更改为 31 和 targetSdk 31

如果使用 AGP 7.* 或更高版本

android {
    compileSdk 30

    defaultConfig {
        ...
        targetSdk 30
        ...
    }
    ...
}

如果使用 AGP 低于 7

android {
    compileSdkVersion 30
   
    defaultConfig {
        ...
        targetSdkVersion 30
        ...
    }
}

推荐阅读