问题
I'm developing an Android app and for one component I can test outside of Android as it does not use any Android code.
It uses xstream and I have the following libraries include: xstream1.4.6 xpp3-min-1.1.4c xmlpull-1.1.3.1
When I unit test my code outside of Android everything works just fine.
When I try and use it with Android I get the following error:
[2014-01-15 18:59:23 - Dex Loader] Unable to execute dex: Multiple dex files define Lorg/xmlpull/v1/XmlPullParser;
[2014-01-15 18:59:23 - AndroidMentor] Conversion to Dalvik format failed: Unable to execute dex: Multiple dex files define Lorg/xmlpull/v1/XmlPullParser;
This is on a clean brand new android app/android junit app. I've tried deleting bin, cleaning, etc but no use. It's just this one, the others don't show any problems.
I need this pullparser as the other ones don't quite seem to work with xstream for me.
回答1:
I was having the same problem with a separately developed project that I was trying to integrate with an android app. The problem is that the Android API defines the class XmlPullParser (https://developer.android.com/reference/org/xmlpull/v1/XmlPullParser.html) and is why this conflict arises.
I solved the problem by excluding the xmlpull dependency from the project which allowed for the Android-defined version of the classes to be used. This is how my build.gradle file looks for the app module (just the dependency section to illustrate the exclusion):
dependencies {
compile (project(':epublib:epublib-core')) {
exclude group: 'xmlpull'
}
compile 'com.android.support:appcompat-v7:21.0.+'
compile 'com.android.support:support-v4:21.0.+'
}
The syntax is important. It must be of the form
compile (project(':project-name')) {
exclude group: 'group-name', module: 'module-name'
}
来源:https://stackoverflow.com/questions/21146142/android-dalvik-conversion-for-xmlpullparser