用于调试Android测试的Dex的Android Espresso测试失败

时间:2016-01-31 10:21:43

标签: android android-espresso

我正在尝试运行一个简单的Espresso测试,它失败并显示错误消息

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

我已经注释掉了很多我的gradle依赖项。这是导致失败的测试。主App可以运行但不能运行

@RunWith(AndroidJUnit4.class)
@LargeTest
public class ScheduleActivityTest {
    @Rule
    public final ActivityTestRule<ScheduleActivity> schedule = new ActivityTestRule<>(ScheduleActivity.class);

    @Test
    public void shouldBeVisible() throws Exception {
        onView(withId(R.layout.activity_schedule))
                .check((ViewAssertion) isDisplayed());

    }
}

这是我的gradle文件

apply plugin: 'com.android.application'
apply plugin: 'com.neenbedankt.android-apt'

android {
    compileSdkVersion 23
    buildToolsVersion "23.0.2"

    defaultConfig {
        applicationId "com.okason.prontosalon"
        minSdkVersion 16
        targetSdkVersion 23
        versionCode 1
        versionName "1.0"

        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    }

   dependencies {

    compile 'com.android.support:support-annotations:23.1.1'

    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile('com.mikepenz:materialdrawer:4.6.4@aar') {
        transitive = true
    }
    compile 'com.android.support:appcompat-v7:23.1.1'
    compile 'com.android.support:design:23.1.1'

    compile 'com.squareup:otto:1.3.8'
    compile 'com.squareup.picasso:picasso:2.5.2'
    compile 'com.jakewharton:butterknife:7.0.1'
    compile 'de.hdodenhof:circleimageview:2.0.0'
    compile 'com.mikepenz:fontawesome-typeface:4.4.0.1@aar'

    androidTestCompile 'com.android.support.test.espresso:espresso-core:2.2.1'
    androidTestCompile 'com.android.support.test:runner:0.4.1'
    androidTestCompile 'com.android.support.test:rules:0.4.1'
    androidTestCompile 'com.android.support:support-annotations:23.1.1'
    androidTestCompile 'com.android.support.test:testing-support-lib:0.1'


}

我能做错什么?这是我的项目结构

enter image description here

1 个答案:

答案 0 :(得分:0)

您可以尝试将dexOptions添加到app / build.gradle。

dexOptions {
  jumboMode = true
}