当前位置:  开发笔记 > 编程语言 > 正文

无法使用gradle将xstream 1.4.8依赖项添加到Android

如何解决《无法使用gradle将xstream1.4.8依赖项添加到Android》经验,为你挑选了1个好方法。

我在将xstream库包含到基于Android gradle的应用程序时遇到了困难.从我在xstream文档中读到的内容来看,它应该"开箱即用".但是,当我添加依赖项时:

compile 'com.thoughtworks.xstream:xstream:1.4.8'

我在构建过程中遇到以下异常:

* 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

好吧,也许我应该排除xmlpull?我尝试将此依赖项更改为:

compile ('com.thoughtworks.xstream:xstream:1.4.8') {
    exclude group: 'xmlpull', module: 'xmlpull'
}

结果,一段时间后:

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

我还使用了检查项目依赖项gradle dependencies,但没有发现与xml相关的内容.

我的整个build.gradle档案:

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'
//    }
}

我应该怎么做才能将xstream库包含到我的项目中?



1> Greg Witczak..:

解决方案是将xstream降级到v1.4.7并排除xmlpull.

compile ('com.thoughtworks.xstream:xstream:1.4.7') {
    exclude group: 'xmlpull', module: 'xmlpull'
}

我不确切知道为什么,但我猜它必须与java8相关.

推荐阅读
sx-March23
这个屌丝很懒,什么也没留下!
DevBox开发工具箱 | 专业的在线开发工具网站    京公网安备 11010802040832号  |  京ICP备19059560号-6
Copyright © 1998 - 2020 DevBox.CN. All Rights Reserved devBox.cn 开发工具箱 版权所有