简体   繁体   English

将jar导入android项目时出错

[英]Error while importing jar into an android project

Below error i get while putting apache xerces.jar in build path .. 低于错误,我在将apache xerces.jar放入构建路径时得到..

I have searched before for the error .. and solutions described were for conflicting jars .. but that isnt the case here .. i am getting some ParserException due a bad utf-8 我之前搜索过错误..描述的解决方案是针对有冲突的jars ..但是这里不是这种情况..由于utf-8错误,我收到了一些ParserException

I have tried (but with no luck): 我尝试过(但没有运气):

  • cleaning the project 清理项目
  • restarting eclipse 重新开始蚀
  • updating adt, sdk 更新adt,sdk
  • removing all libs and fixing proj properties and then importing xerces to resolve conflicts 删除所有库并修复proj属性,然后导入xerces来解决冲突
  • plus i just have only 1 external lib xerces 再加上我只有1个外部lib xerces

from solutions at here 这里的解决方案

removing xerces runs the proj 删除xerces运行项目

Few months ago i had imported xerces normally via build path and it had worked. 几个月前,我通常是通过构建路径导入xerces的,并且已经奏效。 Any help appreciated! 任何帮助表示赞赏!

[2013-12-24 12:21:44 - tryout] Dx UNEXPECTED TOP-LEVEL EXCEPTION: 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.M [2013-12-24 12:21:44-试用)Dx超出预期的最高级别异常:com.android.dx.cf.iface.ParseException:错误的utf-8字节a0在 com.android.dx.cf的偏移 00000004 com.android.dx.cf.cst.ConstantPoolParser.parse0(ConstantPoolParser.java:262)的com.android.dx.cf.cst.ConstantPoolParser.parse0(.cst.ConstantPoolParser.parseUtf8(ConstantPoolParser.java:374) com.android.dx.cf.cst.ConstantPoolParser.parse(ConstantPoolParser.java:150)处的com.android.dx.cf.cst.ConstantPoolParser.parseIfNecessary(ConstantPoolParser.java:124)处的.java:294)。 com.android.dx.cf.direct.DirectClassFile.parse0(DirectClassFile.java:482)的com.android.dx.cf.direct处的android.dx.cf.cst.ConstantPoolParser.getPool(ConstantPoolParser.java:115) com.android.dx.cf.direct.DirectClassFile.parseToInterfacesIfNecessary(DirectClassFile.java:388)的com.android.dx.cf.direct.DirectClassFile.getMagic(DirectClassFile.java:的DirectClassFile.parse(DirectClassFile.java:406) 251),位于com.android.dx.command.dexer.M ain.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.a com.android.dx.command.dexer.Main.processFileBytes(Main.java:634)处的com.android.dx.command.dexer.Main.access中的ain.processClass(Main.java:634)$ 600(Main.java :78)在com.android.dx.command.dexer.Main $ 1.processFileBytes(Main.java:572)在com.android.dx.cf.direct.ClassPathOpener.processArchive(ClassPathOpener.java:284)在com.android com.android.dx.cf.direct.ClassPathOpener.process(ClassPathOpener.java:144)上com.android.dx.command.dexer.Main的.dx.cf.direct.ClassPathOpener.processOne(ClassPathOpener.java:166) com.android.dx.command.dexer.Main.processAllFiles(Main.java:498)的com.android.dx.command.dexer.Main.runMonoDex(Main.java:264的.processOne(Main.java:596) )在com.android.dx.command.dexer.Main.run(Main.java:230)在sun.reflect.NativeMethodAccessorImpl.invoke0(本机方法)在sun.reflect.NativeMethodAccessorImpl.invoke(未知源)在sun.reflect .com.android.ide.eclipse.a上的.DelegatingMethodAccessorImpl.invoke(未知源)(java.lang.reflect.Method.invoke(未知源)) dt.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.doF com.android.ide.eclipse.adt.internal.build.BuildHelper.executeDx(BuildHelper.java:786)上的dt.internal.build.DexWrapper.run(DexWrapper.java:187)在com.android.ide.eclipse处。 adt.internal.build.builders.PostCompilerBuilder.build(PostCompilerBuilder.java:597)在org.eclipse.core.internal.events.BuildManager $ 2.run(BuildManager.java:733)在org.eclipse.core.runtime.SafeRunner org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:206)在org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:328) )于org.eclipse.core.internal.events.BuildManager.build(BuildManager.java:403)于org.eclipse.core.internal.resources.Project $ 1.run(Project.java:618)于org.eclipse.core org.eclipse.core.internal.resources.Project.internalBuild(Project.java:597)上的.internal.resources.Workspace.run(Workspace.java:2345)在org.eclipse.core.internal.resources.Project.build (Project.java:124)在com.android.ide.eclipse.adt.internal.project.ProjectHelper.doF ullIncrementalDebugBuild(ProjectHelper.java:1116) at com.android.ide.eclipse.adt.internal.launch.LaunchConfigDelegate.launch(LaunchConfigDelegate.java:147) 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) ... 43 more ...while parsing cst 012c at offset 00000afe ...while p org.eclipse.debug.internal.core.LaunchConfiguration.launch(LaunchConfiguration。 org.eclipse.debug.internal.core.LaunchConfiguration.launch(LaunchConfiguration.java:707)处org.eclipse.debug.internal.ui.DebugUIPlugin.buildAndLaunch(DebugUIPlugin.java:1018)处的java:858) .debug.internal.ui.DebugUIPlugin $ 8.run(DebugUIPlugin.java:1222)at org.eclipse.core.internal.jobs.Worker.run(Worker.java:53)造成原因:java.lang.IllegalArgumentException:错误的utf -8字节a0,位于com.android.dx.rop.cst.CstString.throwBadUtf8(CstString.java:171)位于com.android.dx.rop.cst.CstString.utf8BytesToString(CstString.java:143)位于00000004处com.android.dx.cf.cst.ConstantPoolParser.parseUtf8(ConstantPoolParser.java:371)上的com.android.dx.rop.cst.CstString。(CstString.java:200)... 43 cst 012c偏移00000afe ...而p arsing cst 00a5 at offset 00000316 ...while parsing > org/apache/xerces/impl/xpath/regex/ParserForXMLSchema.class 在解析> org / apache / xerces / impl / xpath / regex / ParserForXMLSchema.class时将 cst 00a5偏移00000316 ...

