Espresso 2.2.1异常:app:transformClassesWithDexForDebugAndroidTest

时间:2016-08-24 06:52:27

标签: android gradle android-gradle android-espresso

在我的应用中,我想要Espresso来测试用户界面。但是,当我尝试运行我的项目时,我收到消息:

  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

这是我的gradle设置:

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'

 }

任何想法为什么会发生这种情况?

感谢。

1 个答案:

答案 0 :(得分:1)

我很确定,这是你的第三篇帖子,它有同样的问题。 您尝试使用测试期间不需要的依赖项。

将您的build.gradle依赖关系部分更改为:

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的官方Android Testing Support Library网站足以启动Android测试。

Espresso secton

希望它会有所帮助