简体   繁体   中英

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?

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

  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

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.

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.

Only this answer work out for me: https://stackoverflow.com/a/34199964/1034622

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

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://stackoverflow.com/a/51032051/326242 . 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM