[Solved] Jar Convert to Dex Error: bad class file magic (cafebabe) or version

When doing dynamic loading, one step is to convert jar into DEX, using the DX tool. Before, it was normal for the project to generate jar package on eclipse and convert it to DX. However, recently, the project was migrated to Android studio and the jar generated reported bad class file magic (cafebabe) or Version (0033.0000) error in converting DX

After a search on the Internet, the reason is that the JDK version of the jar package is different from that of the DX JDK. The solution is also given to reduce the java file version

javac -source 1.6 -target 1.6 xx.Java

But it doesn’t apply to me, because I have hundreds of java files that need to be reduced, and the JDK version on Android studio is the latest 1.8. Therefore, it is speculated that there will be a solution starting from the JDK used by DX. My DX tool was downloaded from the Internet. Before, I only knew how to use it. I didn’t know what was in it. The zip package only contained dx.bat and dex.jar. There is a sentence in dx.bat:

set jarfile=dx.jar

Moreover, the following command is to call DX. Jar. Since only JDK1.8 is installed on the computer, the Java version obtained through the environment variable must also be this. The only possibility is that DX. Jar is too old. Find the latest version of DX replacement in build tools in the SDK directory, test it, normal

And then we found the same solution on stack overflow

Similar Posts: