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

Got it, the error was because I didn’t specify compatibility options in the module itself. That means if you have installed and using JDK 8 and your android project uses Java 1.7 (which is by default in Android SDK 23 and below) and it has a module included without any specification to use Java 1.7, then that module will be compiled with JDK 8 using Java 1.8 syntax and there will be an error because they are not compatible and compiler that uses Java 1.7 can’t parse class files which were targeting Java 1.8 and have the version 52.

build.gradle – this build file is for module level

apply plugin: 'java'

buildscript {
    tasks.withType(JavaCompile) {
        sourceCompatibility = JavaVersion.VERSION_1_7
        targetCompatibility = JavaVersion.VERSION_1_7
    }
}

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

    // Your libraries here

}

Leave a Comment