Gradle Sync Failure: Could not resolve all artifacts for configuration

Viewed 9083

When trying to Sync Gradle I am getting the following error:

A problem occurred configuring project ':react-native-google-signin'.
> Could not resolve all artifacts for configuration ':react-native-google-signin:classpath'.
   > Could not find com.android.tools.build:gradle:3.6.3.
     Searched in the following locations:
       - https://jcenter.bintray.com/com/android/tools/build/gradle/3.6.3/gradle-3.6.3.pom
       - https://jcenter.bintray.com/com/android/tools/build/gradle/3.6.3/gradle-3.6.3.jar
     Required by:
         project :react-native-google-signin

I have had a search and I am unable to find an answer to this. A similar question here: React native android can not find com.android.tools.build:gradle:3.6.3

Looking at the above this suggests switching off Offline mode, which is not on, so, unfortunately, that is not the answer.

The root bundle.gradle file looks like this:

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
  ext {
        buildToolsVersion = "28.0.3"
        minSdkVersion = 16
        compileSdkVersion = 28
        targetSdkVersion = 28
        supportLibVersion = "28.0.0-alpha1"
      reactNativeVersion = "0.59.9"
    googlePlayServicesAuthVersion = "16.0.1"
  }
    repositories {
        google()
        maven {
          url 'https://maven.google.com/'
        }
        jcenter()
        mavenCentral()
        maven {
            url 'https://maven.fabric.io/public'
        }
        maven { url 'https://dl.bintray.com/android/android-tools' }

      maven {url "$projectDir/../node_modules/react-native/android"}
    }
    dependencies {
        classpath('com.android.tools.build:gradle:3.4.1')
        classpath 'com.google.gms:google-services:4.1.0'
        classpath 'io.fabric.tools:gradle:1.25.4'
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        google()
        mavenLocal()
        maven {
            // All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
            url "$rootDir/../node_modules/react-native/android"
        }
        // React native video - exoplayer missing from google repos, temp fix
        maven {
            url "https://google.bintray.com/exoplayer/"
        }
        maven {
            url 'https://maven.google.com/'
            name 'Google'
        }
        jcenter()
//        configurations.all {
//            resolutionStrategy {
//                force 'com.facebook.android:facebook-android-sdk:4.28.0'
//            }
//        }
    }
}

Based on the error it seems it only searches in jcenter and not the others? I am not sure, but when I searched online this specific build is available from maven.google.com which is included?

4 Answers

Replace your android/build.gradle with this i.e in your project level gradle with this

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:2.2.3'
        classpath 'com.google.gms:google-services:3.0.0'

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        mavenLocal()
        maven {url "https://maven.google.com"} //<---- this should be added and should be aboce jcenter
        maven {url "$rootDir/../node_modules/react-native/android"}
        jcenter()
    }
}

After that clear your gradle inside android/

gradlew clean

Then run the react native application.

NOTE: Use your own gradle and google service versions in above snippet

You should move to Androidx

AndroidX is a major improvement to the original Android Support Library, which is no longer maintained. You can migrate an existing project to AndroidX by selecting Refactor > Migrate to AndroidX from the menu bar.

Upgrade

    classpath 'com.android.tools.build:gradle:3.6.3'
    classpath 'com.google.gms:google-services:4.3.2'

And

    buildToolsVersion = "29.0.2"
    minSdkVersion = 16
    compileSdkVersion = 29
    targetSdkVersion = 29

You should try doing:

react native link

I got this error after enabling flutter web which automatically upgraded my gradle file, so firstly disable your flutter web and update your compileSdkVersion and targetSdkVersion to the last version which is up to now 30

Related