'jCenter returns 502 Bad Gateway

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


Solution 1:[1]

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.

  1. Go to node_modules/library-with-error/android/build.gradle
  2. Change jcenter() to mavenCentral()
  3. Run: npx patch-package library-with-error
  4. 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."

Useful Links

  • Add --use-yarn to patch-package command in case your project uses Yarn.
  • Documentation using Patch package.

Solution 2:[2]

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.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1
Solution 2 Gajapathi Kimidi