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

7

19

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?

Ultraconservative answered 28/6, 2016 at 4:15 Comment(1)
My path has User 1 and Program Files, basically the answer here: #34200142 I had to remove spaces from both the JDK and the SDK, not just the JDK. So basically copied/pasted dirFrederiksen
U
36

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).

Ultraconservative answered 28/6, 2016 at 4:39 Comment(11)
Could you give me the location of the config file. I could not find itOakland
Go to the driver where your Windows is installed. There will be a folder named 'Users' or 'Documents and Settings'. In there, you'll find a folder with your username on it. Inside it will be a folder called .AndroidStudio followed by the version number of your installation. Once you locate this particular folder, find the 'config' folder inside it. There you will see the mentioned file. @GuynamedJonUltraconservative
The fastest way (that I found via Google) to get to your User folder is to press Windows key + R and open the Run dialog box. In there, type this "%userprofile%" (without the quotes). Press enter.Ultraconservative
I tried removing jdk.table.xml and restarting studio, still the new file getting created with jdk 1.7. I have both JDK_HOME and JAVA_HOME environment variable setup. Any help here greatly appreciated.Bevus
I don't know if this will work but try to uninstall JDK7 from your system and only leave 8. Restart your PC. Check the PATH variable as well.Ultraconservative
Can confirm, AS 2.1.x will fetch the default JDK from the JAVA_HOME env var. (had 8_66 and 8_101 installed and it used 8_66 which was set in the env var)Alcuin
I have updated JAVA_HOME and the deleted jdk.table.xml and restarted it,still the problem is same I faced. please, help me.Cicada
First, try to uninstall JDK 1.7 and then follow the above instructions.Ultraconservative
You got your environment variables set up correctly? JDK_HOME needs to point to java 1.8. Best option is to remove 1.7, restart, install 1.8, set up the variables then try the above method.Ultraconservative
close android studio , replace everything in file with C:/Program Files/Java/jdk1.8.0_101 , re-open studio , SyncIra
@Ultraconservative Thanks man! It answered me for the question https://mcmap.net/q/267035/-android-studio-unresolved-reference-for-java-and-javax-imports-but-project-compiles/5434346!Priesthood
I
2
  1. close android studio

  2. go to :

C:\Users\WINDOW_USER_NAME\AndroidStudio2.1\config\options

open jdk.table.xml

  1. replace all with your JDK version , in my case replaced all with :

    C:/Program Files/Java/jdk1.8.0_101

  2. re-open android-studio

  3. Sync

Ira answered 8/1, 2017 at 9:45 Comment(0)
S
0

What you want to do after deleting the xml file is NOT to close android studio before doing this. Because when android boots back up again it will check its referral settings and say "oh this user may have deleted the table of the jdk, but he still had 1.7 selected by default."

No, when you delete the table file keep studio open. Then select 1.8 so that way it will save the reference settings back to the table. You might not have to restart either since the table xml file is not a currently running file since its in the own users profile folder and not in program files.

Sterne answered 29/9, 2016 at 0:39 Comment(0)
B
0

follow these steps:(the steps are for windows; reach the same directories in case of other operating systems)

Step 1: Press "Win + R", type in "%userprofile%" and press enter.

Step 2: Go to the Android Studio folder which will be in the following format - ".AndroidStudio2.2" (the version may vary)

Step 3: Go to the "config\options" folder.

Step 4: Make a copy of jdk.table.xml at desktop and Delete jdk.table.xml . (Do it while the android studio is still running)

Step 5: In android Studio -Go to "File-> Project Structure" and select the correct jdk path.

IF STEP 4 and STEP 5 do not solve the problem, follow these steps::

Step 4': Open jdk.table.xml in notepad.

Step 5': Find all the words including jdk version - for eg. find "1.8.0_45"

Step 6': Replace the words found; with your current jdk version . For eg. change "1.8.0_45" to "1.8.0_111" (make sure you replace all the fields containing the version number)

Step 7': Save the jdk.table.xml file

Step 8': Restart android studio.

This will definitely solve the issue.

PS: JDK should be installed and the path should be set.

Blankbook answered 22/12, 2016 at 18:19 Comment(0)
W
0

Only this answer work out for me: https://mcmap.net/q/267034/-cannot-update-jdk-location-in-android-studio

Both, the android SDK and the JDK folders must not contain spaces.

Woman answered 7/11, 2017 at 22:18 Comment(0)
O
0

1) Add this to your app build.gradle (inside the android element)

compileOptions {
    sourceCompatibility JavaVersion.VERSION_1_8
    targetCompatibility JavaVersion.VERSION_1_8
}

I copied this from https://mcmap.net/q/267036/-why-does-android-studio-keep-toggling-languagelevel . Credit goes to the person who posted that (https://stackoverflow.com/users/2910520/matpag), but the correct answer isn't posted anywhere on this question.

Obala answered 9/7, 2019 at 2:4 Comment(0)
S
0

2023 Update

I was trying to update from VERSION 1.8 to VERSION 11. Went through the answers here and found none working. I couldn't find the file at the specified location. The file has been changed in the newer releases.

New Solution:

Step 1: Open the Android Studio and keep it open.

Step 2: Go to the location given below:

C:\Users\{username}\AppData\Roaming\Google\AndroidStudio2022.1\options

or press Win + R and enter the following:

%userprofile%\AppData\Roaming\Google\AndroidStudio2022.1\options

Your latest version of Android Studio might be different.

Step 3: Delete the file jdk.table.xml from the options folder.

Step 4: Change the Gradle JDK to the new JDK in the settings, so that the Studio can save the new path in the file. (Important: Else Studio assigns JDK from it's memory)

Step 5: Restart Android Studio.

This fixed the issue for me. The newly created jdk.table.xml will have the updated JDK values.

Striker answered 17/2, 2023 at 9:24 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.