Fix React Native Android JCenter Bad Gateway error


Problem

If you’re getting the React Native Android build error:

FAILURE: Build failed with an exception.

> Could not resolve com.facebook.react:react-android:0.71.19.
    > Could not get resource 'https://jcenter.bintray.com/com/facebook/react/react-android/0.71.19/react-android-0.71.19.module'.
        > Could not GET 'https://jcenter.bintray.com/com/facebook/react/react-android/0.71.19/react-android-0.71.19.module'. Received status code 502 from server: Bad Gateway

This is because Bintray (JCenter) has been sunsetted (see #31165).

Solution

The preferred solution is to upgrade your React Native dependencies to the latest version.

If that’s not possible, then update android/build.gradle and replace JCenter with Maven Central:

allprojects {
    repositories {
        all { ArtifactRepository repo ->
            if (repo instanceof MavenArtifactRepository) {
                if (repo.url.toString().startsWith('https://jcenter.bintray.com/')) {
                    remove repo
                    add(mavenCentral())
                }
            }
        }
    }
}

See StackOverflow answer.



Please support this site and join our Discord!