无法将dex与androidTestImplementation

时间:2017-12-08 15:33:49

标签: android gradle

当我尝试与uiAutomation一起运行我的android测试时,我无法合并dex异常。

androidTestImplementation ('com.google.android:android-test:4.1.1.4')
  

错误:任务':app:transformDexArchiveWithExternalLibsDexMergerForDebugAndroidTest'执行失败。   java.lang.RuntimeException:java.lang.RuntimeException:com.android.builder.dexing.DexArchiveMergerException:无法合并dex

但是,如果我从androidTestImplementation更改为testCompile,一切正常。如果有人能解释androidTestImplementation和testCompile之间的不同行为,我会很高兴。其次,我如何使用androidTestImplementation添加这个依赖。

buildscript {
    repositories {
        jcenter()
        google()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.0.1'
    }
}

apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'


allprojects {
    repositories {
        maven {
            url 'https://maven.google.com'
        }

    }
}

task wrapper(type: Wrapper) {
    gradleVersion = '4.1'
}


android {
    compileSdkVersion 27
    buildToolsVersion '26.0.2'

    dexOptions {
        javaMaxHeapSize "4g"
    }


    defaultConfig {
        minSdkVersion 19
        targetSdkVersion 27


        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
        multiDexEnabled = true

        vectorDrawables.useSupportLibrary = true
generatedDensities = []
    }

    // This is handled for you by the 2.0+ Gradle Plugin
    aaptOptions {
        additionalParameters "--no-version-vectors"
    }




    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }


    buildTypes {
        debug {
            debuggable true
            shrinkResources false
            versionNameSuffix "-debug"
            minifyEnabled false

//            minifyEnabled true
//            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.txt'
//            testProguardFiles file ('test-proguard-rules.pro')
        }
        release {
            debuggable true
            minifyEnabled true
            signingConfig signingConfigs.release
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.txt'

        }
        staging {
            // Specifies a sorted list of fallback build types that the
            // plugin should try to use when a dependency does not include a
            // "staging" build type. You may specify as many fallbacks as you
            // like, and the plugin selects the first build type that's
            // available in the dependency.
            matchingFallbacks = ['debug', 'qa', 'release']
        }


    }



    dependencies {
        compile fileTree(include: ['*.jar'], dir: 'libs')


        def playVersion = '11.6.2'
        compile 'com.j256.ormlite:ormlite-core:4.48'
        compile 'com.j256.ormlite:ormlite-android:4.48'
        compile 'com.squareup.picasso:picasso:2.5.2'

        implementation 'com.android.support:appcompat-v7:27.0.2'
        compile 'com.roomorama:caldroid:3.0.1'
        compile 'com.google.android.gms:play-services-location:' + playVersion
        compile 'com.google.android.gms:play-services-ads:' + playVersion

        compile 'com.google.android.gms:play-services-analytics:' + playVersion
        compile 'com.google.guava:guava:18.0'
        compile 'com.google.code.gson:gson:2.5'
        compile 'org.apache.commons:commons-lang3:3.4'
        compile 'org.apache.commons:commons-collections4:4.1'
        compile 'com.android.support:design:27.0.2'
        compile 'joda-time:joda-time:2.9.3'
        compile 'org.joda:joda-convert:1.8.1'
        compile group: 'com.github.chrisbanes.photoview', name: 'library', version: '1.2.4'
        compile 'com.android.support:multidex:1.0.2'

        compile 'com.amazonaws:aws-android-sdk-core:2.4.2'
        compile 'com.amazonaws:aws-android-sdk-s3:2.4.2'
        compile 'com.amazonaws:aws-android-sdk-ddb:2.4.2'
        compile 'com.google.android.gms:play-services-auth:' + playVersion

        // https://mvnrepository.com/artifact/org.simpleframework/simple-xml
        compile('org.simpleframework:simple-xml:2.7.1') {
            exclude group: 'xpp3', module: 'xpp3'
            exclude group: 'stax', module: 'stax-api'
            exclude group: 'stax', module: 'stax'
        }

        compile group: 'commons-codec', name: 'commons-codec', version: '1.3'
        compile project(':volley')
        compile project(':SimpleDTGHub')


        implementation "android.arch.lifecycle:runtime:1.0.3"
        implementation "android.arch.lifecycle:extensions:1.0.0"

        androidTestImplementation 'com.android.support:support-annotations:27.0.2'

        androidTestImplementation 'junit:junit:4.12'
        androidTestImplementation('org.robolectric:robolectric:2.4') {
            exclude group: 'commons-logging', module: 'commons-logging'
            exclude group: 'org.apache.httpcomponents', module: 'httpclient'
        }

        androidTestImplementation('com.google.android:android-test:4.1.1.4') {
            exclude group: 'org.apache.httpcomponents', module: 'httpclient'
            exclude group: 'junit', module: 'junit'
        }

        androidTestImplementation "com.android.support.test:runner:1.0.1"
        androidTestImplementation "com.android.support.test.espresso:espresso-core:3.0.1"
        androidTestImplementation 'com.android.support.test.espresso:espresso-intents:3.0.1'


    }

    android {
        packagingOptions {
            exclude 'LICENSE.txt'
            exclude 'META-INF/DEPENDENCIES.txt'
            exclude 'META-INF/LICENSE.txt'
            exclude 'META-INF/NOTICE.txt'
            exclude 'META-INF/NOTICE'
            exclude 'META-INF/LICENSE'
            exclude 'META-INF/DEPENDENCIES'
            exclude 'META-INF/notice.txt'
            exclude 'META-INF/license.txt'
            exclude 'META-INF/dependencies.txt'
            exclude 'META-INF/inputList.txt'
            exclude 'META-INF/inputList'
            exclude 'META-INF/jersey-module-version'

        }
    }


}
repositories {
    mavenCentral()
}
dependencies {
    compile "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"
}

