112

I've setup the environment for react native on Windows. But when I run the command

react-native run-android

I get the following errors -

* What went wrong:
A problem occurred configuring project ':app'.
> Failed to notify project evaluation listener.
   > Could not initialize class com.android.sdklib.repository.AndroidSdkHandler

How do I fix this?

Paul Santosh
  • 1,121
  • 2
  • 7
  • 3

9 Answers9

147

This is because your classpath build tools in build.gradle root project is deprecated. Update it like this

buildscript {
    repositories {
        google()
        mavenCentral()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:7.0.0'
    }
}

and after that update your minimum sdk and build tools to latest and no problem again

Hasan Jamshaid
  • 1,659
  • 1
  • 11
  • 14
  • 3
    this work for me; I'm on windows 10 android studio 4.2 C15 – Miguel Tomás Mar 05 '21 at 09:12
  • 2
    With that advice, I get Could not find com.android.tools.build:gradle:3.1.2. Searched in the following locations: - https://jcenter.bintray.com/com/android/tools/build/gradle/3.1.2/gradle-3.1.2.pom - https://jcenter.bintray.com/com/android/tools/build/gradle/3.1.2/gradle-3.1.2.jar Required by: project : Add google Maven repository and sync project Open File – Gerd May 20 '21 at 14:26
  • 2
    I'm building an old project, and this fix it for me, and build successfully. – QuartZ Jul 05 '21 at 13:09
  • 1
    For me the important part was adding the `google()` repository. I'm trying to build an old project from GitHub, and it only had `mavenCentral()` but that hasn't included the build tools since 3.0 – Auspex Apr 09 '23 at 10:43
64

I encountered this error while running the following command in macOS

./gradlew assembleRelease --stacktrace

and got the exact error posted. I solved the problem by setting $JAVA_HOME environment variable to your JDK installation. In my case I used the bundled JDK in Android Studio for macOS:

export JAVA_HOME="/Applications/Android Studio.app/Contents/jre/jdk/Contents/Home"

for Windows, just add JAVA_HOME to your user or system variables pointing to

"C://Program Files/Java/jdk_1.x_"

folder and try running react-native run-android again.

33

This will resolve issue to follow below steps:

1) Change Project level Gradle version build.gradle

Earlier version name like

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

Change with new version or latest version you have

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

2) Change gradle-wrapper.properties from \gradle\wrapper

Earlier version name like

distributionUrl=https\://services.gradle.org/distributions/gradle-4.8.1-bin.zip

Change with new version or latest version you have

distributionUrl=https\://services.gradle.org/distributions/gradle-6.7.1-bin.zip

Pratik Dodiya
  • 2,337
  • 1
  • 19
  • 12
16

This is a problem with JDK version 9. Android tools does not support building with Java 9 officially yet. And it has such problems.

Downgrading to Java version 8 will fix the problem.

tasomaniac
  • 10,234
  • 6
  • 52
  • 84
7

On Ubuntu 18.04, this fixed the problem.

  1. Run this command

    sudo apt-get install openjdk-8-jdk

  2. Add this to ~/.bashrc

    export JAVA_HOME="/usr/lib/jvm/java-8-openjdk-amd64"

  3. Restart your terminal or IDE.

Community
  • 1
  • 1
takasoft
  • 1,228
  • 15
  • 15
3

According to the log, add the google() repository to the build.gradle file in the app directory as shown below:

allprojects {
    repositories {
        mavenCentral()
        google()
        jcenter()
    }
}
Shomu
  • 2,734
  • 24
  • 32
0

The possible reason is the Gradle 's version and JDK's version is not matched.

At begin, My computer's gradle version is 4.10.1 and JDK is 12.

My solution is:

Download JDK 1.8 from oracle's website, set JAVA_HOME with JDK8 and It done

jerry
  • 11
  • 2
0

Replace jcenter() with google()

and

mavenCentral()

in project level gradle file

Ibrahim
  • 1
  • 2
-1

Fixed the error by adding the following in .bash_profile

 export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_171.jdk/Contents/Home
export PATH=$PATH:$JAVA_HOME/bin
export ANDROID_HOME=/Users/saif-ams/MyFiles/applications/androidsdk
export PATH=$PATH:$ANDROID_HOME/tools:$ANDROID_HOME/platform-tools
Saif Kamaal
  • 192
  • 1
  • 9