Why does Android Studio keep toggling `languageLevel`?
Asked Answered
A

1

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">
Antineutrino answered 25/6, 2018 at 21:22 Comment(1)
Possible duplicate of Android .idea/misc.xml's languageLevel tag keeps changing JDKsChristadelphian
T
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.

Thermel answered 25/6, 2018 at 21:30 Comment(2)
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.Anthropology
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 usedThermel

© 2022 - 2024 — McMap. All rights reserved.