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?
38 Answers
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 of STUDIO_JDK, JDK_HOME or JAVA_HOME environment variables to point to the JDK location.
studio.sh checks the STUDIO_JDK, JDK_HOME, and JAVA_HOME environment variables in order:
if [ -n "$STUDIO_JDK" -a -x "$STUDIO_JDK/bin/java" ]; then JDK="$STUDIO_JDK"
elif [ -n "$JDK_HOME" -a -x "$JDK_HOME/bin/java" ]; then JDK="$JDK_HOME"
elif [ -n "$JAVA_HOME" -a -x "$JAVA_HOME/bin/java" ]; then JDK="$JAVA_HOME"So you can just set them as appropriate and then Studio will pick it up.
1It 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!
3This worked for me:
Find out the java directory:
$ echo $JAVA_HOME /usr/lib/jvm/java-7-oracleOpen Android Studio and then File-> Project Structure.
- Under SDK Location I past the java directory from above
- Wait a couple of seconds and I got "0 errores 0 advertencias"
It worked! :)
Steps I followed:
Opened terminal and enter
echo $JAVA_HOMECopied 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 the STUDIO_JDK variable before running studio.sh in a terminal:
STUDIO_JDK=./bin/jdk/ ./bin/android-studio/bin/studio.sh 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.