3

I'm trying to compile a simple Android app composed by the app and a module with multiple dependencies (lambdj, org.json, gson, okhttp ).

But I have this error on compiling and I cannot figure out how to solve it (and where is the problem)

:app:preDexDebug
UNEXPECTED TOP-LEVEL EXCEPTION:
java.lang.RuntimeException: Exception parsing classes
    at com.android.dx.command.dexer.Main.processClass(Main.java:752)
    at com.android.dx.command.dexer.Main.processFileBytes(Main.java:718)
    at com.android.dx.command.dexer.Main.access$1200(Main.java:85)
    at com.android.dx.command.dexer.Main$FileBytesConsumer.processFileBytes(Main.java:1645)
    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:672)
    at com.android.dx.command.dexer.Main.processAllFiles(Main.java:574)
    at com.android.dx.command.dexer.Main.runMonoDex(Main.java:311)
    at com.android.dx.command.dexer.Main.run(Main.java:277)
    at com.android.dx.command.dexer.Main.main(Main.java:245)
    at com.android.dx.command.Main.main(Main.java:106)
Caused by: 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.parseClass(Main.java:764)
    at com.android.dx.command.dexer.Main.access$1500(Main.java:85)
    at com.android.dx.command.dexer.Main$ClassParserTask.call(Main.java:1684)
    at com.android.dx.command.dexer.Main.processClass(Main.java:749)
    ... 12 more
1 error; aborting
Error:Execution failed for task ':app:preDexDebug'.
> com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command 'C:\Program Files\Java\jdk1.8.0_31\bin\java.exe'' finished with non-zero exit value 1
Information:BUILD FAILED
appersiano
  • 2,670
  • 22
  • 42

2 Answers2

0

The stacktrace wasn't very clear for me...after some searches I found this thread (Using lambdaj in android).

The only one answer posted suggested to check the hamcrest library ( a dependency of lambdaj , version 1.1), so I decide to add to my gradle build configuration the latest hemcrest lib available (1.3 version).

compile 'org.hamcrest:hamcrest-all:1.3'

And the project build successfully!

Hope it helps!


UPDATE:

I had some problem with lambdaj on my project, this library is not totally compatible. I moved to retrolambda, check it out!

Community
  • 1
  • 1
appersiano
  • 2,670
  • 22
  • 42
  • 2
    I also recently got this error (using Retrolambda on Android). It turned out that the JDK on our Jenkins server that builds a dependency in our project, was upgraded from 1.7 to 1.8. – Mitch Wong Ho Oct 28 '15 at 02:17
0

This is usually caused by using Java 8 libraries on non-Java 8 Projects or vice-versa.

For me the fix was to just use retrolambda on my project and the libraries I used:

in your main build.gradle file:

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:1.5.0'

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
        classpath 'me.tatarka:gradle-retrolambda:3.2.4'
    }
}

then on top of your app/library build.gradle file:

apply plugin: 'me.tatarka.retrolambda'

Also make sure to set it up for Java 8:

android {

    ...

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
}

retrolambda plugin act at compile time and apply Java8 lambda support to your code, see https://github.com/evant/gradle-retrolambda for more informations on what it does.

Daniele Segato
  • 12,314
  • 6
  • 62
  • 88