简体   繁体   English

每次更新到1.8路径时,Android Studio JDK位置都会更改回1.7

[英]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. 我最近安装了jdk 1.8 u92,之后Android Studio表示api24版本需要它。 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. 我查看了一些其他解决方案并卸载了jdk 1.7,为JDK_HOME,JAVA_HOME和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 . 每次我尝试构建应用程序时,gradle sync都会失败,Android studio会要求我选择一个有效的JDK目录 I then go to Project Structure => JDK Location and update it to the 1.8 folder. 然后我转到Project Structure => JDK Location并将其更新到1.8文件夹。 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. 尝试再次构建会产生相同的错误,当我检查项目结构时,路径将自动重新设置为旧的JDK 1.7。

Is there any fix for this issue? 这个问题有什么问题吗?

Figured it out after looking at a few files inside the Android studio settings directory. 查看Android studio设置目录中的一些文件后想出来。

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). 如果您一直在升级Android Studio并从之前的安装中导入设置,则可能会发生这种情况(新安装也可能会发生这种情况)。

Solution: 解:

  1. Go to wherever your Android Studio config folder is located (usually at $HOME/.AndroidStudio2.1/confg). 转到Android Studio配置文件夹所在的位置(通常位于$ HOME / .AndroidStudio2.1 / confg)。
  2. Open the Options folder and delete the file jdk.table.xml (keep a backup just in case) 打开Options文件夹并删除文件jdk.table.xml (保留备份以防万一)
  3. Restart Android Studio 重启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). 新创建的jdk.table.xml将具有更新的java8值(最有可能从JDK_HOME环境变量中获取)。

  1. close android studio 关闭android工作室

  2. go to : 去 :

C:\\Users\\WINDOW_USER_NAME\\AndroidStudio2.1\\config\\options C:\\ Users \\用户WINDOW_USER_NAME \\ AndroidStudio2.1 \\设置\\选项

open jdk.table.xml 打开jdk.table.xml

  1. replace all with your JDK version , in my case replaced all with : 用你的JDK版本替换所有版本,在我的情况下全部替换为:

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

  2. re-open android-studio 重新打开android-studio

  3. Sync 同步

What you want to do after deleting the xml file is NOT to close android studio before doing this. 删除xml文件后你想要做的是不要在执行此操作之前关闭android studio。 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." 因为当android再次启动时它将检查其引用设置并说“哦,这个用户可能已经删除了jdk的表,但他仍然默认选择了1.7。”

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. 然后选择1.8,这样它会将参考设置保存回表格。 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. 您可能不必重新启动,因为表xml文件不是当前正在运行的文件,因为它位于自己的用户配置文件文件夹中而不是程序文件中。

follow these steps:(the steps are for windows; reach the same directories in case of other operating systems) 请按照下列步骤操作:(步骤适用于Windows;在其他操作系统的情况下,访问相同的目录)

Step 1: Press "Win + R", type in "%userprofile%" and press enter. 步骤1:按“Win + R”,输入“%userprofile%”并按Enter键。

Step 2: Go to the Android Studio folder which will be in the following format - ".AndroidStudio2.2" (the version may vary) 第2步:转到Android Studio文件夹,其格式如下 - “。Android Studio2.2”(版本可能会有所不同)

Step 3: Go to the "config\\options" folder. 第3步:转到“config \\ options”文件夹。

Step 4: Make a copy of jdk.table.xml at desktop and Delete jdk.table.xml . 步骤4:在桌面上复制jdk.table.xml并删除jdk.table.xml (Do it while the android studio is still running) (当android工作室仍在运行时这样做)

Step 5: In android Studio -Go to "File-> Project Structure" and select the correct jdk path. 步骤5:在android Studio中 - 转到“文件 - >项目结构”并选择正确的jdk路径。

IF STEP 4 and STEP 5 do not solve the problem, follow these steps:: 如果步骤4和步骤5无法解决问题,请按照下列步骤操作::

Step 4': Open jdk.table.xml in notepad. 步骤4':在记事本中打开jdk.table.xml

Step 5': Find all the words including jdk version - for eg. 步骤5':找到所有单词,包括jdk版本 - 例如。 find "1.8.0_45" 找到“1.8.0_45”

Step 6': Replace the words found; 第6步:替换找到的单词; with your current jdk version . 使用您当前的jdk版本。 For eg. 例如。 change "1.8.0_45" to "1.8.0_111" (make sure you replace all the fields containing the version number) 将“1.8.0_45”更改为“1.8.0_111”(确保替换包含版本号的所有字段)

Step 7': Save the jdk.table.xml file 步骤7':保存jdk.table.xml文件

Step 8': Restart android studio. 步骤8':重启android studio。

This will definitely solve the issue. 这肯定会解决这个问题。

PS: JDK should be installed and the path should be set. PS:应安装JDK并设置路径。

Only this answer work out for me: https://stackoverflow.com/a/34199964/1034622 只有这个答案适合我: https//stackoverflow.com/a/34199964/1034622

Both, the android SDK and the JDK folders must not contain spaces. android SDK和JDK文件夹都不能包含空格。

1) Add this to your app build.gradle (inside the android element) 1)将其添加到您的应用build.gradle(在android元素内)

compileOptions {
    sourceCompatibility JavaVersion.VERSION_1_8
    targetCompatibility JavaVersion.VERSION_1_8
}

I copied this from https://stackoverflow.com/a/51032051/326242 . 我从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. 信用发送给发布该信息的人( https://stackoverflow.com/users/2910520/matpag ),但在此问题的任何地方都没有发布正确答案。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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