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.
Plug in your device via USB Let's now set up an Android device to run our React Native projects. Go ahead and plug in your device via USB to your development machine. Now check that your device is properly connecting to ADB, the Android Debug Bridge, by running adb devices .
react-native run-android Before you can run your app on Android device, you need to enable USB Debugging inside the Developer Options. When USB Debugging is enabled, you can plug in your device and run the code snippet given above. Make sure your laptop and your phone are on the same Wi-Fi network.
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"
}
}
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With