Reputation: 451
I want to build this project with Android Studio at launching, but take a error. Stacktrace is here
Upvotes: 36
Views: 80944
Reputation: 29
Go to build.gradle,
and make sure your gradle dependencies up to date.
For Android studio 4.2.2
dependencies {
classpath 'com.android.tools.build:gradle:4.2.2'
.........
.........
}
Upvotes: 3
Reputation: 1745
One simple solution:
React-Native isn't compatible with Java 9 or Java 10
Resolve this issue by simply downgrading to Java 8
Upvotes: 6
Reputation: 9850
JAVA 9 has forcefully taken over the JAVA_HOME to itself.
after installing java9 you will find
# java -version
java version "9.0.1"
Java(TM) SE Runtime Environment (build 9.0.1+11)
Java HotSpot(TM) 64-Bit Server VM (build 9.0.1+11, mixed mode)
So instead of uninstalling java 9 let us point the JAVA_HOME back to java 8
First find out the Android studio embeded JRE location
and add an entry in ~./bash_profile at last
export JAVA_HOME="/Applications/Android Studio.app/Contents/jre/jdk/Contents/Home"
# source ~/.bash_profile
# java -version
java version "1.8.0_151"
Java(TM) SE Runtime Environment (build 1.8.0_151-b12)
Java HotSpot(TM) 64-Bit Server VM (build 25.151-b12, mixed mode)
source http://scalebean.blogspot.com/2018/01/fix-gradle-could-not-initialize-class.html
Upvotes: 8
Reputation: 905
If the Problem Persists, just import the gradle to Android Studio and build the file inside the Android Studio.
Android Studio automatically handles gradle and sdk problems.
After successful build you can also try running the app via react-native run-android
in the
Command Prompt. Hope this Helps.
This was the only fix that fixed this issue.
I tried all the above answers but problem persisted
Upvotes: 0
Reputation: 1049
this because your classpath build tools in build.gradle root project is deprecated update like this for new android studio 3.2.0
buildscript {
dependencies {
classpath 'com.android.tools.build:gradle:3.2.0-alpha14'
}
and after that update your minimum sdk and build tools to latest and no problem again
Upvotes: 24
Reputation: 38187
If you have several Javas in Ubuntu, you can
sudo update-alternatives --config java
sudo update-alternatives --config javac
to select the Java 8 that Android and Gradle need.
Upvotes: 2
Reputation: 516
This problem occurs when there are multiple JDKs installed in your system, I had the same issue as I had mistakenly installed oracle-jdk-9 and Android studio requires oracle-jdk-8
If you are using Ubuntu you can install jdk-8 from this question.
So, Make following changes as shown below:
Press ctrl+shift+alt+s that will open project structure which can also be opened from
File -> Project Structure
And then change JDK Location where you may have installed JDK 8
Upvotes: 40
Reputation: 270
If anyone is having issues with IntelliJ IDEA, go to File
-> Project Structure
(or press Ctrl + Alt + Shift + S) and remove all JDK 9 entries. JDKs are marked under Platform Settings
-> SDKs
with a folder behind a tiny blue cup of coffee.
I tried adding the correct path to JDK 1.8 but IntelliJ IDEA will default back to JDK 9 for whatever reason. Unfortunately, I need JDK 9 for other projects, so uninstalling it would be too much of a hassle. If you need to use JDK 9 for another project (like I do), you can still add a JDK 9 entry via the same menu and then remove it again when required.
Upvotes: 1
Reputation: 517
Changing the JDK in Android Studio to point back at 8 didn't work for me. I uninstalled Java 9 and this solved the issue.
Upvotes: 7
Reputation: 141
I had the same problem. I had installed Java 8 and Java 9.
I set JAVA_HOME
to Java 8, but Gradle was using Java 9.
I changed the JDK in File->Project Structure to Java 8 and it worked.
Upvotes: 14