Can't add xstream 1.4.8 dependency to Android using gradle

大憨熊 提交于 2019-12-21 20:12:45

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!