> [2013-12-24 12:21:44 - tryout] Dx 1 error; > [2013-12-24 12:21:44-试用] Dx 1错误; aborting [2013-12-24 12:21:44 - tryout] Conversion to Dalvik format failed with error 1 正在中止[2013-12-24 12:21:44-试用]转换为Dalvik格式失败,错误1

In your question, you mention: 在您的问题中,您提到:

Few months ago i had imported xerces normally via build path and it had worked 几个月前,我通常通过构建路径导入了xerces,并且它已经起作用了

This raised the red flag for me, since "months" might as well be a lifetime when it comes to libraries that are constantly being updated. 这对我来说是一个危险信号,因为对于不断更新的库来说,“月”也可能是一生。 Perhaps your issue is not with the jar file compatibility with Eclipse, but rather, an issue with the jar file itself, which could explain your parser error with the "bad UTF-8 byte". 也许您的问题不是与jar文件与Eclipse的兼容性有关,而是与jar文件本身有关,这可以用“错误的UTF-8字节”解释解析器错误。

According to Apache ( http://xerces.apache.org/xerces2-j/install.html ), turns out that xerces.jar is now deprecated: 根据Apache( http://xerces.apache.org/xerces2-j/install.html )的说法,现在不建议使用xerces.jar

xerces.jar is no longer available in the main distribution. xerces.jar在主发行版中不再可用。 You can still download this jar from deprecated distribution. 您仍然可以从不建议使用的发行版中下载此jar。 xerces.jar is a Jar file that contains all the parser class files (ie, it contains the intersection of the contents of xercesImpl.jar and xml-apis.jar). xerces.jar是一个Jar文件,其中包含所有解析器类文件(即,它包含xercesImpl.jar和xml-apis.jar的内容的交集)。

So, on the same page as listed above, I found that you just have to replace xerces.jar with two new files: xercesImpl.jar and xml-apis.jar . 因此,在上面列出的同一页面上,我发现您只需要用两个新文件替换xerces.jar: xercesImpl.jarxml-apis.jar See excerpt below (from same link as above): 请参见下面的摘录(来自与上面相同的链接):

Changes in Xerces jar files : Xerces jar文件中的更改

In order to accommodate the very common case in which Xerces is used with an XSLT processor such as Xalan, between Xerces 2.0.0 beta 3 and beta 4 a change in the default organization of Xerces' jar files was introduced. 为了适应Xerces在Xerces 2.0.0 beta 3和beta 4之间与Xalans等XSLT处理器一起使用的非常常见的情况,引入了Xerces jar文件默认组织的更改。 As well as the xercesSamples.jar file, which we still produce, Xerces formerly came with a file called xerces.jar. 除了我们仍然产生的xercesSamples.jar文件之外,Xerces以前还带有一个名为xerces.jar的文件。 This file contained all of the parser's functionality. 该文件包含解析器的所有功能。 Two files are now included: xercesImpl.jar, our implementation of various APIs, and xml-apis.jar, the APIs themselves . 现在包括两个文件:xercesImpl.jar(我们对各种API的实现)和xml-apis.jar(API本身) This was done so that, if your XSLT processor ships with APIs at the same level as those supported by Xerces-J, you can avoid putting xml-apis.jar on your classpath. 这样做是为了,如果XSLT处理器附带的API与Xerces-J支持的API处于同一级别,则可以避免将xml-apis.jar放在类路径中。

If you still want/need to use xerces.jar, Apache has provided a way for backwards compatibility : 如果仍然希望/需要使用xerces.jar,那么Apache提供了一种向后兼容的方法

Should you wish to use the xerces.jar instead, we have included several Ant targets for backward compatibility. 如果您希望改用xerces.jar,则我们包括了几个Ant目标,以实现向后兼容。 An "Ant target" is an argument given to Ant, our build tool, that tells it which portions of the build.xml file to apply. “ Ant目标”是提供给我们的构建工具Ant的参数,它告诉它要应用build.xml文件的哪些部分。

If you are on a Windows system and you wish to get only the xerces.jar file, you would execute build.bat deprecatedjars. 如果您使用的是Windows系统,并且只希望获取xerces.jar文件,则可以执行build.bat deprecatedjars。

The link above continues to list more potential problems you could encounter with version issues. 上面的链接继续列出了您在版本问题上可能遇到的更多潜在问题。 Let me know if this solves your issue; 让我知道这是否解决了您的问题; if not, I'll continue to look for potential solutions. 如果没有,我将继续寻找潜在的解决方案。

This seems to be an issue with the latest ADT. 最新的ADT似乎是一个问题。 I have been experiencing the same problem since I updated to ADT 22.6.3, and fixed it removing the xerces JAR file from the build path, and using instead the source code from xerces-for-android: https://code.google.com/p/xerces-for-android/source/checkout 自更新至ADT 22.6.3以来,我一直遇到相同的问题,并修复了该问题,从构建路径中删除了xerces JAR文件,并改用了来自xerces-for-android的源代码: https : //code.google。 com / p / xerces-for-android / source / checkout

You just need to download the source code using SVN, then copy the source code into your project source folder, and update a few imports. 您只需要使用SVN下载源代码,然后将源代码复制到您的项目源文件夹中,并更新一些导入。 It worked for me. 它为我工作。

Hope it helps. 希望能帮助到你。

I suggest you delete all install new eclipse and download newest version adt . 我建议您删除所有安装的新Eclipse并下载最新版本的adt。 the best practice is using Android Studio And Build Your Project Using Gradle.And Import your Dependencies using Gradle ,it brings you large variety of feature. 最佳实践是使用Android Studio并使用Gradle构建项目。并使用Gradle导入依赖项,它将为您带来多种功能。 You Can find Document on Vogella tutorial 您可以在Vogella上找到文档教程

and Official Android Tutorial 官方Android教程

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM