2

I am trying to add google_mobile_ads, version 1.0.0 by following the steps mentioned in this answer: https://stackoverflow.com/a/67883550/13240914, but when I run the app in debug mode, I get this error:

Execution failed for task ':app:checkDebugAarMetadata'.
> 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/mydata/.gradle/caches/transforms-2/files-2.1/6ca6bfbb6ed79157a08fdd6548cc9e4d/work-runtime-2.7.0/META-INF/com/android/build/gradle/aar-metadata.properties.

Is there any way to solve this problem? and here is android/app/build.gradle https://gist.github.com/wahyu-handayani/025cbb7c538196cf91e6629ac668954f

Dharman
  • 30,962
  • 25
  • 85
  • 135
wahyu
  • 1,679
  • 5
  • 35
  • 73
  • Duplicate: https://stackoverflow.com/q/64521804/5468463 – Vega Nov 18 '21 at 05:21
  • @Vega I have added my build.gradle in my question, and I am trying to debugging the apps... it takes so long to build the apk so instead of debugging I try to install the apk release and the app gets sudden close – wahyu Nov 18 '21 at 07:13
  • @karel I have tried it but still failed my app get sudden close – wahyu Nov 18 '21 at 07:14
  • As it is this question is a duplicate. If you consider it is not, add [mre] and more context – Vega Nov 18 '21 at 07:18
  • Does this answer your question? [Execution failed for task ':app:checkDebugAarMetadata'](https://stackoverflow.com/questions/64521804/execution-failed-for-task-appcheckdebugaarmetadata) – bad_coder Nov 18 '21 at 23:38

3 Answers3

7

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).

The problem is occurring because in the dependency androidx.work:work-runtime:2.7.0 requires minimum SDK version 31 to run. There can be two solutions:

  1. Use an older version of this dependency, preferably, 2.6.0
  2. In the app\build.gradle file, change the property compileSdkVersion 30 to compileSdkVersion 31. Make sure to download the SDK version 31 from SDK manager first!
JustinW
  • 2,567
  • 1
  • 13
  • 29
  • Hi I have modified compileSdkVersion 30 to compileSdkVersion 31, but I don't know how to edit ```androidx.work:work-runtime:2.7.0``` bucause when I take a look at my gradle there is no something like ```androidx.work:work-runtime:2.7.0``` – wahyu Nov 18 '21 at 06:40
  • Ok, if that's the case a dependency exists which uses the work-runtime dependency, post the list of your deps pls – JustinW Nov 18 '21 at 06:56
  • I have edited my question just now, would you like to take a look – wahyu Nov 18 '21 at 07:05
  • By the way if your project now targets SDK version 31, it should run successfully, I have listed 2 solutions, anyone would work :). Post an error if it persists – JustinW Nov 18 '21 at 07:09
  • right now I am still trying to debugging the app, it takes so long to install the app but I have also tried to install apk release version and something like sudden close happens (force close) – wahyu Nov 18 '21 at 07:18
  • Does the error persist? If not, then that's usual because the gradle task assembleDebug takes long on Flutter. So, you'd have to wait. If it solves your problem, you can upvote the answer and mark it as accepted. – JustinW Nov 18 '21 at 07:22
  • I still didn't get the report yet, because installing process is still running until now, I will try to update the log information – wahyu Nov 18 '21 at 07:44
3

I solved this problem by forcing all the dependencies in my protect to use androidx.work:work-runtime:2.6.0, as suggested by this answer because I didn't use this dependency directly in my protect directly. To do this, open the ./android/app/build.gradle file and add:

configurations.all {
    resolutionStrategy { force 'androidx.work:work-runtime:2.6.0' }
}

inside android/defaultConfig, as:

android {
  ...
  defaultConfig {
    configurations.all {
    resolutionStrategy { force 'androidx.work:work-runtime:2.6.0' }
    }
  ...
  }
}

Then, open ./android/build.gradle file and change the kotlin version to 1.4.32 like this:

buildscript {
  ext.kotlin_version = '1.4.32'
}

After this, If you faced an error that is related to the .dex file, like: Cannot fit requested classes in a single dex file., then make sure you enable multidex in app/build.gradle file by adding

defaultConfig {
    ....
    multiDexEnabled true
}

dependencies {
    ....
    implementation 'com.android.support:multidex:2.0.1'
}

(as mentioned by this StackOverflow answer).

AliZ.ece
  • 51
  • 5
1

I was facing the same error as kotlin version was not specified in my case. I solved it by specifying the kotlin version. from implementation "androidx.core:core-ktx:+" to

implementation "androidx.core:core-ktx:1.8.0"