Getting error while running `react-native run-android`
Asked Answered
M

12

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.
Misti answered 1/7, 2021 at 9:2 Comment(4)
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.Simms
same problem after update Android Studio to 4.2.2Underthrust
try to change the core library with stable version 1.6.0Ameline
@UsamaAltaf where is the core lib defined? I couldn't found androidx.core:core:1.7.0-alpha01 in my projectDiagnostician
H
30

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"
  }
}
Haiduk answered 2/7, 2021 at 8:43 Comment(3)
2021 React-native MVPFurlough
My release build's size has increased by 2x after this.Hypophyge
Thank you! This helped me a lot. I also used ./gradlew :app:dependencies > dependencies.txt (from https://mcmap.net/q/112967/-resource-linking-fails-on-lstar) 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: mvnrepository.com/artifact/io.intercom.android/… - it shows dependencies.Dissuasive
C
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

Cerement answered 1/7, 2021 at 17:20 Comment(1)
this worked for meSorely
D
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

Diagnostician answered 1/7, 2021 at 9:39 Comment(2)
compileSdkVersion=29 to compileSdkVersion=30Misti
0.64.5 will have all sdk versions updated to 30, so you can use ReactNative upgrade tool and upgrade them all upfront to 30.Kentiggerma
A
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

Apfel answered 2/7, 2021 at 7:58 Comment(1)
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.Adze
D
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

Dogy answered 2/9, 2021 at 7:46 Comment(0)
H
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.

Hug answered 1/7, 2021 at 12:38 Comment(0)
S
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

Simms answered 1/7, 2021 at 9:45 Comment(8)
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 errorDiagnostician
Probably the rc build could have caused this. And in general rc builds are quite buggy. Can you try a stable build?Simms
did you use implementation "com.facebook.react:react-native:+"? Did you specified it, the version?Diagnostician
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.Simms
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 errorDiagnostician
Can you get us the list of all dependencies?Simms
Let us continue this discussion in chat.Simms
See my answer below: https://mcmap.net/q/112766/-getting-error-while-running-react-native-run-androidHaiduk
F
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'

Fingernail answered 2/7, 2021 at 4:59 Comment(0)
B
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"
            }
        }
    }
}
Bon answered 4/7, 2021 at 6:48 Comment(0)
E
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"
Eightfold answered 5/7, 2021 at 16:48 Comment(0)
N
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()
Nihilism answered 3/9, 2021 at 8:50 Comment(0)
L
-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'
   }
}
Legerdemain answered 1/7, 2021 at 11:2 Comment(2)
Did you try changing the compileSdkVersion=29 to compileSdkVersion=30Simms
@Simms 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.Legerdemain

© 2022 - 2024 — McMap. All rights reserved.