无法将 Ksoap2 依赖项添加到 Android 项目

Can't add Ksoap2 dependency to Android project

我一直在尝试将 ksoap2 添加到我的 android 项目中。下面是我的 build.gradle 文件:

apply plugin: 'com.android.application'

repositories {
mavenCentral()

maven {
    url 'https://oss.sonatype.org/content/repositories/ksoap2-android-releases/'
}
}


android {
compileSdkVersion 23
buildToolsVersion "23.0.2"


defaultConfig {
    applicationId "com.rsa.mobile.android.transactionsigningsdk"
    minSdkVersion 14
    targetSdkVersion 23
    versionCode 1
    versionName "1.0"
}
buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'),    'proguard-rules.pro'
    }

}
}

dependencies {
compile('com.thoughtworks.xstream:xstream:1.4.7') {
    exclude group: 'xmlpull'
}
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.1.0'
compile 'com.android.support:design:23.1.0'
compile ('com.google.code.ksoap2-android:ksoap2-android:3.0.0')
}

该项目编译正常,没有错误,但是当 运行 我的设备上的应用程序出现以下错误时:

Information:Gradle tasks [:app:generateDebugSources,   

:app:generateDebugAndroidTestSources, :app:assembleDebug]
:app:preBuild UP-TO-DATE
:app:preDebugBuild UP-TO-DATE
:app:checkDebugManifest
:app:preRele

aseBuild UP-TO-DATE
:app:prepareComAndroidSupportAppcompatV72310Library UP-TO-DATE
:app:prepareComAndroidSupportDesign2310Library UP-TO-DATE
:app:prepareComAndroidSupportRecyclerviewV72310Library UP-TO-DATE
:app:prepareComAndroidSupportSupportV42310Library UP-TO-DATE
:app:prepareDebugDependencies
:app:compileDebugAidl UP-TO-DATE
:app:compileDebugRenderscript UP-TO-DATE
:app:generateDebugBuildConfig UP-TO-DATE
:app:generateDebugAssets UP-TO-DATE
:app:mergeDebugAssets UP-TO-DATE
:app:generateDebugResValues UP-TO-DATE
:app:generateDebugResources UP-TO-DATE
:app:mergeDebugResources UP-TO-DATE
:app:processDebugManifest UP-TO-DATE
:app:processDebugResources UP-TO-DATE
:app:generateDebugSources UP-TO-DATE
:app:preDebugAndroidTestBuild UP-TO-DATE
:app:prepareDebugAndroidTestDependencies
:app:compileDebugAndroidTestAidl UP-TO-DATE
:app:processDebugAndroidTestManifest UP-TO-DATE
:app:compileDebugAndroidTestRenderscript UP-TO-DATE
:app:generateDebugAndroidTestBuildConfig UP-TO-DATE
:app:generateDebugAndroidTestAssets UP-TO-DATE
:app:mergeDebugAndroidTestAssets UP-TO-DATE
:app:generateDebugAndroidTestResValues UP-TO-DATE
:app:generateDebugAndroidTestResources UP-TO-DATE
:app:mergeDebugAndroidTestResources UP-TO-DATE
:app:processDebugAndroidTestResources UP-TO-DATE
:app:generateDebugAndroidTestSources UP-TO-DATE
:app:processDebugJavaRes UP-TO-DATE
:app:compileDebugJavaWithJavac UP-TO-DATE
:app:compileDebugNdk UP-TO-DATE
:app:compileDebugSources UP-TO-DATE
:app:preDexDebug UP-TO-DATE
:app:dexDebug
UNEXPECTED TOP-LEVEL EXCEPTION:
com.android.dex.DexException: Multiple dex files define Lorg/xmlpull/v1/XmlPullParser;
at com.android.dx.merge.DexMerger.readSortableTypes(DexMerger.java:579)
at com.android.dx.merge.DexMerger.getSortedTypes(DexMerger.java:535)
at com.android.dx.merge.DexMerger.mergeClassDefs(DexMerger.java:517)
at com.android.dx.merge.DexMerger.mergeDexes(DexMerger.java:164)
at com.android.dx.merge.DexMerger.merge(DexMerger.java:188)
at com.android.dx.command.dexer.Main.mergeLibraryDexBuffers(Main.java:504)
at com.android.dx.command.dexer.Main.runMonoDex(Main.java:334)
at com.android.dx.command.dexer.Main.run(Main.java:277)
at com.android.dx.command.dexer.Main.main(Main.java:245)
at com.android.dx.command.Main.main(Main.java:106)
Error:Execution failed for task ':app:dexDebug'.
> com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command 'C:\Program Files\Java\jdk1.7.0_79\bin\java.exe'' finished with non-zero exit value 2
Information:BUILD FAILED
Information:Total time: 4.485 secs
Information:1 error
Information:0 warnings
Information:See complete output in console 

我已经查找了几乎所有相关问题以查找此类错误,但没有任何效果。 我试过:

1) 清理项目

2) 添加

android {
dexOptions {
preDexLibraries = false
}
}

到我的 gradle 文件

3) 添加

{
exclude group: 'xmlpull'
}

还有很多其他的东西,但没有任何帮助。 我还用 ksoap2 创建了一个新的 android 项目并且成功了。下面是工作 build.gradle:

apply plugin: 'com.android.application'

repositories {
    mavenCentral()

    maven {
        url 'https://oss.sonatype.org/content/repositories/ksoap2-android-releases/'
    }
}

android {
    compileSdkVersion 23
    buildToolsVersion "23.0.2"

    defaultConfig {
        applicationId "com.rsa.mobile.test_ksoap"
        minSdkVersion 14
        targetSdkVersion 23
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {

    testCompile 'junit:junit:4.12'
    compile 'com.android.support:appcompat-v7:23.1.0'
    compile 'com.android.support:design:23.1.0'
    compile 'com.google.code.ksoap2-android:ksoap2-android:3.0.0'
}

它的 xstream 和 ksoap2 一起使用时会导致问题,但我不知道如何解决这个问题。当彼此单独使用时,我的代码有效

有人可以帮忙吗。到目前为止,我已经做了我能做的一切,一点运气都没有。

我终于找到了解决办法。我们应该添加 添加 ksoap2 依赖项时排除模块:'xmlpull' 而不是排除组:'xmlpull'。