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

前端 未结 18 1890
攒了一身酷
攒了一身酷 2020-11-27 05:00

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

相关标签:
18条回答
  • 2020-11-27 05:43

    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 ...
    
    0 讨论(0)
  • 2020-11-27 05:43

    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.

    0 讨论(0)
  • 2020-11-27 05:45

    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.

    0 讨论(0)
  • 2020-11-27 05:48

    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.

    0 讨论(0)
  • 2020-11-27 05:50

    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:

    • I downloaded the latest version of the build tools from Android SDK manager
    • I am using ADT. Still, the latest version of the build tools was not used andthe error persisted. So I added the line sdk.buildtools=22.0.1 in the project.propertiesfiles 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.

    0 讨论(0)
  • 2020-11-27 05:54

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

    This is a check from the build tools about

    1. Is this a java class file. (Java class files have 'cafebabe' at the beginning)
    2. Is it an unsupported version. This message says 0033.0000 (Java SE 1.7) is unsupported

    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.

    How to resolve

    There are 2 mechanisms which can be used to resolve this issue.

    1. Change the compatibility
    2. Change the SDK

    Change the compatibility

    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
    

    Change the SDK

    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

    0 讨论(0)
提交回复
热议问题