Zimad
Zimad

Reputation: 353

Android Studio - Could not determine Java version

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

Upvotes: 27

Views: 42494

Answers (11)

asim ali
asim ali

Reputation: 1

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

  1. you have selected the latest versions of the Android Gradle Plugin and Gradle version
  2. CompileSdkVersion and targetSdkVersion are same
  3. 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.

Upvotes: 0

no_cola
no_cola

Reputation: 1160

Change this:

targetCompatibility 'JavaVersion.VERSION_1_8'
sourceCompatibility 'JavaVersion.VERSION_1_8'

to this:

targetCompatibility JavaVersion.VERSION_1_8
sourceCompatibility JavaVersion.VERSION_1_8

Upvotes: 83

Islam Assem
Islam Assem

Reputation: 1512

well ,what solved the problem for me is that i didn't use embeded jdk and then set java version to java 7 and build it gave me error because of lambda expression then i set java version to 1.8 and sync then build and it worked

Upvotes: 0

Vick Tim
Vick Tim

Reputation: 97

Nothing of this worked for me so in case it can help someone else : Right click on "app" in your project, go to "Open Module Settings">"Properties" and change the source compatibility and target compatibility to the Java version you need.

Upvotes: 0

Rob Johnny Tanen
Rob Johnny Tanen

Reputation: 1

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!

Upvotes: 0

ked
ked

Reputation: 2456

change distributionUrl in gradle/wrapper/gradle-wrapper.properties to new version of gradle

Upvotes: 3

user7007189
user7007189

Reputation: 21

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

Upvotes: 2

Anantha Raju C
Anantha Raju C

Reputation: 1907

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

Upvotes: 6

Nick Spacek
Nick Spacek

Reputation: 4773

One potential problem is that older versions of Gradle can't parse the Java version from the java -version output produced by the OpenJDK. Newer versions can (I think it was updated around Gradle 2.2; the latest, 2.9, works).

Upvotes: 3

Zimad
Zimad

Reputation: 353

I simply changed default java JDK from Oracle JDK to OpenJDK. Works like a charm.

Upvotes: 0

Filipe Batista
Filipe Batista

Reputation: 1854

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

Upvotes: 1

Related Questions