Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error while importing jar into an android project

Below error i get while putting apache xerces.jar in build path ..

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

I have tried (but with no luck):

  • cleaning the project
  • restarting eclipse
  • updating adt, sdk
  • removing all libs and fixing proj properties and then importing xerces to resolve conflicts
  • plus i just have only 1 external lib xerces

from solutions at here

removing xerces runs the proj

Few months ago i had imported xerces normally via build path and it had worked. 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.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: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: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 parsing cst 00a5 at offset 00000316 ...while parsing > org/apache/xerces/impl/xpath/regex/ParserForXMLSchema.class

> [2013-12-24 12:21:44 - tryout] Dx 1 error; aborting [2013-12-24 12:21:44 - tryout] Conversion to Dalvik format failed with error 1

like image 757
riteshtch Avatar asked Dec 24 '13 07:12

riteshtch


2 Answers

In your question, you mention:

Few months ago i had imported xerces normally via build path and it had worked

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".

According to Apache (http://xerces.apache.org/xerces2-j/install.html), turns out that xerces.jar is now deprecated:

xerces.jar is no longer available in the main distribution. You can still download this jar from deprecated distribution. xerces.jar is a Jar file that contains all the parser class files (i.e., it contains the intersection of the contents of xercesImpl.jar and 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. See excerpt below (from same link as above):

Changes in Xerces jar files:

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. As well as the xercesSamples.jar file, which we still produce, Xerces formerly came with a file called 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. 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.

If you still want/need to use xerces.jar, Apache has provided a way for backwards compatibility:

Should you wish to use the xerces.jar instead, we have included several Ant targets for backward compatibility. An "Ant target" is an argument given to Ant, our build tool, that tells it which portions of the build.xml file to apply.

If you are on a Windows system and you wish to get only the xerces.jar file, you would execute 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.

like image 164
bunting Avatar answered Oct 14 '22 11:10

bunting


This seems to be an issue with the latest 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

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. It worked for me.

Hope it helps.

like image 20
Ernesto Avatar answered Oct 14 '22 10:10

Ernesto