Skip to content Skip to sidebar Skip to footer

Error: Could Not Initialize Class Com.android.sdklib.repository.androidsdkhandler

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 con

Solution 1:

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

Solution 2:

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.

Solution 3:

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

Solution 4:

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.

Solution 5:

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.

Post a Comment for "Error: Could Not Initialize Class Com.android.sdklib.repository.androidsdkhandler"