Bad Class File Magic or Version

Bad class file magic or version

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.)

Sample Image

and it seems to compile fine.

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

Unable to fix ParseException: bad class file magic (cafebabe) or version (0034.0000)

After over 6 hours of trying solutions, the one Oleg linked me in the comments finally led me to the real cause of the problem.

The brief explanation of the issue can be found HERE, but I will try to explain how everything looked on my system:

This error first showed up for me when I imported a jar file that was part of my main Java project, which was hosted in Eclipse.

The way this error first pokes up to the user is through the Messages tab where Gradle walks through each of its tasks. The task that it crashes on is

:app:transformClassesWithDexForDebug

The problem is the Gradle Messages window just says the task failed and then gives a non-descriptive error message saying

Error:Execution failed for task ':app:transformClassesWithDexForDebug'.
> com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command 'C:\Program Files\Java\jdk1.7.0_45\bin\java.exe'' finished with non-zero exit value 1

In order to get a better view, you need to go look at the Gradle Console view. The text in the terminal view tells you this:

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:transformClassesWithDexForDebug'.
> com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command 'C:\Program Files\Java\jdk1.7.0_45\bin\java.exe'' finished with non-zero exit value 1

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

Scrolling up a little bit shows that the stacktrace came through just fine, even though this initial message hints that there should be additional flags added for debugging. The top of the stacktrace says this:

UNEXPECTED TOP-LEVEL EXCEPTION:
com.android.dx.cf.iface.ParseException: bad class file magic (cafebabe) or version (0034.0000)

But even that doesn't help very much. What it is trying to tell you (very poorly I have to add) is that the class it is looking at was compiled with a Java version that is not supported. In my case, version (0034) was the hex representation of 52 which means Java 8. Android doesn't support Java 8, so it terminates the build.

The solution was to go back to my Eclipse project and export the jar file with the compiler set to version 1.7 and now everything is up and running again. I hope this helps!

Dx bad class file magic (cafebabe) or version (0033.0000) with ADK14

I found the solution to this problem at last.

If you look in Proguard.bat (Android SDK\tools\proguard\bin), you will find the following line:

call %java_exe% -jar "%PROGUARD_HOME%"\lib\proguard.jar %*

Replace it with the following:

call %java_exe% -jar "%PROGUARD_HOME%"\lib\proguard.jar %1 %2 %3 %4 %5 %6 %7 %8 %9

It's a stupid old issue, that I actually realize that I have seen before, now that I have figured it out. Apparently the Android SDK team still haven't fixed this problem, and it was reintroduced when I did a clean install of the Android SDK.

bad class cafebabe or version 0034

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.

Unexpected top level exception: bad class file magic, in Android

Check the version of Java you are using to compile your classes.

You need to be using Java 6 or 7 for Android development. Java 7 support was added more recently and its functionality is limited, so use 6 for maximum compatibility.

Bad class file magic when using dx.bat

Your classes need to be compiled with jdk 5 or 6. You are probably using 7. If that doesn't work, you might also need to make sure that every single class is compiled right, even if in different projects. Solved my problem here.



Related Topics



Leave a reply



Submit