Bad class file magic or version

my JAVA_HOME variable changed to Java 1.8 and I got this error message when compiling a pure java module as a dependency of my android project.

build.gradle of the java module

apply plugin: 'java'

Solution #1: Quick an dirty

I fixed it by setting my JAVA_HOME back to 1.7:

export JAVA_HOME=`/usr/libexec/java_home -v 1.7`

Solution #2: change compiler version:

change back to 1.7 for this specific module in its build.gradle

apply plugin: 'java'
sourceCompatibility = 1.7
targetCompatibility = 1.7

Leave a Comment