5

Very often, when I look at the git diff output for my Android app built with Android Studio, I see the following. Sometimes it is changing languageLevel from JDK_1_7 to JDK_1_8. Other times it is changing languageLevel from JDK_1_8 to JDK_1_7. Why so much indecision??

--- a/.idea/misc.xml
+++ b/.idea/misc.xml
@@ -24,7 +24,7 @@
       </value>
     </option>
   </component>
-  <component name="ProjectRootManager" version="2" languageLevel="JDK_1_7" default="true" project-jdk-name="1.8" project-jdk-type="JavaSDK">
+  <component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" default="true" project-jdk-name="1.8" project-jdk-type="JavaSDK">
Ted Henry
  • 1,442
  • 1
  • 14
  • 34
  • 1
    Possible duplicate of [Android .idea/misc.xml's languageLevel tag keeps changing JDKs](https://stackoverflow.com/questions/32878888/android-idea-misc-xmls-languagelevel-tag-keeps-changing-jdks) – Hong Duan Jun 26 '18 at 01:04

1 Answers1

4

1) Add this to your app build.gradle (inside the android element)

compileOptions {
    sourceCompatibility JavaVersion.VERSION_1_8
    targetCompatibility JavaVersion.VERSION_1_8
}

2) Exclude the .idea folder from Git adding this to your project level .gitignore

# Ignore idea folder
.idea/

then you need to refresh your versioned files following something like this

Versioning the .idea folder it's useful only to share some AS settings with your team, if you are working alone or if you don't have shared coding policies you can remove it.

MatPag
  • 41,742
  • 14
  • 105
  • 114
  • 4
    Adding `compileOptions` does not prevent `misc.xml` from toggling `languageLevel`. Excluding `.idea` folder only hides the issue by making version control ignores `misc.xml` and also prevent sharing AS settings with your team (as you have already mentioned). This answer neither explain *why* `misc.xml` keep toggling, nor provides a solution to prevent `misc.xml` from toggling. – Weizhi Aug 09 '19 at 12:07
  • I think it was an AS or Intellij bug at the time, now in AS 3.4 it is not happening to me (and I am using the default gitignore where misc.xml is versioned). What i mentioned was the workaround which pretty everybody used – MatPag Aug 09 '19 at 12:31