Android .idea/misc.xml 的 languageLevel 标签不断变化 JDK [英] Android .idea/misc.xml's languageLevel tag keeps changing JDKs

查看:39
本文介绍了Android .idea/misc.xml 的 languageLevel 标签不断变化 JDK的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

由于我不知道的原因,languageLevel 键从 JDK_1_8 更改为 JDK_1_7.

The languageLevel key gets changed from JDK_1_8 to JDK_1_7 for reasons I am not aware.

会发生什么?

这与从事该项目的其他开发人员的 IDE 有关系吗?也许他们有另一个 Android Studio 设置?

Does this have something to do with the IDE of other developers working on the project? Maybe they have another Android Studio setting?

这是我注意到源代码管理下的文件发生更改后弹出的内容:

Here is what pops up after I notice files under source control have changed:

$ git diff
diff --git a/.idea/misc.xml b/.idea/misc.xml
index fbb6828..5d19981 100644
--- a/.idea/misc.xml
+++ b/.idea/misc.xml
@@ -37,7 +37,7 @@
     <ConfirmationsSetting value="0" id="Add" />
     <ConfirmationsSetting value="0" id="Remove" />
   </component>
-  <component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" default="true" assert-keyword="true" jdk-15="true" project-jdk-name="1.8" project-jdk-type="JavaSDK">
+  <component name="ProjectRootManager" version="2" languageLevel="JDK_1_7" default="true" assert-keyword="true" jdk-15="true" project-jdk-name="1.8" project-jdk-type="JavaSDK">
     <output url="file://$PROJECT_DIR$/build/classes" />
   </component>
   <component name="ProjectType">

这是我的 gitignore,以防万一.

This is my gitignore in case it matters.

.gradle
/local.properties
/.idea/workspace.xml
/.idea/libraries
.DS_Store
/build
/captures

我该如何进行才能让它保持一种或另一种方式?

How do I proceed so that it just stays one way or the other?

推荐答案

这让我抓狂了一段时间.我能够通过在我的 build.gradle 中显式设置 java 版本来修复它:

This was driving me nuts for a while. I was able to fix it by explicitly setting the java version in my build.gradle:

android {
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_7
        targetCompatibility JavaVersion.VERSION_1_7
    }
}

请注意,如果您使用的是 VERSION_1_7,当您冷启动 Android Studio 或切换到另一个使用 VERSION_1_8 的项目时,它会修改 .idea/misc.xml 使用 JDK_1_8.进行 gradle 同步会将其恢复为使用 JDK_1_7.如果您使用的是 VERSION_1_8,则不会遇到此问题.

Note that if you're using VERSION_1_7, when you cold launch Android Studio or switch to another project that uses VERSION_1_8, it will modify .idea/misc.xml to use JDK_1_8. Doing a gradle sync will revert it back to using JDK_1_7. If you're using VERSION_1_8, you won't have this issue.

它并不完美,但我发现现在已经足够了.

It's not perfect but I found this to be good enough for now.

这篇关于Android .idea/misc.xml 的 languageLevel 标签不断变化 JDK的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