Home » Android » react native – Could not find com.android.tools.build:gradle:3.5

react native – Could not find com.android.tools.build:gradle:3.5

Posted by: admin May 14, 2020 Leave a comment

Questions:

I’m trying to update gradle from 1.3.1 to 3.5, as some of my dependencies requires version 3.3 or above.

I’ve seen similar questions, but none of them help.

build.gradle:

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.5'
    }
}

gradle-wrapper.properties:

distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-3.5-all.zip

Still i’m getting this when trying to do anything (build, clean etc):

Building and installing the app on the device (cd android && ./gradlew installDebug...

FAILURE: Build failed with an exception.

* What went wrong:
A problem occurred configuring root project 'chat'.
> Could not resolve all dependencies for configuration ':classpath'.
   > Could not find com.android.tools.build:gradle:3.5.
     Searched in the following locations:
         https://jcenter.bintray.com/com/android/tools/build/gradle/3.5/gradle-3.5.pom
         https://jcenter.bintray.com/com/android/tools/build/gradle/3.5/gradle-3.5.jar
     Required by:
         project :

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

BUILD FAILED
How to&Answers:

To fix this issue check do you have google() repo in your project’s level build.gradle file.

buildscript {
    repositories {
        jcenter()
        google() //HAVE YOU MISS IT?
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.5.0'
    }
}

allprojects {
    repositories {
        jcenter()
        google() //HAVE YOU MISS IT?
    }
}

Answer:

There is a difference between the Android Plugin for Gradle version and the Gradle version being used. The plugin version typically matches the version number of Android Studio you are using. See the documentation for more information. So if using the latest stable Android Studio it should currently be com.android.tools.build:gradle:2.3.1.

These values can also be reviewed and set from the Project Structure window in Android Studio.

enter image description here

Answer:

Try this

  ** If you are using android studio 3.5 and your build.gradle(Project 
level) is=> classpath 'com.android.tools.build:gradle:3.5.1' or => 
classpath 'com.android.tools.build:gradle:3.5.1'.
than replace with *** 

   classpath 'com.android.tools.build:gradle:3.3.2' to 

    classpath 'com.android.tools.build:gradle:3.5.0' 

                   OR 
   classpath 'com.android.tools.build:gradle:3.5.1'

Answer:

You may need to save your build.gradle (for whatever reason, Android Studio doesn’t always save your latest changes, as I found even with Android Studio 3.5.3, the gradle sync kept failing even after I had changed the classpath line, and it only picked up the new value after saving the build.gradle file)

Answer:

I got an error after changing version code from 2 to 2.1.
When I opened the build with ctrl+shift+alt+s, I realized adding .1 (decimals) resulted in a $ symbol being added to the right and so build failed. I opted to use numbers without decimal positions and it worked.
For example, I used 3 for buildversion because I wanted to upgrade the app in playstore.