muilpp
muilpp

Reputation: 1343

bad class cafebabe or version 0034

After reading other similar questions, I still couldn't find a solution for this. I get the following stack trace which complains about a jar containing a library that I developed, compiled with Java 1.7:

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:704)
at com.android.dx.command.dexer.Main.processFileBytes(Main.java:673)
at com.android.dx.command.dexer.Main.access$300(Main.java:83)
at com.android.dx.command.dexer.Main$1.processFileBytes(Main.java:602)
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:632)
at com.android.dx.command.dexer.Main.processAllFiles(Main.java:510)
at com.android.dx.command.dexer.Main.runMonoDex(Main.java:280)
at com.android.dx.command.dexer.Main.run(Main.java:246)
at com.android.dx.command.dexer.Main.main(Main.java:215)
at com.android.dx.command.Main.main(Main.java:106)
...while parsing build/classes/main/com/utils/helpers/DateTimeAdapter.class

I have the compiler level set to java 7 both in Android Studio and Eclipse and adding sourceCompatibility and targetCompatibility in the build.gradle file did not solve this problem. The path to the JDK is also correctly set in both IDE's.

I found out that 0034 is hexadecimal for Java 8, but it's not even installed in my machine.

I also tried editing proguard.bat, suggested in this thread, with no luck.

Does anyone have any thoughts on this?

Upvotes: 2

Views: 1639

Answers (1)

muilpp
muilpp

Reputation: 1343

Even though the class was compiled with Java 7 and the command javap -verbose said so, when I opened the .class file in Android Studio, it showed Decompiled .class file, bytecode version: 52.0 (Java 8) on the top of the screen.

In the end, deleting and compiling the jar again did the trick.

Upvotes: 2

Related Questions