问题
I'm having difficulties with including xstream library to my Android gradle-based app. From what I've read in xstream documentation, it should work "out of the box". However, when I add dependency:
compile 'com.thoughtworks.xstream:xstream:1.4.8'
I get following exception during build process:
* What went wrong:
Execution failed for task ':app:transformClassesWithJarMergingForDebug'.
> com.android.build.api.transform.TransformException: java.util.zip.ZipException: duplicate entry: org/xmlpull/v1/XmlPullParser.class
Ok, so maybe I should exclude xmlpull? I tried changing this dependency to:
compile ('com.thoughtworks.xstream:xstream:1.4.8') {
exclude group: 'xmlpull', module: 'xmlpull'
}
And, as a result, after some time:
UNEXPECTED TOP-LEVEL EXCEPTION:
java.lang.RuntimeException: Exception parsing classes
at com.android.dx.command.dexer.Main.processClass(Main.java:752)
// ...
Caused by: com.android.dx.cf.iface.ParseException: bad class file magic (cafebabe) or version (0034.0000)
at com.android.dx.cf.direct.DirectClassFile.parse0(DirectClassFile.java:472)
// ...
1 error; aborting
I've also checked project dependencies using gradle dependencies
, but found nothing xml-related there.
My whole build.gradle
file:
group 'myGroup'
version '1.0'
apply plugin: 'com.android.application'
buildscript {
repositories {
jcenter()
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.5.0'
}
}
android {
compileSdkVersion 23
buildToolsVersion "23.0.2"
useLibrary 'org.apache.http.legacy'
defaultConfig {
applicationId "edu.foo.app"
minSdkVersion 19
targetSdkVersion 23
versionCode 1
versionName "1.0"
multiDexEnabled true
}
buildTypes {
release {
minifyEnabled false
//proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
packagingOptions {
exclude 'META-INF/DEPENDENCIES'
exclude 'META-INF/NOTICE'
exclude 'META-INF/LICENSE'
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/NOTICE.txt'
}
}
repositories {
mavenCentral();
maven {
url 'https://repository-achartengine.forge.cloudbees.com/snapshot/'
}
}
dependencies {
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.1.1'
compile 'com.android.support:design:23.1.1'
compile project(':Commons')
compile 'commons-io:commons-io:2.4'
compile 'commons-codec:commons-codec:1.10'
compile 'com.nostra13.universalimageloader:universal-image-loader:1.9.4'
compile 'org.achartengine:achartengine:1.2.0'
compile 'com.google.code.gson:gson:2.4'
compile 'com.thoughtworks.xstream:xstream:1.4.8'
// compile ('com.thoughtworks.xstream:xstream:1.4.8') {
// exclude group: 'xmlpull', module: 'xmlpull'
// }
}
What should I do to include xstream library to my project?
回答1:
Solution was to downgrade xstream to v1.4.7 and exclude xmlpull.
compile ('com.thoughtworks.xstream:xstream:1.4.7') {
exclude group: 'xmlpull', module: 'xmlpull'
}
I don't know exactly why, but I'd guess that it must be java8-related.
回答2:
I was getting the same Error.What i did, i just Disable the "Enable all the test artifacts" from my default preferences.
and Open build variants select unit tests..
Hope above Ans may helps any one.
来源:https://stackoverflow.com/questions/34486111/cant-add-xstream-1-4-8-dependency-to-android-using-gradle