Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Studio JDK location changes back to 1.7 every time it is updated to 1.8 path

I recently installed jdk 1.8 u92 after Android Studio said it is needed for api24 builds. However, I've run into this issue now.

I looked at some other solutions and uninstalled jdk 1.7, added environment variables for JDK_HOME, JAVA_HOME, and JAVA8_HOME. The problem still persists.

Every time I try to build the app, gradle sync fails and Android studio asks me to Choose a valid JDK directory. I then go to Project Structure => JDK Location and update it to the 1.8 folder. Trying to build again gives the same error and when I check the Project Structure, the path is set back to the old JDK 1.7 automatically.

Is there any fix for this issue?

like image 468
Asim Avatar asked Jun 28 '16 04:06

Asim


People also ask

How do I change the default JDK location in Android Studio?

Set the JDK version Open your project in Android Studio and select File > Settings... > Build, Execution, Deployment > Build Tools > Gradle (Android Studio > Preferences... > Build, Execution, Deployment > Build Tools > Gradle on a Mac). Under Gradle JDK, choose the Embedded JDK option. Click OK.

Does Android Studio automatically install JDK?

Note that installing Android Studio doesn't automatically configure the built-in JDK command line tools. This matters if you want to use the Android SDK command line tools.

Where is the location of JDK?

The JDK software is installed on your computer, for example, at C:\Program Files\Java\jdk1. 6.0_02. You can move the JDK software to another location if desired.

Where is Java path in Android Studio?

Method #1: For Android Studio Version 4.2 and Above Navigate to File > Project Structure > SDK Location. Upon navigating there you will find that a tab named “JDK Location”, select that and then you can set the JDK path for the current project on which you're working.


1 Answers

Figured it out after looking at a few files inside the Android studio settings directory.

If you've been upgrading your Android Studio and importing settings from previous installations, this might happen (it might also happen with a fresh installation).

Solution:

  1. Go to wherever your Android Studio config folder is located (usually at $HOME/.AndroidStudio2.1/confg).
  2. Open the Options folder and delete the file jdk.table.xml (keep a backup just in case)
  3. Restart Android Studio

This fixed the issue for me. The newly created jdk.table.xml will have updated java8 values (which it most probably fetches from the JDK_HOME environment variable).

like image 111
Asim Avatar answered Oct 11 '22 12:10

Asim