Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android .idea/misc.xml's languageLevel tag keeps changing JDKs

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
    }
}

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.


Came here from Google after updating to Android Studio 2.2. This might be helpful to others.

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.

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.

enter image description here


It seems the file should be stored under version control. I would propose to keep it in git, but ignore all local changes:

git update-index --assume-unchanged .idea/misc.xml

When switching branches there might be conflict in these files. Then you could use following imlreset script to reset the files:

#!/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.


I solved this problem when I removed and stopped committing the .idea folder to source control.

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:

1) Add this .gitignore (from 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.

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.