48

Whle running my react native code react-native run-android getting below error. It was working proper. But after taking fresh pull from git and npm ci and after I am running then getting this error.

error Failed to install the app. Make sure you have the Android development environment set up: https://reactnative.dev/docs/environment-setup.
Error: Command failed: gradlew.bat app:installDebug -PreactNativeDevServerPort=8081

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 (30) specified in a
     dependency's AAR metadata (META-INF/com/android/build/gradle/aar-metadata.properties)
     is greater than this module's compileSdkVersion (android-29).
     Dependency: androidx.core:core:1.7.0-alpha01.
     AAR metadata file: C:\Users\gauraab\.gradle\caches\transforms-2\files-2.1\9e02d64f5889006a671d0a7165c73e72\core-1.7.0-alpha01\META-INF\com\android\build\gradle\aar-metadata.properties.
Pedro A
  • 3,989
  • 3
  • 32
  • 56
Abhigyan Gaurav
  • 1,854
  • 6
  • 28
  • 58
  • Since everyone is facing it just today, I think this could probably be because of our dependencies. Some update to minor version/patch version broke the android builds probably? In the dependencies, we can try providing an exact stable version number for our dependencies. – ChandrasekarG Jul 01 '21 at 09:37
  • same problem after update Android Studio to 4.2.2 – MagogCZ Jul 01 '21 at 09:38
  • 1
    try to change the core library with stable version 1.6.0 – Usama Altaf Jul 01 '21 at 09:43
  • 4
    @UsamaAltaf where is the core lib defined? I couldn't found ```androidx.core:core:1.7.0-alpha01``` in my project – Akza Jul 01 '21 at 10:16

12 Answers12

29

As some has mentioned, the problem is that the RN build automatically "upgraded" to androidx.core:core:1.7.0-alpha01, which depends on SDK version 30.

The Fix

The fix is simply to specify android core version via androidXCore in build.gradle

buildscript {
    ext {
        buildToolsVersion = "29.0.3"
        minSdkVersion = 23
        compileSdkVersion = 29
        targetSdkVersion = 29
        ndkVersion = "20.1.5948944"
        kotlin_version = "1.5.0"
        androidXCore = "1.5.0"
    }

How I figured it out

Figuring this out was painful. I grepped for gradle files that would automatically upgrade packages like so

find . -name '*.gradle' -exec grep -H "\.+" {} \;

and found in node_modules/@react-native-community/netinfo/android/build.gradle the following snippet

def androidXCore = getExtOrInitialValue('androidXCore', null)
  if (supportLibVersion && androidXVersion == null && androidXCore == null) {
    implementation "com.android.support:appcompat-v7:$supportLibVersion"
  } else {
    def defaultAndroidXVersion = "1.+"
    if (androidXCore == null) {
      androidXCore = androidXVersion == null ? defaultAndroidXVersion : androidXVersion
    }
    implementation "androidx.core:core:$androidXCore"
  }
}
Gilbert
  • 901
  • 1
  • 10
  • 22
  • 1
    2021 React-native MVP – Denis Tsoi Aug 20 '21 at 07:02
  • My release build's size has increased by 2x after this. – Rohit Aggarwal Sep 02 '21 at 05:55
  • Thank you! This helped me a lot. I also used `./gradlew :app:dependencies > dependencies.txt` (from https://stackoverflow.com/a/69031232/1395078) which helped me find the random dependency that was forcing `core 1.7`. I had to hunt through several resolutions and eventually found it was Intercom bumping `activity-compose` between 10.6.2 and 10.6.3. I had `10+` so pinned it to 10.6.2. If it's a native package, finding the version to downgrade to is very easy with this repository explorer: https://mvnrepository.com/artifact/io.intercom.android/intercom-sdk-base/10.6.2 - it shows dependencies. – Nabil Freeman Mar 08 '22 at 16:48
22

Apparently they just broke this today.

You can fix it by adding the following line to your app level build.gradle file (above the android { } block as a sibling):

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

Finally, the Gradle build was successfully completed. Ref. https://docs.gradle.org/current/dsl/org.gradle.api.artifacts.ResolutionStrategy.html

Adam Johns
  • 35,397
  • 25
  • 123
  • 176
Kristy Welsh
  • 7,828
  • 12
  • 64
  • 106
10

I got same issue. Just today. When I try to run locally, I got the exact same error. To get it run again, I update the field compileSdkVersion and targetSdkVersion in file android > build.gradle from 29 to 30. Then, it can run again. If this answer fits with you, you can go with this way. But, personally, I'm lookin for solution without to change the value compileSdkVersion and targetSdkVersion

Update: just change the compileSdkVersion

Akza
  • 1,033
  • 3
  • 19
  • 37
5

Here is a screenshot of what I have done and it's run perfectly. change these lines from

 compileSdkVersion = 29
 targetSdkVersion = 29

to

 compileSdkVersion = 30
 targetSdkVersion = 30

and also change this line from

implementation 'androidx.appcompat:appcompat:1.+'

to implementation 'androidx.appcompat:appcompat:1.3.0'

enter image description here

Engr.Aftab Ufaq
  • 3,356
  • 3
  • 21
  • 47
  • I was able to build by only adjust 'androidx.appcompat:appcompat:1.3.0', leaving the compileSdkVersion and targetSdkVersion at 29 - thus avoid upgrading the React Native NPM packages. – Mr Chris Jul 07 '21 at 10:01
5

First never use + to define the version of Libraries in Gradle, Try to give the latest version always.

If you are using Core KTX like below in your main Gradle dependencies

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

Just replace it to

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

Core and Core-ktx Version 1.7.0 released yesterday(September 1, 2021), which is causing the issues.

https://developer.android.com/jetpack/androidx/releases/core

Guruprasad
  • 931
  • 11
  • 16
3

For me the issue is caused by react-native-netinfo 's old version 4.0.0 which was configured to automatically pick up the latest published package of androidx.core... So in that case it did I realized androidx.core.core-1.7.0-alpha01 had been published right as the issue started occurring.

So to fix that I updated my react-native-netinfo package from 4.0.0 to 6.0.0 and this issue was resolved for me.

Asadullah Ali
  • 1,056
  • 14
  • 31
1

The issue was just what I guessed. So, some updates to a minor version/patch version of an android dependency caused all this today.

To solve this, for the dependencies in your build.gradle file, if you have specified it to take the latest minor/patch version every time you build it, make it take an exact stable version.

For example, my appcompact dependecy was,

implementation "androidx.appcompat:appcompat:1.+

This means that it can update to 1.2.x or 1.3.x etc.. as and when such version updates get published. I changed this to depend on an exact stable version like below,

implementation "androidx.appcompat:appcompat:1.3.0"

Hopefully, this solves the issue for everyone.

enter image description here

ChandrasekarG
  • 1,384
  • 13
  • 24
  • do you know which dependency it is? Caused I already specified with ```implementation 'androidx.appcompat:appcompat:1.1.0-rc01'```. But still got the same error – Akza Jul 01 '21 at 09:50
  • Probably the rc build could have caused this. And in general rc builds are quite buggy. Can you try a stable build? – ChandrasekarG Jul 01 '21 at 09:53
  • 1
    did you use ```implementation "com.facebook.react:react-native:+"```? Did you specified it, the version? – Akza Jul 01 '21 at 09:57
  • I don't use react-native. Mine is a native android project. So, you don't have to change it I believe since that did not break things for me. – ChandrasekarG Jul 01 '21 at 09:59
  • I've try to change from ```androidx.appcompat:appcompat:1.1.0-rc01``` to ```androidx.appcompat:appcompat:1.3.0``` (like you did). But, still got the error – Akza Jul 01 '21 at 10:01
  • Can you get us the list of all dependencies? – ChandrasekarG Jul 01 '21 at 10:02
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/234408/discussion-between-chandrasekarg-and-akza). – ChandrasekarG Jul 01 '21 at 10:49
  • See my answer below: https://stackoverflow.com/a/68222185/70488 – Gilbert Jul 02 '21 at 08:44
