I'm trying to build a project in my M1,
but I got this error when I run npx react-native run-android
FAILURE: Build failed with an exception.
* What went wrong:
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-beta01.
AAR metadata file: /Users/macpro/.gradle/caches/transforms-3/999e9d813832e06d8f1b7de52647a502/transformed/work-runtime-2.7.0-beta01/META-INF/com/android/build/gradle/aar-metadata.properties.
Android/build.gradle
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
ext {
buildToolsVersion = "30.0.0"
minSdkVersion = 21
compileSdkVersion = 30
targetSdkVersion = 30
supportLibVersion = "28.0.0"
}
repositories {
google()
jcenter()
}
dependencies {
classpath('com.android.tools.build:gradle:4.1.2')
classpath('com.google.gms:google-services:4.3.0')
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
mavenLocal()
maven {
// All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
url("$rootDir/../node_modules/react-native/android")
}
maven {
// Android JSC is installed from npm
url("$rootDir/../node_modules/jsc-android/dist")
}
google()
jcenter()
maven { url 'https://www.jitpack.io' }
}
}
gradle-wrapper.properties
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.9-all.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
The error is being caused because one of your dependencies is internally using WorkManager 2.7.0-beta01 that was released today (which needs API 31). In my case it was CheckAarMetadata.kt.
You can fix it by forcing Gradle to use an older version of Work Manager for the transitive dependency that works with API 30. In your build.gradle file add:
dependencies {
def work_version = "2.6.0"
// Force WorkManager 2.6.0 for transitive dependency
implementation("androidx.work:work-runtime-ktx:$work_version") {
force = true
}
}
This should fix it.
This is because in work-runtime:2.7.0-beta01 the compileSdkVersion was updated to 31
you could either update your compileSdkVersion to 31
or use an older version of work-runtime that doesn't include this change
It is mentioned in the release notes of Version 2.7.0-beta01
Note: WorkManager Version 2.7.0 is required for apps targeting Android 12 (S).
for example, adding this to your build.gradle should fix it
api(group: "androidx.work", name: "work-runtime") {
version {
strictly "2.7.0-alpha04"
}
}
I had the same problem and I was able to solve it by changing the version of appcompat in the dependencies
What I had:
implementation 'androidx.appcompat:appcompat:1.4.0'
I changed it to:
implementation 'androidx.appcompat:appcompat:1.3.1'
Note that I am using java.
I experienced the same thing but was actually caused by work manager dependency that I upgraded to version 2.7.0
I simply downgraded it back to 2.6.0
dependencies{
implementation 'androidx.work:work-runtime-ktx:2.6.0'
}
I was also having the same issue in my project and now that issue is being resolved. The issue was because of the dependency androidx.work:work-runtime
But I would like to first mention that I was not using that dependency in my project directly (not added in my app level gradle), probably some other dependency was using that internally.
So what I did is forcefully downgraded its version by adding this
configurations.all {
resolutionStrategy { force 'androidx.work:work-runtime:2.6.0' }
}
inside
android {
defaultConfig {
//here
}
}
and it resolved my issue.
In my flutter application, changed the compileSdkVersion and targetSdkVersion in android\app\build.gradle
android {
compileSdkVersion 31 // Changed to 31
sourceSets {
main.java.srcDirs += 'src/main/kotlin'
}
defaultConfig {
applicationId "com.example.blah_blah"
minSdkVersion 16
targetSdkVersion 31 //Changed to 31
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
}
buildTypes {
release {
// TODO: Add your own signing config for the release build.
// Signing with the debug keys for now, so `flutter run --release` works.
signingConfig signingConfigs.debug
}
}
}
And also, changed the kotlin version to '1.6.10' in android\build.gradle
buildscript {
ext.kotlin_version = '1.6.10' //change here
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:4.1.0'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
For those others facing the below error from last 36hrs (due to an update on androidx-core):
Error:
> 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.core:core-ktx:1.7.0-alpha02.
you can try to force use androidx to older version:
place it under android/app/build.gradle (under dependencies {} preferably or outside android {})
configurations.all {
resolutionStrategy { force 'androidx.core:core-ktx:1.6.0' }
}
Check the message
you can see the module used that has minCompileSdk (31) specified
Dependency: androidx.appcompat:appcompat:1.4.0.
To fix this issue momentarily you have to downgrade the dependency defined into your build.gradle, for example from appcompat:1.4.0 to appcompat:1.3.0 :
dependencies {
implementation 'androidx.appcompat:appcompat:1.3.0'
...
...
...
/* 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.appcompat:appcompat:1.4.0. */
}
I have changed this
implementation 'androidx.core:core-ktx:1.7.0'
implementation 'androidx.appcompat:appcompat:1.4.0'
to this
implementation 'androidx.core:core-ktx:1.6.0'
implementation 'androidx.appcompat:appcompat:1.3.0'
and it worked for me, also i was using Kotlin
In my case what worked for me was to change compileSdk version to 31
A similar issue on 4Nov, 2022. If someone is stuck due to this build issue please checkout
https://github.com/facebook/react-native/issues/35210
def REACT_NATIVE_VERSION = new File(['node', '--print',"JSON.parse(require('fs').readFileSync(require.resolve('react-native/package.json'), 'utf-8')).version"].execute(null, rootDir).text.trim())
allprojects {
configurations.all {
resolutionStrategy {
// Remove this override in 0.66, as a proper fix is included in react-native itself.
force "com.facebook.react:react-native:" + REACT_NATIVE_VERSION
}
}
}
Something in my project auto-updated causing a cascading effect. After first it was giving errors that I had intent-filters missing android:export="true/false" when targeting SDK 31. But my targets were set for SDK 30. I then setting targets to SDK 31 causing more issues. So I backed them out...but as a result of setting to SDK 31, other dependencies were trying to use BETA releases versus the stable version.
In my case, after rolling back to SDK 30, I then started getting an error similar to the OPs minCompileSdk (31) specified in a dependency's androidx.appcompat:appcompat-resources:1.4.0-beta01 - the stable version for appcompat is 1.3.1.
In my /<project>/platforms/android/project.properties file my appcompat dependency was set to:
cordova.system.library.19=androidx.appcompat:appcompat:1+
This was causing version 1.4.0-Beta01 to be updated/loaded. So I had to pin it back to:
cordova.system.library.19=androidx.appcompat:appcompat:1.3.1
I had similar problem and I updated one of the Gradle Script and it fix the problem;
// build.gradle (Module:testApp)
android {
compileSdkVersion 30
buildToolsVersion "30.0.3"
defaultConfig {
applicationId "myproject.name.testApp"
minSdkVersion 16 // <--- must be same as under dependencies section
targetSdkVersion 30
versionCode 1
versionName "1.0"
dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
implementation 'androidx.core:core-ktx:1.6.0' // <--- Was showing 1.7, it fix problem
implementation 'androidx.appcompat:appcompat:1.3.1'
To solve this issu follow these steps
Go to SDK manager in android studio and install 'Android api 31'
Go to build.gradle file and change complie SDK version 'x' to compile SDK
version 31 and change target SDK version also to 31
Now synk
go to manifest.xml and write this line to inside your activity which is linked with intent filter
'android: export="true"
Now build the project. It will definitely solve this problem
Note also that the latest Google Ads SDK dependencies (currently v20.5.0) may lead to the minCompileSDK (31) error in the following circumstance:
your project is setup to use a compileSDK and targetSDK of 29/30
The Google Ads (or any) dependency version included in the implementation section of your build.gradle is intended for use with Apps compiling against API 31 / Android 12
For example your build.gradle may contain:
compileSdkVersion 29
targetSdkVersion 29
implementation 'com.google.android.gms:play-services-ads-lite:20.5.0'
As mentioned in other answers the way to resolve this is that you need to apply a force resolutionStrategy to ensure that the latest versions of the androidx.work:work-runtime and androidx.core:core-ktx are not picked up as required build dependencies.
The following works for me
configurations.all {
resolutionStrategy { force 'androidx.work:work-runtime:2.6.0' }
resolutionStrategy { force 'androidx.core:core-ktx:1.6.0' }
}
NOTE: Once you have migrated to compiling against API 31, the resolutionStrategy lines should be removed to ensure that you are using the latest versions of the core Android platform dependencies
I had this problem and was getting no solutions from any of the Stack Overflow threads. Disabling Hyper V and running basic diagnostics were still not helpful. I was getting stop codes each time I tried to run my VM.
I fixed this issue by going into the SDK manager and updating the SDK Platform and SDK tools. Start by opening the SDK Manager from the Tools menu, and each option with a hyphen in the Platform/Tools panes click to change into a check mark, hit apply and accept the changes. The stop codes went away for me.
BROTHER MY ERROR HAS BEEN RESOLVED BY DOWNLOADING THE SDK TOOL OF 31 FROM SETTINGS -> APPERENCE AND BEHAVIOUR-> ANDROID SDK - AND THE 2ND ONE IN THE LIST
as in the image instead of 28 in the second column there will be 31 So u need to download that and then rebuild your project
That's it !
I solved the issue by adding this piece of code at the end of dependencies inside android/app/build.gradle :
android/app/build.gradle
dependencies {
....
....
api(group: "androidx.work", name: "work-runtime") {
version {
strictly "2.7.0-alpha04"
}
}
}
And this is android/build.gradle
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
ext {
buildToolsVersion = "30.0.2"
minSdkVersion = 21
compileSdkVersion = 30
targetSdkVersion = 30
ndkVersion = "21.4.7075529"
androidXCore = "1.7.0" // <-- Add this. Check versions here: https://developer.android.com/jetpack/androidx/releases/core
}
repositories {
google()
mavenCentral()
}
dependencies {
classpath("com.android.tools.build:gradle:4.2.2")
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
mavenCentral()
mavenLocal()
maven {
// All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
url("$rootDir/../node_modules/react-native/android")
}
maven {
// Android JSC is installed from npm
url("$rootDir/../node_modules/jsc-android/dist")
}
google()
maven { url 'https://www.jitpack.io' }
}
}
I had to update from RN 0.66.4 to 0.66.5.
https://github.com/facebook/react-native/releases/tag/v0.66.5
The description:
🚨 IMPORTANT: This is an exceptional release on an unsupported version. We recommend you upgrade to one of the supported versions, listed here.
Hotfix
This version is a patch release addressing the Android build issue that has been ongoing since Nov 4th 2022. If you are on 0.66.x, update to this version to fix it.
If you are on an older version of React Native, refer to this issue for details and the workaround you can apply in your project.
After bumping it worked for me.
In my case, on of the module's version has + on its versioning, specifying the version which suits to your sdk version will solve it
I have the following dependency in one module -
implementation "androidx.core:core-ktx:+"
but others module including app module has following dependency
implementation "androidx.core:core-ktx:1.6.0"
You need change + to version
implementation "androidx.core:core-ktx:+" ->
implementation "androidx.core:core-ktx:1.6.0"
I had the same error and it worked when I modified the following:
implementation 'androidx.core:core-ktx:1.7.0' and `api 'com.google.android.material:material:1.4.0-alpha07'`
to
implementation 'androidx.core:core-ktx:1.6.0' and api 'com.google.android.material:material:1.4.0-alpha06'
I was having the same problem the minCompileSdk (31) specified in a dependency's AAR metadata when I created an activity from the templates with ViewModel and LiveData it add the latest versioned dependencies like
then I downgraded the version to 1.6.0 as
I also had this probem in a jetpack compose project.
I was using paging and the problem was because of both paging and some other dependencies.
I could solve the problem by using the following version of paging instead :
implementation "androidx.paging:paging-compose:1.0.0-alpha10"
and I replaced the old dependencies with the following :
implementation 'androidx.core:core-ktx:1.6.0'
implementation 'androidx.appcompat:appcompat:1.3.1'
implementation 'com.google.android.material:material:1.4.0'
implementation "androidx.compose.ui:ui:$compose_version"
implementation "androidx.compose.material:material:$compose_version"
implementation "androidx.compose.ui:ui-tooling-preview:$compose_version"
implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.3.1'
implementation 'androidx.activity:activity-compose:1.3.1'
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'
androidTestImplementation "androidx.compose.ui:ui-test-junit4:$compose_version"
debugImplementation "androidx.compose.ui:ui-tooling:$compose_version"
Changing
implementation 'androidx.core:core-ktx:1.7.0'
to
implementation 'androidx.core:core-ktx:1.6.0'
worked for me.
Because you use gradle>7.0, you can chan gradle-6.7.1-all and com.android.tools.build:gradle:4.0.0. :3
I was facing same issue for the last few weeks, now in Dec 2021 first week the official sdk of 31 is released,
Now change the compilesdk to 31 and targetsdk to 30
Download the latest sdk from android studio,
Click Tools > SDK Manager.
In the SDK Platforms tab, select Android 12.
In the SDK Tools tab, select Android SDK Build-Tools 31.
Click OK to install the SDK.
The latest lib wants the compilesdk of 31,
Once you do this all issues resolved.
#Kishan Solanki answer worked for me. I am using Flutter.
So what I did is forcefully downgraded its version by adding this
configurations.all {
resolutionStrategy { force 'androidx.work:work-runtime:2.6.0' }
}
inside
android {
defaultConfig {
//here
}
}
I got this error when trying to target API 30 in a Java project. It was caused by appcompat version 1.4.1 requiring a target API of 31 or higher. If you downgrade to version 1.3.1 it will support a target API of 30 or higher.
To target API 30, you need to downgrade both androidx.appcompat:appcompat and com.google.android.material:material to older versions.
Change the versions from:
implementation 'androidx.appcompat:appcompat:1.4.1'
implementation 'com.google.android.material:material:1.5.0'
To:
implementation 'androidx.appcompat:appcompat:1.3.1'
implementation 'com.google.android.material:material:1.4.0'
Ionic user with Cordova
I would have loved to give an answer to the following question, but since it have been closed..
This is a pure copy of the following answer but it should make the trick
"This issue is related to androidx.appcompat:appcompat 1.4.0-beta01 released on September 29, 2021.
As plugin.xml defines ANDROIDX_VERSION as major version 1 (1.+), 1.4.0-beta01 was used instead of 1.3.0. Unfortunately you cannot simply use cordova plugin add cordova.plugins.diagnostic --variable ANDROIDX_VERSION=1.3.+ to overwrite the value, as the same version would be used for androidx.legacy:legacy-support-v4 which exists as version 1.0.0 only.
I successfully used cordova plugin add cordova.plugins.diagnostic --variable ANDROIDX_VERSION="[1.0, 1.4[" to get my builds fixed." - Vivek Kachhwaha
For me, I had to uninstall the java version which is currently the latest (java 17) and install java 11.
I'm using expo react native. I tried to use expo run:android or eas build --profile development --platform android. The error I got from these two was solved by simply doing the above.
I am working on this project: https://github.com/muxinc/mux-stats-sdk-exoplayer/tree/min_sdk_version_fix It is Android app called demo that have dependency to a module from a same project called MuxExoPlayer which have a dependency to a MuxCore.jar library.
When I try to compile the project with minSdkVersion 16, I get desugaring issue on jar file, error:
Transform artifact full.jar (project :MuxExoPlayer) with DexingWithClasspathTransform
AGPBI: {"kind":"error","text":"Default method desugaring of `com.mux.stats.sdk.muxstats.MuxStatsExoPlayer` failed because it's hierarchy is incomplete. The class `com.mux.stats.sdk.core.events.EventBus` is missing and it is the declared super class of `com.mux.stats.sdk.muxstats.MuxBaseExoPlayer`","sources":[{}],"tool":"D8"}
When I compile with minSdkVersion 24, I do not get this error and project compile just fine.
MuxCore.jar is also built with gradle, here is the gradle.build:
apply plugin: 'java-library'
// In this section you declare where to find the dependencies of your project
repositories {
// Use jcenter for resolving your dependencies.
// You can declare any Maven/Ivy/file repository here.
jcenter()
}
tasks.withType(JavaCompile) {
sourceCompatibility = '1.7'
targetCompatibility = '1.7'
}
dependencies {
// This dependency is exported to consumers, that is to say found on their compile classpath.
api 'org.apache.commons:commons-math3:3.6.1'
// This dependency is used internally, and not exposed to consumers on their own compile classpath.
implementation 'com.google.guava:guava:23.0'
implementation 'org.json:json:20180130'
// Use JUnit test framework
testImplementation 'junit:junit:4.4'
testImplementation 'org.mockito:mockito-core:2.23.4'
}
What am I missing here ?
How do I need to compile MuxCore in order to compile with android minSdkVersion 16 ?
I have the same problem and also create a ticket in Mux github repo but could not make it work... If you update the minSdk to 24 it will work...
https://github.com/muxinc/mux-stats-sdk-exoplayer/issues/19
What is working for me is: instead of adding MuxStatsExoPlayer as a module add directly all the files and classes in your app module into your project and it should work.
I have a problem using the android support library in my Android Studio project using gradle.
If I add the support-library as dependency I will receive and "Error: Gradle: Execution failed for task ':AppName:dexDebug'.
I have done a some researches and found the problem using the support-library with other dependencies which are using the support libraries as well (greendao 1.3.0).
I would like to use a NavDrawer in my app, so I have to use these support library.
If I remove the support library, of course I will receive an inflate error for the "android.support.v4.widget.DrawerLayout".
Does somebody here has an idea?
I used two kind of dependency-imports
compile files('libs/android-support-v13.jar')
and
compile 'com.android.support:support-v4:13.0.0'
cause of a found post in a forum. But that doesn't work, too.
Thanks for your support.
Regards,
Marine
If your other dependencies also depend on the support lib, you need to make sure they are not using local dependencies (ie embedding the jar file). You should always use only
dependencies {
compile 'com.android.support:support-v4:x.y.z'
}
and not a local dependencies. Make sure all your dependencies do the same and Gradle will automatically detect that everything depends on the same library and only add it once to dex.
I tried it but I receive the dex error as well.
Attached you could see my current gradle build-file.
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.5.+'
}
}
apply plugin: 'android'
repositories {
mavenCentral()
}
dependencies {
compile 'com.android.support:support-v4:13.0.0'
compile 'com.google.android.gms:play-services:3.1.36'
compile 'de.greenrobot:greendao:1.3.0'
}
android {
compileSdkVersion 17
buildToolsVersion "17.0.0"
defaultConfig {
minSdkVersion 15
targetSdkVersion 18
}
sourceSets {
main {
java.srcDirs = ['src/main/java', 'src-gen/main/java']
}
}
}
The src-gen folder is used for my greendao generated classes.
Please let me know if you need some more information.
Edit:
I resolved it using the latest greendao version. Added: compile
de.greenrobot:greendao:1.3.1
instead of compile
de.greenrobot:greendao:1.3.0
Now it works.
Regards,
Marine_of_Hell