[Flutter] - build error : app:checkDebugAarMetadata


flutter 버전을 한번 올리고 2.5.3으로 개발을 진행하던중 아래와 같은 에러를 만나게 되었다.

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:checkDebugAarMetadata'.
> Multiple task action failures occurred:
   > A failure occurred while executing com.android.build.gradle.internal.tasks.CheckAarMetadataWorkAction
      > 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-beta01.
        AAR metadata file: /Users/teddy/.gradle/caches/transforms-2/files-2.1/91d56f1310179422011dd40da8898a7a/jetified-lifecycle-runtime-ktx-2.4.0-beta01/META-INF/com/android/build/gradle/aar-metadata.properties.
   > A failure occurred while executing com.android.build.gradle.internal.tasks.CheckAarMetadataWorkAction
      > 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.work:work-runtime:2.7.0.
        AAR metadata file: /Users/teddy/.gradle/caches/transforms-2/files-2.1/83035a64dc09dc2fde1ddabd29e1b8ef/work-runtime-2.7.0/META-INF/com/android/build/gradle/aar-metadata.properties.
   > A failure occurred while executing com.android.build.gradle.internal.tasks.CheckAarMetadataWorkAction
      > 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-beta01.
        AAR metadata file: /Users/teddy/.gradle/caches/transforms-2/files-2.1/2b4008d37c8113ef28c5974387aca61f/lifecycle-runtime-2.4.0-beta01/META-INF/com/android/build/gradle/aar-metadata.properties.

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 38s
Exception: Gradle task assembleDebug failed with exit code 1

해결 방법


  1. android/app/build.gradle 에서 compileSdkVersiontargetSdkVersion를 31로 올린다.
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.example.test"
        minSdkVersion 19
        targetSdkVersion 31
        versionCode flutterVersionCode.toInteger()
        versionName flutterVersionName
        multiDexEnabled true
    }

   signingConfig
....
}
  1. android/build.gradle 에서 kotlin 버전을 1.4.32로 변경한다.
buildscript {
    ext.kotlin_version = '1.4.32'
    repositories {
        google()
        jcenter()
    }
...
}

그럼 정상적으로 빌드가 동작한다.