全程输出:

Executing tasks: [:MyApp:assembleDebug, :MyApp:assembleDebugAndroidTest]

Configuration 'compile' in project ':MyApp' is deprecated. Use 'implementation' instead.
Configuration 'compile' in project ':SimpleDTGHub' is deprecated. Use 'implementation' instead.
Configuration 'testCompile' in project ':volley' is deprecated. Use 'testImplementation' instead.
:MyApp:preBuild UP-TO-DATE
:SimpleDTGHub:preBuild UP-TO-DATE
:SimpleDTGHub:preDebugBuild UP-TO-DATE
:SimpleDTGHub:checkDebugManifest UP-TO-DATE
:SimpleDTGHub:processDebugManifest UP-TO-DATE
:volley:preBuild UP-TO-DATE
:volley:preDebugBuild UP-TO-DATE
:volley:checkDebugManifest UP-TO-DATE
:volley:processDebugManifest UP-TO-DATE
:MyApp:preDebugBuild UP-TO-DATE
:SimpleDTGHub:compileDebugAidl UP-TO-DATE
:volley:compileDebugAidl UP-TO-DATE
:MyApp:compileDebugAidl UP-TO-DATE
:SimpleDTGHub:packageDebugRenderscript NO-SOURCE
:volley:packageDebugRenderscript NO-SOURCE
:MyApp:compileDebugRenderscript UP-TO-DATE
:MyApp:checkDebugManifest UP-TO-DATE
:MyApp:generateDebugBuildConfig UP-TO-DATE
:MyApp:generateDebugResValues UP-TO-DATE
:MyApp:generateDebugResources UP-TO-DATE
:SimpleDTGHub:compileDebugRenderscript UP-TO-DATE
:SimpleDTGHub:generateDebugResValues UP-TO-DATE
:SimpleDTGHub:generateDebugResources UP-TO-DATE
:SimpleDTGHub:packageDebugResources UP-TO-DATE
:volley:compileDebugRenderscript UP-TO-DATE
:volley:generateDebugResValues UP-TO-DATE
:volley:generateDebugResources UP-TO-DATE
:volley:packageDebugResources UP-TO-DATE
:MyApp:mergeDebugResources UP-TO-DATE
:MyApp:createDebugCompatibleScreenManifests UP-TO-DATE
:MyApp:processDebugManifest UP-TO-DATE
:MyApp:splitsDiscoveryTaskDebug UP-TO-DATE
:SimpleDTGHub:platformAttrExtractor UP-TO-DATE
:SimpleDTGHub:processDebugResources UP-TO-DATE
:volley:platformAttrExtractor UP-TO-DATE
:volley:processDebugResources UP-TO-DATE
:MyApp:processDebugResources UP-TO-DATE
:SimpleDTGHub:generateDebugBuildConfig UP-TO-DATE
:SimpleDTGHub:compileDebugKotlin UP-TO-DATE
:SimpleDTGHub:prepareLintJar UP-TO-DATE
:SimpleDTGHub:generateDebugSources UP-TO-DATE
:SimpleDTGHub:javaPreCompileDebug UP-TO-DATE
:SimpleDTGHub:compileDebugJavaWithJavac UP-TO-DATE
:SimpleDTGHub:processDebugJavaRes NO-SOURCE
:SimpleDTGHub:transformClassesAndResourcesWithPrepareIntermediateJarsForDebug UP-TO-DATE
:volley:generateDebugBuildConfig UP-TO-DATE
:volley:prepareLintJar UP-TO-DATE
:volley:generateDebugSources UP-TO-DATE
:volley:javaPreCompileDebug UP-TO-DATE
:volley:compileDebugJavaWithJavac UP-TO-DATE
:volley:processDebugJavaRes NO-SOURCE
:volley:transformClassesAndResourcesWithPrepareIntermediateJarsForDebug UP-TO-DATE
:MyApp:compileDebugKotlin
:MyApp:prepareLintJar UP-TO-DATE
:MyApp:generateDebugSources UP-TO-DATE
:MyApp:javaPreCompileDebug
:MyApp:compileDebugJavaWithJavac
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Note: Some input files use unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
:MyApp:compileDebugNdk NO-SOURCE
:MyApp:compileDebugSources
:MyApp:mergeDebugShaders UP-TO-DATE
:MyApp:compileDebugShaders UP-TO-DATE
:MyApp:generateDebugAssets UP-TO-DATE
:SimpleDTGHub:mergeDebugShaders UP-TO-DATE
:SimpleDTGHub:compileDebugShaders UP-TO-DATE
:SimpleDTGHub:generateDebugAssets UP-TO-DATE
:SimpleDTGHub:mergeDebugAssets UP-TO-DATE
:volley:mergeDebugShaders UP-TO-DATE
:volley:compileDebugShaders UP-TO-DATE
:volley:generateDebugAssets UP-TO-DATE
:volley:mergeDebugAssets UP-TO-DATE
:MyApp:mergeDebugAssets UP-TO-DATE
:MyApp:transformClassesWithStackFramesFixerForDebug UP-TO-DATE
:MyApp:transformClassesWithDesugarForDebug UP-TO-DATE
:MyApp:transformClassesWithDexBuilderForDebug UP-TO-DATE
:MyApp:transformDexArchiveWithExternalLibsDexMergerForDebug UP-TO-DATE
:MyApp:transformDexArchiveWithDexMergerForDebug UP-TO-DATE
:MyApp:mergeDebugJniLibFolders UP-TO-DATE
:SimpleDTGHub:compileDebugNdk NO-SOURCE
:SimpleDTGHub:mergeDebugJniLibFolders UP-TO-DATE
:SimpleDTGHub:transformNativeLibsWithMergeJniLibsForDebug UP-TO-DATE
:SimpleDTGHub:transformNativeLibsWithIntermediateJniLibsForDebug UP-TO-DATE
:volley:compileDebugNdk NO-SOURCE
:volley:mergeDebugJniLibFolders UP-TO-DATE
:volley:transformNativeLibsWithMergeJniLibsForDebug UP-TO-DATE
:volley:transformNativeLibsWithIntermediateJniLibsForDebug UP-TO-DATE
:MyApp:transformNativeLibsWithMergeJniLibsForDebug UP-TO-DATE
:MyApp:processDebugJavaRes NO-SOURCE
:MyApp:transformResourcesWithMergeJavaResForDebug UP-TO-DATE
:MyApp:validateSigningDebug
:MyApp:packageDebug UP-TO-DATE
:MyApp:assembleDebug
:MyApp:bundleAppClassesDebug UP-TO-DATE
:MyApp:preDebugAndroidTestBuild
:MyApp:compileDebugAndroidTestAidl UP-TO-DATE
:MyApp:processDebugAndroidTestManifest UP-TO-DATE
:MyApp:compileDebugAndroidTestRenderscript UP-TO-DATE
:MyApp:generateDebugAndroidTestBuildConfig UP-TO-DATE
:MyApp:generateDebugAndroidTestResValues UP-TO-DATE
:MyApp:generateDebugAndroidTestResources UP-TO-DATE
:MyApp:mergeDebugAndroidTestResources UP-TO-DATE
:MyApp:splitsDiscoveryTaskDebugAndroidTest UP-TO-DATE
:MyApp:processDebugAndroidTestResources UP-TO-DATE
:MyApp:compileDebugAndroidTestKotlin
:MyApp:generateDebugAndroidTestSources UP-TO-DATE
:MyApp:javaPreCompileDebugAndroidTest
:MyApp:compileDebugAndroidTestJavaWithJavac
:MyApp:compileDebugAndroidTestNdk NO-SOURCE
:MyApp:compileDebugAndroidTestSources
:MyApp:mergeDebugAndroidTestShaders UP-TO-DATE
:MyApp:compileDebugAndroidTestShaders UP-TO-DATE
:MyApp:generateDebugAndroidTestAssets UP-TO-DATE
:MyApp:mergeDebugAndroidTestAssets UP-TO-DATE
:MyApp:transformClassesWithStackFramesFixerForDebugAndroidTest UP-TO-DATE
:MyApp:transformClassesWithDesugarForDebugAndroidTest UP-TO-DATE
:MyApp:transformClassesWithDexBuilderForDebugAndroidTest UP-TO-DATE
:MyApp:transformDexArchiveWithExternalLibsDexMergerForDebugAndroidTest FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':MyApp:transformDexArchiveWithExternalLibsDexMergerForDebugAndroidTest'.
> java.lang.RuntimeException: java.lang.RuntimeException: com.android.builder.dexing.DexArchiveMergerException: Unable to merge dex

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

* Get more help at https://help.gradle.org

BUILD FAILED in 7s

87 actionable tasks: 9 executed, 78 up-to-date

1 个答案:

答案 0 :(得分:0)

根本原因是XmlPullParserException类的冲突。该类是xxp3依赖项的一部分,是org.simpleframework.simplexml的一部分。

+--- com.google.android:android-test:4.1.1.4
|    +--- com.google.android:android:4.1.1.4
|    |    +--- commons-logging:commons-logging:1.1.1
|    |    +--- org.apache.httpcomponents:httpclient:4.0.1
|    |    |    +--- org.apache.httpcomponents:httpcore:4.0.1
|    |    |    +--- commons-logging:commons-logging:1.1.1
|    |    |    \--- commons-codec:commons-codec:1.3
|    |    +--- org.khronos:opengl-api:gl1.1-android-2.1_r1
|    |    +--- xerces:xmlParserAPIs:2.6.2
|    |    +--- xpp3:xpp3:1.1.4c

要解决此问题,我必须从com.google.android:android-test中排除dependecy。

 androidTestImplementation('com.google.android:android-test:4.1.1.4'){
            exclude group: 'xpp3'
        }