Sébastien Sébastien - 4 months ago 520x
Android Question

Got "unsupported class file version 52.0" after including a module to a project

After creating an empty project within Android Studio and including a pure java module, which compiles and works perfectly on its own, I get the following error on every single class within that module:

Error:PARSE ERROR: Error:unsupported class file version 52.0

I tried to run the project using the embedded JDK and the one that I have on my system - JDK 8 (1.8.0_91), the result is the same.

Note this, that I don't include the module as
library, it is source code which is importing with following instruction:

include ':app', ':my-module'
project(':my-module').projectDir = new File(settingsDir, '../my-module-java')


Got it, the error was because I didn't specify compatibility options in the module itself. That's mean if your project is bound to JDK 7, but you have installed and using JDK 8, then all modules that were used in a project have to be compatible with JDK 7 and explicitly specified to use it, and if you are using Android SDK 23 and below that is the case. Otherwise, there will be an error because JDK 7 can't parse class files which were compiled by JDK 8 and have the version 52.

apply plugin: 'java'

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')

    sourceCompatibility = 1.7
    targetCompatibility = 1.7