android编译时报com.android.dx.cf.iface.ParseException异常

在android项目中引入其他jar包时,如果遇到类似于以下异常:

?

UNEXPECTED TOP-LEVEL EXCEPTION:
com.android.dx.cf.iface.ParseException: bad class file magic (cafebabe) or version (0034.0000)
	at com.android.dx.cf.direct.DirectClassFile.parse0(DirectClassFile.java:472)
	at com.android.dx.cf.direct.DirectClassFile.parse(DirectClassFile.java:406)
	at com.android.dx.cf.direct.DirectClassFile.parseToInterfacesIfNecessary(DirectClassFile.java:388)
	at com.android.dx.cf.direct.DirectClassFile.getMagic(DirectClassFile.java:251)
	at com.android.dx.command.dexer.Main.processClass(Main.java:665)
	at com.android.dx.command.dexer.Main.processFileBytes(Main.java:634)
	at com.android.dx.command.dexer.Main.access$600(Main.java:78)
	at com.android.dx.command.dexer.Main$1.processFileBytes(Main.java:572)
	at com.android.dx.cf.direct.ClassPathOpener.processArchive(ClassPathOpener.java:284)
	at com.android.dx.cf.direct.ClassPathOpener.processOne(ClassPathOpener.java:166)
	at com.android.dx.cf.direct.ClassPathOpener.process(ClassPathOpener.java:144)
	at com.android.dx.command.dexer.Main.processOne(Main.java:596)
	at com.android.dx.command.dexer.Main.processAllFiles(Main.java:498)
	at com.android.dx.command.dexer.Main.runMonoDex(Main.java:264)
	at com.android.dx.command.dexer.Main.run(Main.java:230)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
	at java.lang.reflect.Method.invoke(Unknown Source)
	at com.android.ide.eclipse.adt.internal.build.DexWrapper.run(DexWrapper.java:187)
	at com.android.ide.eclipse.adt.internal.build.BuildHelper.executeDx(BuildHelper.java:786)
	at com.android.ide.eclipse.adt.internal.build.builders.PostCompilerBuilder.build(PostCompilerBuilder.java:597)
	at org.eclipse.core.internal.events.BuildManager$2.run(BuildManager.java:733)
	at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42)
	at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:206)
	at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:246)
	at org.eclipse.core.internal.events.BuildManager$1.run(BuildManager.java:299)
	at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42)
	at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:302)
	at org.eclipse.core.internal.events.BuildManager.basicBuildLoop(BuildManager.java:358)
	at org.eclipse.core.internal.events.BuildManager.build(BuildManager.java:381)
	at org.eclipse.core.internal.resources.Workspace.buildInternal(Workspace.java:514)
	at org.eclipse.core.internal.resources.Workspace.build(Workspace.java:423)
	at org.eclipse.jdt.internal.ui.util.CoreUtility$BuildJob.run(CoreUtility.java:162)
	at org.eclipse.core.internal.jobs.Worker.run(Worker.java:53)

?

这其实是jdk版本兼容性问题。你引入的jar包编译环境(比如是1.8)要高于你android中默认的jdk编译版本(比如1.6)。要解决这个问题,就必须保证你android项目的编译jdk版本要高于等于你引入jar包的编译jdk版本,然后重新编译就好了。有两种解决方案:

?

1、低于等于你android的jdk版本来重新编译你要引入的jar包(不推荐)

如果引入的jar是开源框架,你要去修改jar的编译版本比较麻烦,所以不推荐

2、修改android项目的jdk版本。

可以修改android项目的jdk版本,具体修改方式如下:

Windows-->Preferences-->Java-->Compiler,然后修改默认的编译版本:


技术文章
?

文章来自:http://quenice.iteye.com/blog/2246521
© 2021 jiaocheng.bubufx.com  联系我们
ICP备案:鲁ICP备09046678号-3