20

When I am including the jaxp.jar, I get the following error-

trouble processing "javax/xml/XMLConstants.class":
[2009-05-08 16:53:18 - TestProject] 
Attempt to include a core VM class in something other than a core library.
It is likely that you have attempted to include the core library from a desktop
virtual machine into an application, which will most assuredly not work. If
you really intend to build a core library -- which is only appropriate as
part of creating a full virtual machine binary, as opposed to compiling an
application -- then use the "--core-library" option to suppress this error
message. If you go ahead and use "--core-library" but are in fact building
an application, then please be aware that your build will still fail at some
point; you will simply be denied the pleasure of reading this helpful error
message.
[2009-05-08 16:53:18 - TestProject] 1 error; aborting
[2009-05-08 16:53:18 - TestProject] Conversion to Dalvik format failed with error 1

Has anyone faced this problem? Any help will be really appreciated I have gone with some solutions but they are not specific.

SAurabh
  • 87
  • 17

5 Answers5

16

the error you get from Dx is based only on the java package names of the libs you are importing and nothing else.

the message can by summarized as: if you import a library in the java.* or javax.* namespace, it's very likely that it depends on other "core" libraries that are only provided as part of the JDK, and therefore won't be available in the Android platform. it's essentially preventing you from doing something stupid, which is accurate 99% of the time when you see that message.

now, of course, just because a java package starts with java.* or javax.* does not necessarily mean that it depends on the JDK proper. it may work perfectly fine in android. to get around the stupidity check, add the --core-library option to dx. change the last line of $ANDROID_HOME/platform-tools/dx from,

exec java $javaOpts -jar "$jarpath" "$@"

to,

exec java $javaOpts -jar "$jarpath" --core-library "$@"

in my case, i was including a library that depended on Jackson, which depends on JAXB. for me, overriding the stupidity check was acceptable because the library's use of Jackson was only for JSON and not for XML serialization (i only include the JAXB API library, not the impl). of course i wish there was a cleaner way to go about this, but re-writing the top level library to avoid using Jackson was not an option.

Jeffrey Blattman
  • 22,176
  • 9
  • 79
  • 134
  • In my case , there is no dx file in $ANDROID_HOME/platform-tools/ , inspite I found it in $ANDROID_HOME/build-tools/21.1.2/. there I changed it as you suggested , but getting same error. Any help ? – MohK Feb 17 '15 at 08:46
  • which build tools is your build poinitng to? – Jeffrey Blattman Feb 17 '15 at 17:01
  • I am using buld tools v21.1.2 as the folder path showing in above comment. – MohK Feb 18 '15 at 11:45
  • try putting an echo in the dx you modified to ensure that's the one that's being executed when you build. – Jeffrey Blattman Feb 18 '15 at 21:22
  • 1
    thnx for the suggestion. I put echo in all build tools available in my sdk dx files like `echo "Mohammad started 21.1.2\n" >> ~/Desktop/buildDX` , but surprisingly no `buildDX` file generated on Desktop and the error still remains. Can't figure out what is happening. :( – MohK Feb 19 '15 at 06:00
  • And for information I am using `xmlParserAPIs-2.6.2.jar` without maven. – MohK Feb 19 '15 at 06:21
  • well, you modified the wrong file. it has to be that your build isn't using that version of the build tools, or it's pointed to a different SDK all together. – Jeffrey Blattman Feb 19 '15 at 16:47
  • I have only one build tool version , have a look at Images inside question http://stackoverflow.com/q/28622254/1602333 – MohK Feb 20 '15 at 05:34
  • Hello, surprisingly your solution doesn't work with eclipse but does work with android studio with gradle. Thank you for the help. – MohK Mar 04 '15 at 07:26
4

I see two possibilities:

In your project's folder, the file .classpath could be wrong. Try to replace it with:

<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="src" path="gen"/>
<classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/>
<classpathentry kind="output" path="bin"/>
</classpath>

If it does not work, it means the library you are trying to include is not compatible with Android.

Nicolas Raoul
  • 58,567
  • 58
  • 222
  • 373
3

If you are including a core class then this error is self explanatory. If you aren't (search your code, just to make sure) then I have seen this error from time to time only when using Eclipse when the Android "library" gets added to the Eclipse build path multiple times on accident.

I don't know how it gets in that state, but it has happened to me twice now. To resolve it, you need to fix the .classpath file as Nicolas noted. Another way to do that is to edit the "Java Build Path" (right click on the project and select properties) and remove your Android* libraries (if there are more than one remove them all).

This will cause the project to fail to compile and have many errors, but, once you are sure you have gotten rid of all the libraries you can then right click the project again and select "Android Tools"->"Fix Project Properties" and the correct (single copy) of Android.jar will be added back and things should work fine again from there.

Charlie Collins
  • 8,806
  • 4
  • 32
  • 41
  • 1
    By the way, I had the same problem in IntelliJ IDEA loading a project. To resolve it I removed all the facets, rebuilt the project and then added the Android facet back to the Android target module. – jwadsack Mar 30 '11 at 22:55
  • Thank you for the solution. I have been reading all the solutions, none seems to be working for me. Removing android.jar file from build path and using "Android Tools -> Fix project properties" solved the problem. – amadamala Jun 22 '11 at 19:07
  • According to my interpretation, all the solutions finally come to the changes in .classpath file. Android Tools -> Fix Project Properties & edit libraries in build path – WaiKit Kung Mar 10 '13 at 09:15
1

I got this after copy-pasting an Android project into the same workspace. Deleting it from disk afterwards wasn't enough, cause Eclipse still hade some reference to it hidden away. I also had to remove the following folder under the workspace folder:

.metadata\.plugins\org.eclipse.core.resources.projects[NameOfTheDuplicateProject]

Nilzor
  • 18,082
  • 22
  • 100
  • 167
-1

I'm not including a core class or building a core library or any of that.

yes, you are:

trouble processing "javax/xml/XMLConstants.class"

java.* and javax.* both count. you can use the --core-library switch if you just want to ignore this in a test app, but heed the warning: "your application will still fail to build or run, at some point. Please be prepared for angry customers who find, for example, that your application ceases to function once they upgrade their operating system. You will be to blame for this problem."

the right fix, as it says, for a shipping app, is to repackage those classes (i.e. move them to a new directory, edit their "package" lines correspondingly, and update the "import" lines in their callers).

Elliott Hughes
  • 4,595
  • 2
  • 23
  • 21
  • 2
    I've had this issue too, and just quoting the offending file from the unhelpful error message is very unhelpful. This is actually a problem that occurs without trying to build the core libraries. Check Nicolas Raoul and Charlie Collins' answers to see what helpful looks like. – Cobus Kruger Nov 21 '10 at 22:38