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