0

Simple work around with complie version

  • Change compileSdkVersion=29 to compileSdkVersion=30 and sync.

If you not willing to change the complie version,then

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

add the above code in build.gradle inside android and apply this

implementation 'androidx.core:core-ktx:1.7.0-alpha01'

Agilanbu
  • 2,747
  • 2
  • 28
  • 33
0

Try to add this on your top build.gradle at the bottom of buildscript. This will force anything to a specific version.

subprojects {
    project.configurations.all {
        resolutionStrategy.eachDependency { details ->
            if (details.requested.group == 'androidx.core'
                    && !details.requested.name.contains('androidx') ) {
                details.useVersion "1.5.0"
            }
            
            if (details.requested.group == 'androidx.core-ktx'
                    && !details.requested.name.contains('androidx') ) {
                details.useVersion "1.5.0"
            }
        }
    }
}
0

Updating version numbers to match those shown in the official template build.gradle file worked for me: https://github.com/facebook/react-native/blob/master/template/android/build.gradle

 buildToolsVersion = "30.0.2"
 compileSdkVersion = 30
 targetSdkVersion = 30
 ndkVersion = "21.4.7075529"
Gav
  • 431
  • 5
  • 12
0

None of the single solutions above worked, but a combo of them worked for me, using RN 0.63.3 Here's the diff:

diff --git a/android/app/build.gradle b/android/app/build.gradle
index 9c014f8..1b59f65 100644
--- a/android/app/build.gradle
+++ b/android/app/build.gradle
@@ -139,6 +139,12 @@ def enableProguardInReleaseBuilds = false
  */
 def jscFlavor = 'org.webkit:android-jsc:+'
 
+configurations.all {
+   resolutionStrategy {
+     force 'androidx.core:core-ktx:1.6.0'
+   }
+}
+
 android {
     compileSdkVersion rootProject.ext.compileSdkVersion
 
diff --git a/android/build.gradle b/android/build.gradle
index a32892e..db64506 100644
--- a/android/build.gradle
+++ b/android/build.gradle
@@ -3,12 +3,13 @@
 buildscript {
     ext.kotlin_version = '1.4.0'
     ext {
-        buildToolsVersion = "29.0.2"
+        buildToolsVersion = "29.0.3"
         minSdkVersion = 21
-        compileSdkVersion = 30
+        compileSdkVersion = 29
         targetSdkVersion = 29
         androidXAnnotation = "1.1.0"
         androidXBrowser = "1.0.0"
+        androidXCore = "1.5.0"
     }
     repositories {
         google()
Esben von Buchwald
  • 2,772
  • 1
  • 29
  • 37
-1

Observing the same core library dependency is causing Gradle build issues for all.

Also, clean project or Invalidate Caches/Restart... options wouldn't help here.

Affecting dependency: 'androidx.core:core-ktx:1.7.0-alpha01'

This dependency which was causing issue, for that I have made it stable in build.gradle file, then added a new line to solve dependency conflicts:

configurations.all {
   resolutionStrategy {
     force 'androidx.core:core-ktx:1.6.0'
   }
}
  • Did you try changing the compileSdkVersion=29 to compileSdkVersion=30 – ChandrasekarG Jul 01 '21 at 11:42
  • @ChandrasekarG To most of us, this issue type is being observed in most recent, to be precise since yesterday. TBH, I haven't tried upgrading `compileSdkVersion`, will try and check. – Rohit Bhargava Jul 01 '21 at 15:27