Android tests build error: Multiple dex files define Landroid/support/test/BuildConfig

前端 未结 7 2299
逝去的感伤
逝去的感伤 2020-12-01 05:02

I\'m trying to add Espresso 2 to my project (which also has lots of other dependencies), but I\'m hitting this error when trying to run tests:

UNEXPECTED TOP         


        
相关标签:
7条回答
  • 2020-12-01 05:05

    I got this error trying to set up Espresso as well. Try using espresso-contrib:2.1, not 2.0

    0 讨论(0)
  • 2020-12-01 05:08

    Try excluding the following from espresso (one at a time):

    androidTestCompile('com.android.support.test.espresso:espresso-core:2.1') {
      exclude group: 'javax.inject'
      exclude group: 'com.google.code.findbugs'
      exclude group: 'com.android.support', module: 'support-annotations'
    }
    

    Probably need to do the same with runner

    0 讨论(0)
  • 2020-12-01 05:10

    I recently ran into this error after we enabled incremental gradle builds.

    dexOptions {
        javaMaxHeapSize "2g"
        incremental true
    }
    

    This was resolved by disabling predexing libraries.

    dexOptions {
        javaMaxHeapSize "2g"
        incremental true
        preDexLibraries = false
    }
    
    0 讨论(0)
  • 2020-12-01 05:13

    According to this bug report, you can also use resolutionStrategy:

    allprojects {
        repositories {
            mavenCentral()
            maven {
                url 'http://download.crashlytics.com/maven'
            }
        }
        configurations.all {
            resolutionStrategy.force 'com.android.support:support-annotations:22.2.0'
        }
    }
    

    This is the solution that worked for me and allowed me to use the most recent version of appcompat-v7 and appcompat-v4.

    0 讨论(0)
  • 2020-12-01 05:22

    One other useful tip is how to force dependency resolution to a specific version.

    Here is one way:

    configurations.all {
        resolutionStrategy.force 'com.android.support:support-annotations:22.0.0'
    }
    

    ...and here is another:

    configurations.all {
        resolutionStrategy.eachDependency { DependencyResolveDetails details ->
            if (details.requested.group == 'com.android.support') {
                details.useVersion '22.0.0'
            }
        }
    }
    

    Using either of these with com.android.support.test.espresso:espresso-core:2.1 should work.

    See the Forcing consistent version for a group of libraries section in the Gradle documentation for more information.

    0 讨论(0)
  • 2020-12-01 05:28

    My solution:

    compile 'com.android.support:appcompat-v7:22.1.0'
    androidTestCompile 'com.android.support.test.espresso:espresso-core:2.1'
    androidTestCompile 'com.android.support:support-annotations:22.1.0'
    androidTestCompile 'com.android.support.test:runner:0.2'
    

    +

    android {
        packagingOptions {
            exclude 'LICENSE.txt'
       }
    }
    
    0 讨论(0)
提交回复
热议问题