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

后端 未结 6 1838
傲寒
傲寒 2020-12-03 21:23

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 an

相关标签:
6条回答
  • 2020-12-03 21:36

    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.

    0 讨论(0)
  • 2020-12-03 21:39

    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.

    0 讨论(0)
  • 2020-12-03 21:48

    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.

    0 讨论(0)
  • 2020-12-03 21:49
    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

    0 讨论(0)
  • 2020-12-03 21:49

    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.

    0 讨论(0)
  • 2020-12-03 21:56

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

    0 讨论(0)
提交回复
热议问题