Theo Theo - 3 months ago 74
Android Question

Espresso 2.2.1 exception :app:transformClassesWithDexForDebugAndroidTest

In my app I want to Espresso in order to test the UI. However,when I try to run my project,I get message:

Error:Execution failed for task
':app:transformClassesWithDexForDebugAndroidTest'.
> com.android.build.api.transform.TransformException:
com.android.ide.common.process.ProcessException:
java.util.concurrent.ExecutionException:
com.android.ide.common.process.ProcessException:
org.gradle.process.internal.ExecException: Process 'command 'C:\Program
Files\Java\jdk1.8.0_45\bin\java.exe'' finished with non-zero exit value 2


This is my gradle setup:

apply plugin: 'com.android.application'

android {
compileSdkVersion 24
buildToolsVersion "24.0.0"

defaultConfig {
applicationId "theo.testing.androidespresso"
minSdkVersion 18
targetSdkVersion 24
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
androidTestCompile 'com.android.support:support-annotations:24.2.0'

compile 'com.android.support:appcompat-v7:24.2.0'
androidTestCompile('com.android.support.test.espresso:espresso-
core:2.2.1')
{
exclude group: 'javax.inject'
}
androidTestCompile 'com.android.support.test:testing-support-lib:0.1'

}


Any ideas why is this happening?

Thanks.

Answer

I'm pretty sure, that it's your third post and it has the same problem. You're trying to use dependencies which you don't need to have during the test.

Change your build.gradle dependencies section to:

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

compile 'com.android.support:appcompat-v7:24.2.0'

  testCompile 'junit:junit:4.12'

androidTestCompile 'com.android.support.test:runner:0.5'
androidTestCompile 'com.android.support:support-annotations:24.2.0'
androidTestCompile 'com.android.support.test.espresso:espresso-core:2.2.2'
androidTestCompile('com.android.support.test.espresso:espresso-contrib:2.2.1') {
    // Necessary to avoid version conflicts
    exclude group: 'com.android.support', module: 'appcompat'
    exclude group: 'com.android.support', module: 'support-v4'
    exclude group: 'com.android.support', module: 'support-annotations'
}

}

Google's official Android Testing Support Library site is enough to start Android testing.

See Espresso secton

Hope it will help