java Android .idea/misc.xml 的 languageLevel 标签不断变化 JDK
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/32878888/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Android .idea/misc.xml's languageLevel tag keeps changing JDKs
提问by kraftydevil
The languageLevel key gets changed from JDK_1_8 to JDK_1_7 for reasons I am not aware.
由于我不知道的原因,languageLevel 键从 JDK_1_8 更改为 JDK_1_7。
What could be going on?
会发生什么?
Does this have something to do with the IDE of other developers working on the project? Maybe they have another Android Studio setting?
这与从事该项目的其他开发人员的 IDE 有关系吗?也许他们有另一个 Android Studio 设置?
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">
This is my gitignore in case it matters.
这是我的 gitignore 以防万一。
.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?
我该如何继续以使其保持一种或另一种方式?
回答by Noel
This was driving me nuts for a while. I was able to fix it by explicitly setting the java version in my build.gradle
:
这让我发疯了一段时间。我能够通过在我的中显式设置 java 版本来修复它build.gradle
:
android {
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_7
targetCompatibility JavaVersion.VERSION_1_7
}
}
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.
请注意,如果您使用的是VERSION_1_7
,当您冷启动 Android Studio 或切换到另一个使用 的项目时VERSION_1_8
,它会修改.idea/misc.xml
为使用JDK_1_8
. 进行 gradle 同步会将其恢复为使用JDK_1_7
. 如果您正在使用VERSION_1_8
,则不会遇到此问题。
It's not perfect but I found this to be good enough for now.
它并不完美,但我发现这对于现在来说已经足够了。
回答by RED_
Came here from Google after updating to Android Studio 2.2. This might be helpful to others.
更新到 Android Studio 2.2 后从 Google 来到这里。这可能对其他人有帮助。
Since Android Studio 2.2, the JDK has been bundled with it, instead of you having to download and install it on your system. My project JDK started switching when I updated to 2.2, possibly because of the confusion between the two versions available now - system and embedded.
从 Android Studio 2.2 开始,JDK 已与它捆绑在一起,您无需在系统上下载并安装它。当我更新到 2.2 时,我的项目 JDK 开始切换,可能是因为现在可用的两个版本之间的混淆 - 系统和嵌入式。
If you go into File > Project Structure (Mac OS), on the SDK Location tab, there is JDK location. There's now a new setting to use the embedded JDK. Once I switched to it, it solved my issue.
如果您进入文件 > 项目结构 (Mac OS),则在 SDK 位置选项卡上,有 JDK 位置。现在有一个使用嵌入式 JDK 的新设置。一旦我切换到它,它就解决了我的问题。
回答by Pawe? Nadolski
It seems the file should be stored under version control. I would propose to keep it in git, but ignore all local changes:
似乎该文件应该存储在版本控制下。我建议将它保留在 git 中,但忽略所有本地更改:
git update-index --assume-unchanged .idea/misc.xml
When switching branches there might be conflict in these files. Then you could use following imlresetscript to reset the files:
切换分支时,这些文件可能会发生冲突。然后您可以使用以下imlreset脚本来重置文件:
#!/bin/bash
while read f
do
[ -f $f ] && git checkout $f
done <<!
app/app.iml
wear/wear.iml
!
Create similar script for ignoring these files if you do it often.
如果您经常这样做,请创建类似的脚本来忽略这些文件。
回答by kraftydevil
I solved this problem when I removed and stopped committing the .idea folder to source control.
当我删除并停止将 .idea 文件夹提交到源代码管理时,我解决了这个问题。
The problem is that some of these files are machine specific configurations so sharing them could be an issue.
问题是其中一些文件是机器特定的配置,因此共享它们可能是一个问题。
Removing it and other offending files was a two step git process:
删除它和其他有问题的文件是一个两步 git 过程:
1) Add this .gitignore (from https://stackoverflow.com/a/32942758/869936):
1)添加这个.gitignore(来自https://stackoverflow.com/a/32942758/869936):
#built application files
*.apk
*.ap_
# files for the dex VM
*.dex
# Java class files
*.class
# generated files
bin/
gen/
# Local configuration file (sdk path, etc)
local.properties
# Windows thumbnail db
Thumbs.db
# OSX files
.DS_Store
# Eclipse project files
.classpath
.project
# Android Studio
*.iws
*.iml
.idea
.gradle
build/
*/build/
2) For each line of the .gitignore, run git rm line
from the command line.
2) 对于 .gitignore 的每一行,从命令行运行git rm line
。
Example:
例子:
$ git rm *.iws
$ git rm *.iml
$ git rm .idea
$ git rm .gradle
$ git rm build/
$ git rm */build/
Add and commit the changes
添加并提交更改
Now these files will be generated when you open the Android Studio project and they won't be added to git.
现在这些文件将在您打开 Android Studio 项目时生成,并且不会添加到 git 中。