eclipse android 开发2个奇怪错误

Life is short , play more!
本文来自lihao's Blog,转载请注明。

发现错误的ide工具版本: (顺便说一句, 最新版本的东西也不是什么都是好)
Android Developer Tools
Build: v22.6.2-1085508

错误一:

1. dx编译的时候, utf-8读取class文件发生错误

1. 更换更新版本的jar库版本后,有时可以解决该问题。 例如将xalan-2.7.1 升级到 xalan-2.7.2 。 (经过我亲自试验, xalan的错误通过升级后,可以解决)

2. google很久,也很多人认为是adt 版本的bug。 不import 库,又不行, 真是恼火的很。
也有部分网友指出需要下载对应的for android的xerces的源代码。 这样就可以解决。
其他的办法,可以尝试升级对应jar库的版本,到比较新的版本。 (xerces的问题, 网友指出需要下载for android的代码哦)

com.android.dx.cf.iface.ParseException: bad utf-8 byte a0 at offset 00000004
at com.android.dx.cf.cst.ConstantPoolParser.parseUtf8(ConstantPoolParser.java:374)
at com.android.dx.cf.cst.ConstantPoolParser.parse0(ConstantPoolParser.java:262)
at com.android.dx.cf.cst.ConstantPoolParser.parse0(ConstantPoolParser.java:294)
at com.android.dx.cf.cst.ConstantPoolParser.parse(ConstantPoolParser.java:150)
at com.android.dx.cf.cst.ConstantPoolParser.parseIfNecessary(ConstantPoolParser.java:124)
at com.android.dx.cf.cst.ConstantPoolParser.getPool(ConstantPoolParser.java:115)
at com.android.dx.cf.direct.DirectClassFile.parse0(DirectClassFile.java:482)
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.GeneratedMethodAccessor31.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:483)
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:328)
at org.eclipse.core.internal.events.BuildManager.build(BuildManager.java:403)
at org.eclipse.core.internal.resources.Project$1.run(Project.java:618)
at org.eclipse.core.internal.resources.Workspace.run(Workspace.java:2345)
at org.eclipse.core.internal.resources.Project.internalBuild(Project.java:597)
at org.eclipse.core.internal.resources.Project.build(Project.java:124)
at com.android.ide.eclipse.adt.internal.project.ProjectHelper.doFullIncrementalDebugBuild(ProjectHelper.java:1143)
at com.android.ide.eclipse.adt.internal.launch.LaunchConfigDelegate.launch(LaunchConfigDelegate.java:155)
at org.eclipse.debug.internal.core.LaunchConfiguration.launch(LaunchConfiguration.java:858)
at org.eclipse.debug.internal.core.LaunchConfiguration.launch(LaunchConfiguration.java:707)
at org.eclipse.debug.internal.ui.DebugUIPlugin.buildAndLaunch(DebugUIPlugin.java:1018)
at org.eclipse.debug.internal.ui.DebugUIPlugin$8.run(DebugUIPlugin.java:1222)
at org.eclipse.core.internal.jobs.Worker.run(Worker.java:53)
Caused by: java.lang.IllegalArgumentException: bad utf-8 byte a0 at offset 00000004
at com.android.dx.rop.cst.CstString.throwBadUtf8(CstString.java:171)
at com.android.dx.rop.cst.CstString.utf8BytesToString(CstString.java:143)
at com.android.dx.rop.cst.CstString.(CstString.java:200)
at com.android.dx.cf.cst.ConstantPoolParser.parseUtf8(ConstantPoolParser.java:371)
... 42 more
...while parsing cst 012c at offset 00000afe
...while parsing cst 00a5 at offset 00000316
...while parsing org/apache/xerces/impl/xpath/regex/ParserForXMLSchema.class

[2014-09-24 23:56:00 - zizhufang] Dx 1 error; aborting
[2014-09-24 23:56:00 - zizhufang] Conversion to Dalvik format failed with error 1

 

错误二

引入的库和android.jar 里有class冲突。。因为不允许替换android核心库的内容,所以报错。

擦, 啥也不说了, 说是import 引入的库, 和android的核心库有冲突,package和class相同引起的。
无语中。 Dx
trouble processing “javax/xml/XMLConstants.class”:

Ill-advised or mistaken usage of a core class (java.* or javax.*)
when not building a core library.

解决办法: 

因为笔者使用 android 4.4.2 的sdk,所以编辑$ANDROID_HOME/build-tools/android-4.4.2/dx

将 exec java $javaOpts -jar “$jarpath” “[email protected]” 改为 exec java $javaOpts -jar “$jarpath” “[email protected]

(若还报错, 只能repack要引入的库代码拉。)

更多资料,同学门可以看。

http://stackoverflow.com/questions/9816768/trouble-processing-javax-xml-xmlconstants-class
http://stackoverflow.com/questions/17165498/trouble-processing-javax-xml-xmlconstants-class-in-android
http://stackoverflow.com/questions/20756461/error-while-importing-jar-into-an-android-project
http://stackoverflow.com/questions/839435/android-core-library-error


发表评论

电子邮件地址不会被公开。 必填项已用*标注