I already know that question has been already asked very often and answers, but no one of the answers i found fixed my problem.

It's the error:

Error:Gradle: Execution failed for task ':ffcommunity:preDexDebug'.
 com.android.ide.common.internal.LoggedErrorException: Failed to run command:
    D:\Android SDK\sdk\build-tools\20.0.0\dx.bat --dex --output D:\Users\ReVo\Documents\IntelliJ IDEA\FFCommunity\ffcommunity\build\intermediates\pre-dexed\debug\bananaquery-2ee85432877a057e7414910b8127805535139d5d.jar D:\Users\ReVo\Documents\IntelliJ IDEA\FFCommunity\ffcommunity\libs\bananaquery.jar
Error Code:
    1
Output:
    UNEXPECTED TOP-LEVEL EXCEPTION:
    com.android.dx.cf.iface.ParseException: bad class file magic (cafebabe) or version (0034.0000)
        at com.android.dx.cf.direct.DirectClassFile.parse0(DirectClassFile.java:472)
        at com.android.dx.cf.direct.DirectClassFile.parse(DirectClassFile.java:406)
        at com.android.dx.cf.direct.DirectClassFile.parseToInterfacesIfNecessary(DirectClassFile.java:388)
        at com.android.dx.cf.direct.DirectClassFile.getMagic(DirectClassFile.java:251)
        at com.android.dx.command.dexer.Main.processClass(Main.java:665)
        at com.android.dx.command.dexer.Main.processFileBytes(Main.java:634)
        at com.android.dx.command.dexer.Main.access$600(Main.java:78)
        at com.android.dx.command.dexer.Main$1.processFileBytes(Main.java:572)
        at com.android.dx.cf.direct.ClassPathOpener.processArchive(ClassPathOpener.java:284)
        at com.android.dx.cf.direct.ClassPathOpener.processOne(ClassPathOpener.java:166)
        at com.android.dx.cf.direct.ClassPathOpener.process(ClassPathOpener.java:144)
        at com.android.dx.command.dexer.Main.processOne(Main.java:596)
        at com.android.dx.command.dexer.Main.processAllFiles(Main.java:498)
        at com.android.dx.command.dexer.Main.runMonoDex(Main.java:264)
        at com.android.dx.command.dexer.Main.run(Main.java:230)
        at com.android.dx.command.dexer.Main.main(Main.java:199)
        at com.android.dx.command.Main.main(Main.java:103)
    ...while parsing com/comuf/revonline/bananaquery/BananaInsert.class
    1 error; aborting

The error is bad class file magic (cafebabe) or version (0034.0000).

I builded and execute the application without problems many times in the same day but now this fails everytime with this message.


Project SDK is Android API 19 Platform and project level is 1.7.

CompileSDK is 19 and buildToolsVersion is '20.0.0'.

Compile options:

compileOptions {
    sourceCompatibility JavaVersion.VERSION_1_7
    targetCompatibility JavaVersion.VERSION_1_7
}

and in dependencies i have:

compile files('libs/bananaquery.jar')

The library is build with SDK Android API 19 Platform with project level 1.7.

My .jar file is inside libs/ folder.

I use IntelliJ IDEA 14 Preview, it could be the reason? With IntellIJ IDEA 13 it remains stuck at "Gradle sync"

compile files could be useless since i have compile fileTree(dir: 'libs', include: ['*.jar']) too


Solution 1:

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

Solution 2:

Ok, my bad.

In the Project SDK section, when you add an Android SDK you should provide the Java SDK and all my Android SDKs uses Java 8 as SDK so it create the class files with the wrong version even if the Project level is 1.7 (i don't know why, i supposed that everything was choosed by Project level).

Now i changed the SDK (the java version "1.x.0" part.)

enter image description here

and it seems to compile fine.

The reason that worked before today was because my SDK was 1.8 and not Android API x