I'm getting an error every time I try to run 'react-native run-android' or './gradlew bundleRelease' for my React Native project.
FAILURE: Build failed with an exception.
* What went wrong:
Could not determine the dependencies of task ':app:collectReleaseDependencies'.
> Could not resolve all task dependencies for configuration ':app:releaseRuntimeClasspath'.
> Could not resolve org.webkit:android-jsc:+.
Required by:
project :app
> Failed to list versions for org.webkit:android-jsc.
> Unable to load Maven meta-data from https://jcenter.bintray.com/org/webkit/android-jsc/maven-metadata.xml.
> Could not HEAD 'https://jcenter.bintray.com/org/webkit/android-jsc/maven-metadata.xml'.
> Read timed out
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
* Get more help at https://help.gradle.org
Deprecated Gradle features were used in this build, making it incompatible with Gradle 7.0.
Use '--warning-mode all' to show the individual deprecation warnings.
See https://docs.gradle.org/6.7/userguide/command_line_interface.html#sec:command_line_warnings
BUILD FAILED in 2m 37s
Here's my build.gradle file:
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
ext {
buildToolsVersion = "29.0.3"
minSdkVersion = 24
compileSdkVersion = 30
targetSdkVersion = 30
supportLibVersion = "28.0.0"
googlePlayServicesAuthVersion = "16.0.1"
}
repositories {
google()
mavenCentral()
mavenCentral()
}
dependencies {
classpath 'com.facebook.react:react-native:0.12.+'
classpath 'com.android.tools.build:gradle:4.0.0'
classpath 'com.google.gms:google-services:4.2.0'
// 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")
}
maven {
// expo-camera bundles a custom com.google.android:cameraview
url "$rootDir/../node_modules/expo-camera/android/maven"
}
maven { url 'https://maven.google.com' }
maven { url 'https://www.jitpack.io' }
google()
jcenter()
}
}
I can't find any an information about why this is happening bar adding 'www.' to 'https://www.jitpack.io' but it already has that.
'react-native run-android' was working yesterday, since then I changed emulator and also changed java version.
Does anyone know why this is happening?
JCenter is going to shutdown and now is READ-ONLY. And it is getting offline often causing issues with builds and pipelines.
In summary
You will require to update your android/build.gradle file to use mavenCentral() instead of Jcenter().
As per Gradle documentation, JCenter is a mirror of Maven Central, so all of your dependencies should be there.
JCenter is a central artifact repository, like Maven Central. Software
projects use JCenter to distribute their software to other people.
JCenter also serves as a mirror for Maven Central, so any dependencies
available on Maven Central are also available on JCenter (but not vice
versa).
A few things to consider:
In case it is a library (e.g node_modules/react-native-appsflyer), pointing to Jcenter, that is giving you an error... I would advise you to check the library giving you an error has updated a new version with a fix. In case so, update to the new
version to get the changes.
In case the library doesn't have versions with the fix, if you are building in React-native using npm packages, you could potentially take advantage of patch-package library. Because there will a possibility the libraries have not yet released the update removing JCenter from build.gradle.
Applying the patch
You can apply the changes yourself using the Patch Package library. Documentation added in the end for reference.
Go to node_modules/library-with-error/android/build.gradle
Change jcenter() to mavenCentral()
Run: npx patch-package library-with-error
Git add, commit and push
Personal notes:
I did advise the full removal of JCenter instead of adding MavenCentral() to the top because of the shutdown and that JCenter is often getting offline and giving timeout errors.
Based on the current timeline, builds that use JCenter will be able to
resolve dependencies until February 1, 2022 without changes. After
that date, there are no guarantees that you will be able to build
your software if you continue to use JCenter."
Also, Gradle is discouraging the usage of JCenter.
"To discourage new projects from using JCenter, we will be removing
JCenter from our samples and init templates. The new default will be
Maven Central. Gradle itself has no inherent tie to JCenter or Maven
Central, so you can always switch any other repository of your choice.
This change will be effective with the next Gradle release – Gradle
7.0."
In case of dependencies (pom, jar) are not added to Maven, here are instructions on how to add. Add that to the PR with discussions to collaborate.
Useful Links
Add --use-yarn to patch-package command in case your project uses Yarn.
Documentation using Patch package.
We also just ran into this. I believe JCenter is down right now. https://status.bintray.com/
Related
Note: Error may be different but if you are getting any error when taking android build without any changes in code for past two days
My Error - Failed to install the app. Error: Command failed: ./gradlew app:installDebug -PreactNativeDevServerPort=8081
error Failed to install the app. Make sure you have the Android development environment set up:
Error: Command failed: ./gradlew app:installDebug
-PreactNativeDevServerPort=8081
FAILURE: Build failed with an exception.
* Where: Build file '/Users/....../node_modules/react-native-month-year-picker/android/build.gradle' line: 115
* What went wrong: A problem occurred configuring project ':react-native-month-year-picker'.
> Could not resolve all files for configuration ':react-native-month-year-picker:implementation'.
> Could not resolve com.facebook.react:react-native:+.
Required by:
project :react-native-month-year-picker
> Cannot choose between the following variants of com.facebook.react:react-native:0.71.0-rc.0:
- debugVariantDefaultRuntimePublication
- releaseVariantDefaultRuntimePublication
All of them match the consumer attributes:
- Variant 'debugVariantDefaultRuntimePublication' capability com.facebook.react:react-native:0.71.0-rc.0:
The build failures for Android was due to the publish of the React Native version 0.71.0-rc0.
Note: Error may be different but this would be the solution if you are getting android build failures without any changes in code for past two days
before trying these methods please revert back every changes you have done : https://stackoverflow.com/a/74371195/10657559
Method 1
Add this fix to your android -> build.gradle file as follows:
buildscript {
// ...
}
allprojects {
repositories {
exclusiveContent {
filter {
includeGroup "com.facebook.react"
}
forRepository {
maven {
url "$rootDir/../node_modules/react-native/android"
}
}
}
// ...
}
}
What this fix will do is apply an exclusiveContent resolution rule that will force the resolution of React Native Android library, to use the one inside node_modules
Method 2
If your gradle doesn't support above, then add this to your android -> build.gradle file as follows:
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())
buildscript {
// ...
}
allprojects {
configurations.all {
resolutionStrategy {
force "com.facebook.react:react-native:" + REACT_NATIVE_VERSION
}
}
// ...
}
Ref: Fix and updates on Android build failures happening since Nov 4th 2022 #35210
Adding on to the voted answer to do some knowledge sharing.
To reiterate, as #Thanhal has posted, the solution and official explanation can be found here: Android build failures No matching variant of com.facebook.react:react-native:0.71.0-rc.0 was found.
The biggest question I needed answer following the error was:
After specifying my react-native version in package.json, why does my project still download another react-native version?
I even used npm install --save-exact to ensure I am getting the correct version
The error message I was given left me even more confused:
The class is loaded from ~/.gradle/caches/transforms-3/9a8c596b7e1788d5bad7c80991eefff1/transformed/jetified-kotlin-stdlib-1.6.10.jar!/kotlin/Unit.class
e: .../node_modules/expo-modules-core/android/src/main/java/expo/modules/adapters/react/permissions/PermissionsService.kt: (351, 32): Class 'kotlin.Unit' was compiled with an incompatible version of Kotlin. The binary version of its metadata is 1.6.0, expected version is 1.4.1.
Somehow Kotlin became an issue for me as well.
Who / What is asking for the latest react-native?
For my case, the issue here wasn't about the version of react-native my project is using. It was about what my libraries are using.
The react-native team had been shipping a Maven Repository inside the NPM package (node_modules/react-native/android/) up till 0.71.0-rc.0. Most of the libraries have their build.gradle configured to reference to this directory. This is done through declaring a custom repository in the libraries' build.gradle:
maven {
url "$rootDir/../node_modules/react-native/android"
}
But in the libraries' build.gradle files, more repositories are declared, which may look like this:
repositories {
maven {
url "$rootDir/../node_modules/react-native/android"
}
google()
mavenLocal()
mavenCentral()
}
Then, the dependency for the library is declared as so:
dependencies {
implementation 'com.facebook.react:react-native:+'
}
Because the "+" as version for the react-native dependency, Gradle will take the latest react-native version from the various declared repositories.
Since in the past react-native was shipped with npm package, the latest which Gradle will always take the react-native in node_modules. However, now that the react-native team is publishing the library to public repositories including MavenCentral, Gradle honours the "+" and take the version on MavenCentral instead.
Why did I get the Kotlin error?
My project uses an older version of react-native and as of version 0.68 react-native started using Kotlin version 1.6.10 (see the change history). So yes, the difference in react-native version would also result in Kotlin error.
Facebook has release bugfix versions for >=0.63. You can upgrade instead of apply the hotfix also.
https://github.com/facebook/react-native/issues/35210
This fix works:
Reason for Failures : The build failures for Android was due to the publish of the React Native version 0.71.0-rc0 to Maven and because of which when the gradle is syncing its picking this 0.71.0-rc0 version of react-native rather then your current version of react-native.
Made it work without upgrading react-native version and by adding this in build.gradle, this works (hermes enabled or not, along with flipper too)
exclusiveContent {
// We get React Native's Android binaries exclusively through npm,
// from a local Maven repo inside node_modules/react-native/.
// (The use of exclusiveContent prevents looking elsewhere like Maven Central
// and potentially getting a wrong version.)
filter {
includeGroup "com.facebook.react"
}
forRepository {
maven {
url "$rootDir/../node_modules/react-native/android"
}
}
}
final snippet looks like this
allprojects {
repositories {
exclusiveContent {
// We get React Native's Android binaries exclusively through npm,
// from a local Maven repo inside node_modules/react-native/.
// (The use of exclusiveContent prevents looking elsewhere like Maven Central
// and potentially getting a wrong version.)
filter {
includeGroup "com.facebook.react"
}
forRepository {
maven {
url "$rootDir/../node_modules/react-native/android"
}
}
}
maven {
// All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
url("$rootDir/../node_modules/react-native/android")
gradle clean and rebuild after this fix. Then you can react native run android successfully.
What this fix will do is apply an exclusiveContent resolution rule that will force the resolution of React Native Android library, to use the one inside node_modules
Now,
There are some patch releases from react native for different versions, If you dont want to put this fix,
you can update your current react native version to the react native patch version as mentioned here
https://github.com/facebook/react-native/issues/35210
I am trying to build my project but it seems the jcenter is down.
$ cd android
$ sudo ./gradlew assembleRelease
> Task :app:lintVitalRelease FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:lintVitalRelease'.
> Could not resolve all artifacts for configuration ':react-native-community_masked-view:releaseRuntimeClasspath'.
> Could not resolve com.facebook.react:react-native:+.
Required by:
project :react-native-community_masked-view
> Failed to list versions for com.facebook.react:react-native.
> Unable to load Maven meta-data from https://jcenter.bintray.com/com/facebook/react/react-native/maven-metadata.xml.
> Could not HEAD 'https://jcenter.bintray.com/com/facebook/react/react-native/maven-metadata.xml'. Received status code 502 from server: Bad Gateway
JCenter is going to shutdown and now is READ-ONLY. And it is getting offline often causing issues with builds and pipelines.
In summary
You will require to update your android/build.gradle file to use mavenCentral() instead of Jcenter().
As per Gradle documentation, JCenter is a mirror of Maven Central, so all of your dependencies should be there.
JCenter is a central artifact repository, like Maven Central. Software
projects use JCenter to distribute their software to other people.
JCenter also serves as a mirror for Maven Central, so any dependencies
available on Maven Central are also available on JCenter (but not vice
versa).
A few things to consider:
In case it is a library (e.g node_modules/react-native-appsflyer), pointing to Jcenter, that is giving you an error... I would advise you to check the library giving you an error has updated a new version with a fix. In case so, update to the new
version to get the changes.
In case the library doesn't have versions with the fix, if you are building in React-native using npm packages, you could potentially take advantage of patch-package library. Because there will a possibility the libraries have not yet released the update removing JCenter from build.gradle.
Applying the patch
You can apply the changes yourself using the Patch Package library. Documentation added in the end for reference.
Go to node_modules/library-with-error/android/build.gradle
Change jcenter() to mavenCentral()
Run: npx patch-package library-with-error
Git add, commit and push
Personal notes:
I did advise the full removal of JCenter instead of adding MavenCentral() to the top because of the shutdown and that JCenter is often getting offline and giving timeout errors.
Based on the current timeline, builds that use JCenter will be able to
resolve dependencies until February 1, 2022 without changes. After
that date, there are no guarantees that you will be able to build
your software if you continue to use JCenter."
Also, Gradle is discouraging the usage of JCenter.
"To discourage new projects from using JCenter, we will be removing
JCenter from our samples and init templates. The new default will be
Maven Central. Gradle itself has no inherent tie to JCenter or Maven
Central, so you can always switch any other repository of your choice.
This change will be effective with the next Gradle release – Gradle
7.0."
In case of dependencies (pom, jar) are not added to Maven, here are instructions on how to add. Add that to the PR with discussions to collaborate.
Useful Links
Add --use-yarn to patch-package command in case your project uses Yarn.
Documentation using Patch package.
JFrog will keep JCenter as a read-only repository indefinitely. JCenter users and the community can continue to rely on JCenter as a reliable mirror for Java packages. You may visit https://www.jfrog.com/confluence/display/JFROG/JFrog+Bintray+Migration+Guide
for further details.
android -> build.gradle
allprojects {
repositories {
all { ArtifactRepository repo ->
if(repo instanceof MavenArtifactRepository){
def url = repo.url.toString()
if (url.startsWith('https://jcenter.bintray.com/')) {
remove repo
}
}
}
mavenCentral()
}
}
I checked out and built the project at https://github.com/kosiara/artoolkit-android-studio-example
I have Android Studio 4.0.2 on Windows 10.
The build error I get is:
Executing tasks: [:app:assembleDebug] in project D:\Downloads\artoolkit-android-studio-example-master\artoolkit-android-studio-example-master
FAILURE: Build failed with an exception.
* What went wrong:
A problem occurred configuring project ':app'.
> A problem occurred configuring project ':base'.
> Could not resolve all dependencies for configuration ':base:_debugCompile'.
> Could not find com.android.support:appcompat-v7:23.1.1.
Searched in the following locations:
https://jcenter.bintray.com/com/android/support/appcompat-v7/23.1.1/appcompat-v7-23.1.1.pom
https://jcenter.bintray.com/com/android/support/appcompat-v7/23.1.1/appcompat-v7-23.1.1.jar
Required by:
artoolkit-android-studio-example-master:base:unspecified
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
BUILD FAILED
Total time: 1.346 secs
I'm afraid I don't understand what is wrong.
I'm not sure what needs to be set to version 23.1.1. I looked in my Android SDK manager under SDK Tools, Android SDK Build-Tools and there is no option for 23.1.1. (Is that even where I should be looking?) I see 23.0.1, 23.0.2 (Installed), 23.0.3. Also the Android SDK Platform 23 is installed.
Do I need to add a custom Site to get the missing 23.1.1 option? I have no idea how to do that or what site it would be, if that's what's required.
I suspect there's likely something not set up correctly about my SDK or Android Studio, but I don't know what to check next.
I see this related question but that question has no answer.
I'd like some help getting this example to build.
That version of that module (appcompat-v7) is not in the JCenter repository.
You have to add google maven using the old way when you're using an old version of Gradle, you are not allowed to use google() on Gradle v1.5.
build.gradle (project level)
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
jcenter()
maven {
url 'https://maven.google.com/'
name 'Google'
}
}
dependencies {
classpath 'com.android.tools.build:gradle:1.5.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
maven {
url 'https://maven.google.com/'
name 'Google'
}
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
I'm getting error when i try to run android code in react native using react-native run-android.
I am running code on ubuntu.
rahul#rahul-Inspiron-15-3567 ~/Documents/reactNative/crowdalert/CrowdAlert-Mobile master ● react-native run-android
Scanning folders for symlinks in /home/rahul/Documents/reactNative/crowdalert/CrowdAlert-Mobile/node_modules (8ms)
JS server already running.
Building and installing the app on the device (cd android && ./gradlew installDebug)...
> Configure project :app
WARNING: The option 'android.enableAapt2' is deprecated and should not be used anymore.
Use 'android.enableAapt2=true' to remove this warning.
It will be removed at the end of 2018..
Reading env from: .env
WARNING: Configuration 'compile' is obsolete and has been replaced with 'implementation' and 'api'.
It will be removed at the end of 2018. For more information see: http://d.android.com/r/tools/update-dependency-configurations.html
FAILURE: Build failed with an exception.
* What went wrong:
A problem occurred configuring project ':app'.
> Failed to notify project evaluation listener.
> JAVA_LETTER_OR_DIGIT
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
* Get more help at https://help.gradle.org
running the app in react native too shows the same error.These are my versions of gradle and react-native:
react-native-cli: 2.0.1
react-native: 0.51.0
Gradle 4.4
Project level build.gradle file.
buildscript {
repositories {
google()
jcenter()
maven {
url 'https://maven.fabric.io/public'
}
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.3.3'
classpath 'com.android.tools.build:gradle:3.1.2'
classpath 'com.google.gms:google-services:4.3.2'
classpath 'io.fabric.tools:gradle:1.25.1'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
mavenLocal()
jcenter()
maven {
// All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
url "$rootDir/../node_modules/react-native/android"
}
maven {
url "https://maven.google.com"
}
}
}
You probably have a version mismatch with your RN version and gradle. For ReactNative 0.51, you should use gradle 3.5. But this is not the only problem. Your project is out of date. You probably won't be able to publish your app to Google Play store, because Google introduced new publishing format (App Bundle) and your release apk will be rejected by the Play store. See more here: https://developer.android.com/platform/technology/app-bundle
To make that possible, you need to upgrade to gradle 5.5, and do that with React Native, you'll need to upgrade to 0.60+ version. See how to do that here: https://facebook.github.io/react-native/docs/upgrading
If you get lost upgrading the current project, alternative is to initialize a new project, link dependencies and c/p block-by-block of your code and adjust your code to new versions of libraries you use (if necessary).
Linux environment using jenkins android gradle project to build an error
* What went wrong:
A problem occurred configuring project ':app'.
> Could not download glide.jar (com.github.bumptech.glide:glide:3.7.0)
> Could not get resource 'https://jcenter.bintray.com/com/github/bumptech/glide/glide/3.7.0/glide-3.7.0.jar'.
> Could not GET 'https://jcenter.bintray.com/com/github/bumptech/glide/glide/3.7.0/glide-3.7.0.jar'.
> repo.jfrog.org: unknown error
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
I tried to use the wget way to download the link will prompt an error, then I use the sudo way to download the link successfully. So, how can I make jenkins gradle also use the sudo download, or use other solutions
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
jcenter()
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.2.1'
classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8'
classpath 'me.tatarka:gradle-retrolambda:3.2.5'
classpath 'me.tatarka.retrolambda.projectlombok:lombok.ast:0.2.3.a2'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
// Exclude the version that the android plugin depends on.
configurations.classpath.exclude group: 'com.android.tools.external.lombok'
}
allprojects {
repositories {
jcenter()
mavenCentral()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
Please help me, thanks.
You can try upload your local library (in user/.gradle/caches) to Jenkins server, It 's work for me.
I don't think that run the build with super user rights is a good solution, because it's not seems to be possible to resolve dependencies.
Just a suggestion how to solve it: Gradle has it's own local cache for dependencies and doesn't need to download them on every build. So you may use the same Gradle distribution, which is used by Jenkins, and once build your application manually with su rights, to resolve all dependencies and cache them.
Just to note, by default dependencies with dynamic versions are cached for 24 hours only, as it's said in the official docs, but you can change it as:
configurations.all {
resolutionStrategy.cacheDynamicVersionsFor 10, 'minutes'
resolutionStrategy.cacheChangingModulesFor 4, 'hours'
}