Error: Could not initialize class com.android.sdklib.repository.AndroidSdkHandler

Paul Santosh picture Paul Santosh · Oct 24, 2017 · Viewed 25.4k times · Source

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?

Answer

Jeremy Patrick Pacabis picture Jeremy Patrick Pacabis · Nov 28, 2017

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.