I installed a fresh copy of Android Studio using terminal but when i create a new project it gives the error "Could not determine Java Version". JDK and SDK both are installed. Android Studio is updated to the latest version. I am using Ubuntu 14.04 LTS
11 Answers
I faced the same issue, but on windows 7 OS. It was because multiple versions of java was present in the same location C:\Program Files\Java Java 5, 7, 8, and 9. Although the Environment variables JAVA_HOME and PATH were set to Java 8, Android studio was referring to Java 9.
My Solution, in the menu, click on File > Project Structure here, point JDK to appropriate location C:\Program Files\Java\jdk
I faced the same issue, in ubuntu 16. It was because multiple versions of java was present in the same location 7, 8 and 9. Although the Environment variables JAVA_HOME and PATH were set to Java 8, Android studio was referring to Java 9.
My Solution, in the menu, click on File > Project Structure here, select 8 version
Did you set the JAVA_HOME environment? run echo $JAVA_HOME in your terminal and see if you get a valid path to your Java binaries.
if not, set the the JAVA_HOME:
nano .bashrc
Add the lines:
export JAVA_HOME=<path to jdk>
export PATH=$JAVA_HOME/bin:$PATH
Save the file and then reload the .bashrc
source ~/.bashrc
Similar to Keds's answer. In android Studio, in Project Tab/File Explorer go to Gradle Scripts -> gradle.properties
You will see something like this:
#Sat Sep 21 13:08:26 CEST 2013
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=http\://services.gradle.org/distributions/gradle-2.4-all.zip
The distributionURL is old and, I'm assuming based on other answers, could not parse the Java version appropriately.
So picked a newer version by going to this site: http://services.gradle.org/distributions/
I picked
distributionUrl=http\://services.gradle.org/distributions/gradle-4.8.1-all.zip
just because. There are newer versions, such as 4.10.2, but I'm not really using gradle, it's just required for the project.
Also, although it didn't really affect me running my project, my project wasn't pointing to the new JDK. It was pointing to Android Studio's jre file automatically as recommended.
If you want to change this, get the file path location of the newest Java JDK. Usually in
C:\Program Files\Java\your_jdk_file
for windows. In Android Studio, go to File -> Project Structure -> SDK Location.
Uncheck 'Embedded JDK (recommended)', then paste the file path to the newest JDK file path for the entire file.
Such as
C:\Program Files\Java\jdk-10.0.2
And not just the bin file. Good luck!
While opening an old android project with latest version of the android studio many compilation errors occur. However, following steps worked for me to update the project settings and build scripts.
Open File->Project Structure and make sure that
- you have selected the latest versions of the Android Gradle Plugin and Gradle version
- CompileSdkVersion and targetSdkVersion are same
- compileSdkVerrion and buildToolsVersion are compatible (if not exactly same)
In the project level build.gradle file make sure google() is added to the repositories for buildscript{} and allprojects{}.
In the module level build.gradle file, replace the word compile with implementation and testCompile with testImplementation. In the compileOptions{} block remove the single quotes from around the JavaVersion… string.
Synchronize again and make the project.