I have an Android project containing an application MultiDex.
I am trying to run Espresso tests using ./gradlew clean connectectedAndroidTest. This command ultimately results in this error message:
:app:dexDebugAndroidTest
UNEXPECTED TOP-LEVEL EXCEPTION:
java.lang.IllegalArgumentException: already added: Landroid/support/test/InstrumentationRegistry;
My top level build.gradlecontains:
classpath 'com.android.tools.build:gradle:1.2.3'
and I use Gradle 2.4 through the wrapper.
My project is build.gradleas follows:
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'org.robolectric:robolectric-gradle-plugin:1.0.1'
}
}
apply plugin: 'android-sdk-manager'
apply plugin: 'com.android.application'
apply plugin: 'org.robolectric'
android {
compileSdkVersion 21
buildToolsVersion "22.0.1"
defaultConfig {
applicationId "com.something"
minSdkVersion 15
targetSdkVersion 21
versionCode 1
versionName "1.0"
multiDexEnabled true
testInstrumentationRunner "com.android.test.runner.MultiDexTestRunner"
}
dexOptions {
javaMaxHeapSize "2g"
preDexLibraries = false
}
buildTypes {
debug {
versionNameSuffix '-DEBUG'
minifyEnabled false
shrinkResources = false
zipAlignEnabled = false
}
release {
minifyEnabled false
shrinkResources = true
zipAlignEnabled = true
}
}
lintOptions {
checkReleaseBuilds false
abortOnError false
}
packagingOptions {
exclude 'LICENSE.txt'
exclude 'META-INF/DEPENDENCIES'
exclude 'META-INF/NOTICE'
exclude 'META-INF/LICENSE'
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/NOTICE.txt' }
}
dependencies {
compile 'com.android.support:multidex:1.0.1'
compile 'com.auth0.android:lock:1.7.0'
compile 'com.auth0.android:lock-googleplus:1.7.0'
compile 'com.android.support:appcompat-v7:22.1.1'
compile 'com.google.code.gson:gson:2.3.1'
compile 'com.squareup.picasso:picasso:2.1.1'
compile 'com.squareup.retrofit:retrofit:1.9.0'
compile 'com.squareup.okhttp:okhttp:2.4.0'
compile 'com.google.android.gms:play-services-plus:7.3.0'
compile 'io.reactivex:rxandroid:0.24.0'
compile 'com.amazonaws:aws-android-sdk-cognito:2.2.1'
compile 'com.amazonaws:aws-android-sdk-core:2.2.1'
compile 'com.amazonaws:aws-android-sdk-mobileanalytics:2.2.1'
testCompile "org.robolectric:robolectric:3.0-rc3"
testCompile "org.robolectric:shadows-multidex:3.0-rc3"
androidTestCompile ('com.android.support.test:rules:0.2') {
exclude module: 'support-v4'
exclude module: 'support-annotations'
}
androidTestCompile ('com.android.support.test:testing-support-lib:0.1') {
exclude group: 'junit'
}
androidTestCompile ('com.android.support.test.espresso:espresso-core:2.0') {
exclude module: 'testing-support-lib'
exclude module: 'support-v4'
exclude module: 'support-annotations'
exclude group: 'javax.inject'
}
}
robolectric {
include '**/*Test.class'
exclude '**/espresso/**/*.class'
maxHeapSize = '2048m'
maxParallelForks = 4
forkEvery = 150
ignoreFailures true
afterTest { descriptor, result ->
println "Executing test for ${descriptor.name} with result: ${result.resultType}"
}
}
Now I was trying to figure out what was going on, for example, by looking at the dependencies, using ./gradlew -q app:dependencieswhich leads to (among other internal configurations):
androidJacocoAgent - The Jacoco agent to use to get coverage data.
\
androidJacocoAnt - The Jacoco ant tasks to use to get execute Gradle tasks.
\
+
| \
+
| +
| \
\
androidTestCompile - Classpath for compiling the androidTest sources.
+
| \
| +
| | \
| \
+
\
+
+
| \
+
| \
+
+
+
\
compile - Classpath for compiling the main sources.
+
+
| +
| | \
| | \
| +
| +
| | +
| | +
| | \
| | +
| | +
| | +
| | \
| | +
| | \
| \
+
| +
| +
| \
| \
| \
+
+
+
+
| \
+
| \
+
+
| \
+
| \
| +
| \
+
\
\
testCompile - Classpath for compiling the test sources.
+
| +
| +
| +
| | +
| | | +
| | | \
| | +
| | \
| +
| +
| | +
| | +
| | +
| | +
| | \
| +
| +
| +
| | \
| | \
| +
| | \
| +
| | \
| +
| +
| \
| \
\
\
Now my question is: how do I figure out what causes duplication? From what I understand, there must be some kind of library, which includes another library that defines InstrumentationRegistry.