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

I recently imported a jar from my AWS application, which contains all the objects that I'm going to reference in my Android application. As soon as it is in my Android Studio project and connects via Gradle, the error will appear and will not disappear until I delete my imported jar and rebuild everything.

What I read:

This error may be legal. This can happen if the Android application exceeds the 65k method names. My application may be great, but I would be amazed if all the libraries that I imported were summed up over this .... I do not exclude this, but there are a lot of methods. From what I saw, nine times out of ten, it was a configuration error. The first two articles I read say that Proguard allows you to remove all unused methods, but that did not help.

My configuration:

I have everything on my Android Studio installed to run Java 7:

  • Project Bytecode Version: 1.7
  • JDK Location: C: \ Program Files \ Java \ jdk1.7.0_45

build.gradle

apply plugin: 'com.android.application' android { compileSdkVersion 20 buildToolsVersion "21.1.2" defaultConfig { applicationId "com.example.maveric.helloworld" minSdkVersion 15 targetSdkVersion 20 versionCode 1 versionName "1.0" } buildTypes { release { minifyEnabled true proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } } } dependencies { compile fileTree(dir: 'libs', include: ['*.jar']) compile 'com.google.android.gms:play-services:4.2.42' compile 'com.android.support:appcompat-v7:20.0.0' compile 'org.apache.commons:commons-io:1.3.2' compile 'com.cedarsoftware:json-io:4.3.0' } 

I spent the last 5 hours trying to figure out every solution on SO, and not one of them had any luck.

+6
android studio
Jan 10 '16 at 7:18
source share
1 answer

After more than 6 hours of trying to solve, one Oleg tied me up in the comments, finally leading me to the real cause of the problem.

A brief explanation of the problem can be found HERE , but I will try to explain how everything looked in my system:

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

The way this error first lends itself to the user is the Messages tab, where Gradle performs each of his tasks. The task with which he falls is

 :app:transformClassesWithDexForDebug 

The problem is that the Gradle Messages message box simply says a failed task and then gives a message without a descriptive 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 

To get a better overview, you need to take a look at the Gradle Console view. The terminal text tells you the following:

 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 a bit shows that stacktrace went very well, although this initial message suggests that additional flags should be added for debugging. The top of stacktrace says the following:

 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 much. What he is trying to tell you (very badly what I have to add) is that the class he is looking at was compiled with a version of Java that is not supported. In my case, version (0034) was a hexadecimal representation of 52, which means Java 8. Android does not support Java 8, so it completes the build.

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

+17
Jan 11 '16 at 0:43
source share



All Articles