Reputation: 1904
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.
Upvotes: 48
Views: 55116
Reputation: 3049
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()
Upvotes: 0
Reputation: 931
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
Upvotes: 5
Reputation: 8530
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
Upvotes: 22
Reputation: 431
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"
Upvotes: 0
Reputation: 1
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"
}
}
}
}
Upvotes: 0
Reputation: 921
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 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"
}
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"
}
}
Upvotes: 30
Reputation: 6272
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'
Upvotes: 5
Reputation: 2805
Simple work around with complie version
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'
Upvotes: 0
Reputation: 94
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'
}
}
Upvotes: -1
Reputation: 1064
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.
Upvotes: 3
Reputation: 1143
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
Upvotes: 10
Reputation: 1383
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.
Upvotes: 1