androidactivity-lifecycle

After update lifecyle to version 2.4.0 Make build error AAR metadata file: **/aar-metadata.properties


After update lifecycle version to 2.4.0 i cant build my app the error code is :

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.

added this code but its not work for me

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

Solution

  • Change compileSdk to 31 and targetSdk 31

    if use AGP 7.* or above

    android {
        compileSdk 30
    
        defaultConfig {
            ...
            targetSdk 30
            ...
        }
        ...
    }
    

    if use AGP Below 7

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