I can't compile a default new project for Android 2.1 because(?) the JDK used by Android Studio is JDK 1.7 but it should be JDK 1.6.
To change it I go to File -> Project Structure and try to find the JDK 1.6 location.
But when I select its directory and press OK I get the following error:
Please choose a valid JDK directory
As you can see on the screenshoot I'm trying to set Java 6 OpenJDK 64-bits as the new JDK.
What can I do? Isn't Android Studio compatible with OpenJDK and should I use Oracle JDK instead?
I'm using OpenJDK 7 with Android Studio and it works just fine. (I don't even have Oracle JDK installed at the moment.)
On that screen that you are showing (Project Structure-->SKD Location) I have the following path for the JDK location:
/usr/lib/jvm/java-1.7.0-openjdk-amd64
.By inspecting
studio.sh
, you can also set one ofSTUDIO_JDK
,JDK_HOME
orJAVA_HOME
environment variables to point to the JDK location.studio.sh
checks theSTUDIO_JDK
,JDK_HOME
, andJAVA_HOME
environment variables in order:So you can just set them as appropriate and then Studio will pick it up.
It seems that Android Studio does not recognize OpenJDK, so I need to install the OracleJDK.
Then I choose the path to Oracle JDK and it worked!
This worked for me:
Find out the java directory:
Open Android Studio and then File-> Project Structure.
It worked! :)
Steps I followed:
Opened terminal and enter
echo $JAVA_HOME
Copied the path displayed in terminal - Ctrl+Shift+C copy in Ubuntu terminal
In Android studio - Project Structure - Pasted the copied path
Waited for the software to recognize and update the settings
This solved the problem of Invalid Jdk settings
I fixed this problem. I use AS 2.1 and JDK1.7 while it required me to update JDK1.8 for some functions. I download the java setup file. Maybe I only installed jre but not jdk. so AS always warn me that "Please choose a valid JDK directory". So I guess the asker's problem same as me that you should install a JDK but not jre.
If you have a
./bin
folder with a JDK and Android Studio, you can set theSTUDIO_JDK
variable before runningstudio.sh
in a terminal:I think that you might have installed the jdk somewhere else for e.g.
/usr/local/java
. In my case also I saw the same folder name in the directory shown in your screenshot.So just check if the jdk is present somewhere else.