Reputation: 4193
Since moving to ADK14, I have been unable to build new apks for release on my Windows 7 system.
Building fails with "conversion to dalvik format failed with error 1", while the console is filled with lots of "Dx bad class file magic (cafebabe) or version (0033.0000)".
The full exception text:
com.android.ide.eclipse.adt.internal.build.DexException: Conversion to Dalvik format failed with error 1
at com.android.ide.eclipse.adt.internal.build.BuildHelper.executeDx(BuildHelper.java:740)
at com.android.ide.eclipse.adt.internal.project.ExportHelper.exportReleaseApk(ExportHelper.java:204)
at com.android.ide.eclipse.adt.internal.wizards.export.ExportWizard.doExport(ExportWizard.java:290)
at com.android.ide.eclipse.adt.internal.wizards.export.ExportWizard.access$0(ExportWizard.java:229)
at com.android.ide.eclipse.adt.internal.wizards.export.ExportWizard$1.run(ExportWizard.java:214)
at org.eclipse.jface.operation.ModalContext$ModalContextThread.run(ModalContext.java:121)
I am building an old project that uses lots of libraries, so presumably the problem is related to this fact. Already done all the "Fix Properties"/Clean etc that are suggested when moving to ADK14 (as I naturally had all those problems), but they haven't helped with this.
All the libraries are on the same Android SDK and JDK/JRE version, so this wouldn't seem to be the issue.And in fact, the app is easily built in debug and installed on my old version 1.5 HTC Magic - it is only when I need to export a signed application package that this breaks down.
[Edit] This is on a Windows 7x64 PC. I observe that packing the apk on my Linux laptop (Lucid Lynx) for the exact same code has absolutely no problems whatsoever.
Any ideas? Getting very frustrated with this.
NOTE
Apparently, this error message can be triggered by a variety of different problems. My particular problem was not related to Java 6/7, as I never installed Java 7 in the first place, and compiler compliance was set to Java 6 (I checked at the time, as I had seen that solution suggested elsewhere).
Upvotes: 54
Views: 37376
Reputation: 542
In my case, the problem is not about JDK nor compiler compliance level 1.6 It was about my SDK build-tools that was "18.1.1". I update build-tools to "21.1.2" and the errors gone.
Upvotes: 0
Reputation: 13073
Dx bad class file magic (cafebabe) or version (0033.0000)
This is a check from the build tools about
So this particular message says
Reading this class file (it has 'cafebabe' magic), I got confused by version of JVM 1.7
The java language and build tools are maintained by Oracle, and the dex/dalvik/Android Runtime (ART) tools are maintained by google/android. So when oracle generates a new java, there is a period of time when the java generated by the latest sdk, is incompatible with the java supported by the build tools.
wikipedia : Java class file has a table showing the versions of java and their version number
+------------+-----------+
|Java SE 1.9 | 0035.0000 |
|Java SE 1.8 | 0034.0000 |
|Java SE 1.7 | 0033.0000 |
|Java SE 1.6 | 0032.0000 |
+------------+-----------+
So in this case, the "bad version" - is 1.7. The latest (May 2016) tool chain supports 1.6 and 1.7, but not 1.8.
There are 2 mechanisms which can be used to resolve this issue.
When compiling on java you can tell the compiler to target an earlier SDK. With Android studio at the moment (2.0), that is done by changing.
File/Project Structure
Click on each module, and set Source Compatibility
to the required java version.
In raw gradle, that means inserting into build.gradle
something like :-
android {
...
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_6
targetCompatibility JavaVersion.VERSION_1_6
}
For a java project, the build.gradle
needs
sourceCompatibility= 1.6
targetCompatibility= 1.6
The sdk for earlier java builds can be downloaded, and you can download and install the earlier SDK. This is a limited time fix. Oracle are continuously improving java, removing bugs, and the older SDKs are not being updated.
The SDK is updated by changing the SDK
from the left hand side of project structure
Upvotes: 3
Reputation: 51
I had the same problem when using build-tools 18.0.1, but everything works fine when I change to use 19.0.1. It might be better to post a comment after Whome's answer, but the reputation is low.
Upvotes: 0
Reputation: 2268
This error occurs when you use a .jar
file that is not using any feature of Java 6 or higher but was built using Java 6 or higher, according to informIT.com. Apparently, Google doesn't include JDK 7 in Android's system requirements.
So the solution, that worked for me is very simple.
Build the .jar
file using Java 5 or less.
Upvotes: 0
Reputation: 46943
For me this problem resided in too old build tools version installed (the build tools were behind the platform tools and sdk versions I was using). So what I did to fix the error:
sdk.buildtools=22.0.1
in the project.properties
files in all my projects and libraries. Now the error is gone.PS: The only drawback being that I hardcoded the version and in future updates I will not automatically use it.
Upvotes: 0
Reputation: 121
If you are using Android Studio, this can be fixed by using the above advice to target Java 1.6 in your build.gradle by adding the following lines:
apply plugin: 'java'
sourceCompatibility = 1.6
targetCompatibility = 1.6
Discovered this fix from this blog post: http://www.alonsoruibal.com/my-gradle-tips-and-tricks/
Upvotes: 12
Reputation: 931
Upon reading the source of the dex tool, the problem here is that the class file is not within a version that it can understand. The version must be between 45-50 (major version) The version you're using here is 0033.0000 (0x33 in hex), which is 51 in decimal (the version number representing Java 7). This is not speculation on my part, I found this directly in the source code.
Following is speculation, and what solved my problem: I haven't figured out what you have to do to solidly confirm what class file version you'll get upon compiling with various options, but for me the problem was that my library had been compiled with Java 7. Since Android only supports Java 5 or 6, I simply recompiled in 6, and boom, solved.
Upvotes: 25
Reputation: 37916
I've faced this error message during jar -> dex conversion. The problem was in a corrupted jar file.
Upvotes: 0
Reputation: 4193
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.
Upvotes: 27
Reputation: 10400
I was having same error message dexing did not work "Dx bad class file magic (cafebabe) or version (0033.0000)".
I had JDK1.7, Eclipse Kepler, AndroidSDK-19 (Android 4.4) installed. Finally run android-sdk-windows/SDK Manager.exe tool if there is any updates. Turns out I had level 19 sdk but Tools/Android SDK Build-tools part was 18.1.1. Installed Build-tools 19.0.3 and compilation started working fine.
Upvotes: 3
Reputation: 3382
For others searching for this error message, another possible cause is that you are including libraries that were built for java 7. For us, adjusting those builds to specifically target java 6 (and then building new jars) fixed the problem.
If building with ant, you can do this by adding the following attributes to your javac tag:
<javac
...
source="1.6" target="1.6"
...
>
If invoking javac directly, use:
javac -source 1.6 -target 1.6 ...
Upvotes: 2
Reputation: 3100
You can easily get around this error with Maven's compiler plugin while having only JDK 1.7 installed. Check out my blog post on how to do it.
Upvotes: 0
Reputation: 141
I solved this problem in Eclipse by going to Windows --> Preferences Java --> Compiler
in the right side window choose Compiler compliance level
to 1.6
, click Apply
and Ok
.
And Clean Build
all projects that should solve the problem
Upvotes: 5
Reputation: 10952
I fixed this problem by Right click Java Project->Build Path->Configure Build Path Go to Libraries Tab, Select JavaSE-1.7->press Edit then change to JavaSE-1.6 Press finish then ok.
Go to Android Project, right click Project->Build Path->Configure Build Path Go to Order and Export Tab, check box beside your java project and other libraries you included. Click ok. In your Android Project, delete "gen" and "bin". then shortly after those two folders will regenerate.(If it doesn't then make sure you have ran your eclipse as administrator.)
now try running android project on your phone. Wala it works :)
Upvotes: 5
Reputation: 131
Changing the Eclipse java version to 6 worked for me. In Eclipse, go to Windows->Preferences->Java->Compiler and set "Compiler compliance level" to 1.6.
Strange thing is that I had Eclipse 3.7.0 and it worked fine, while other computers had 3.7.1 and the jar files built there didn't work...
Upvotes: 13
Reputation: 371
Compiling with Java 6 instead of 7 worked for me, but only after I configured Eclipse to "know about" my JRE6 install path. Previously I only had the JRE7 set up in Eclipse. I could set my compiler compliance level to 1.6 or 1.5 but apparently without the corresponding JRE it didn't really have any effect. I don't really understand why that should be--what does the JRE have to do with compiling, and what does it have to do with Android code?
Upvotes: 37
Reputation: 21
i tried everything from the several other solutions. that thing that helped me was to download the most current version of ProGuard and copy it do android-sdk/tools/proguard/bin and lib.
Upvotes: 2
Reputation: 4193
For the benefit of anyone who may have the same problem:
Removing proguard allowed the export of the apk to work. Why Proguard works in Linux but not on Windows remains a mystery, however.
The issue has now been reported on the Android project here: http://code.google.com/p/android/issues/detail?id=21170&can=4&colspec=ID%20Type%20Status%20Owner%20Summary%20Stars
If you encounter the same problem, please star it.
Upvotes: 3