повторяющаяся запись: org / junit / ClassRule.class в Android

Я хочу запустить espresso test, написанный Record Espresso Test на Андориде. Тест написан так

Тест

import android.support.test.espresso.ViewInteraction;
import android.support.test.rule.ActivityTestRule;
import android.support.test.runner.AndroidJUnit4;
import android.test.suitebuilder.annotation.LargeTest;

import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;

import static android.support.test.espresso.Espresso.onView;
import static android.support.test.espresso.action.ViewActions.click;
import static android.support.test.espresso.action.ViewActions.closeSoftKeyboard;
import static android.support.test.espresso.action.ViewActions.replaceText;
import static android.support.test.espresso.matcher.ViewMatchers.isDisplayed;
import static android.support.test.espresso.matcher.ViewMatchers.withId;
import static android.support.test.espresso.matcher.ViewMatchers.withParent;
import static android.support.test.espresso.matcher.ViewMatchers.withText;
import static org.hamcrest.Matchers.allOf;
import android.support.multidex.MultiDex;

@LargeTest
@RunWith(AndroidJUnit4.class)
public class CarParki_SignIn_Test {

    @Rule
    public ActivityTestRule<CarParki_O> mActivityTestRule = new ActivityTestRule<>(CarParki_O.class);

    @Test
    public void carParki_SignIn_Test() {
        ViewInteraction appCompatButton = onView(
                allOf(withId(R.id.id_signIn), withText("SIGN IN"),
                        withParent(allOf(withId(R.id.buttonsLayout),
                                withParent(withId(R.id.content_login_or_signup)))),
                        isDisplayed()));
        appCompatButton.perform(click());

        ViewInteraction appCompatEditText = onView(
                allOf(withId(R.id.field_email),
                        withParent(withId(R.id.email_password_fields)),
                        isDisplayed()));
        appCompatEditText.perform(replaceText("[email protected]"), closeSoftKeyboard());

        ViewInteraction appCompatEditText2 = onView(
                allOf(withId(R.id.field_password),
                        withParent(withId(R.id.email_password_fields)),
                        isDisplayed()));
        appCompatEditText2.perform(replaceText("444444"), closeSoftKeyboard());

        ViewInteraction appCompatButton2 = onView(
                allOf(withId(R.id.email_sign_in_button), withText("Sign In"),
                        withParent(withId(R.id.email_password_buttons)),
                        isDisplayed()));
        appCompatButton2.perform(click());

    }

}

При беге дает;

Ошибка: не удалось выполнить задачу ': app: transformClassesWithJarMergingForDebugAndroidTest'. com.android.build.api.transform.TransformException: java.util.zip.ZipException: повторяющаяся запись: org / junit / ClassRule.class

Мой файл gradle:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 24
    buildToolsVersion "25.0.1"
    defaultConfig {
        applicationId "com.example.fyp_awais.carparki_o"
        minSdkVersion 16
        targetSdkVersion 24
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
        multiDexEnabled true
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations , '
    })
    androidTestCompile('com.android.support.test:testing-support-lib:0.1')
    compile 'com.android.support:appcompat-v7:24.2.1'
    compile 'com.android.support:design:24.2.1'
    compile 'com.google.firebase:firebase-database:10.0.1'
    compile 'com.google.android.gms:play-services:10.0.1'
    testCompile 'junit:junit:4.12'
}



apply plugin: 'com.google.gms.google-services'

Что-то здесь не так?


person user6750923    schedule 04.01.2017    source источник


Ответы (1)


Когда вы добавили зависимость com.android.support:multidex, вы фактически добавили некоторые зависимости, которые конфликтуют с другими зависимостями.

Я решил это:

  1. поиск класса, в вашем случае «RequestWeakReference.class» (в AndroidStudio просто нажмите Ctrl + N в Windows или CMD-O на Mac)
  2. Посмотрите, в какой банке он находится - Android Studio напишет его во всплывающем окне.
  3. Исключите его из всех сборок, например:

     android {
     configurations{
        all*.exclude module: 'servlet-api'
    }
    
person Raut Darpan    schedule 04.01.2017
comment
Я нашел класс ClassRule.java, но как его исключить из Gradle? - person user6750923; 04.01.2017
comment
модуль для этого будет показан во всплывающем поиске ctrl-n - person Raut Darpan; 04.01.2017
comment
например это: compile ('javax.annotation:javax.annotation-api:1.2'){ exclude group: 'com.google.common.annotations' } - person Raut Darpan; 04.01.2017
comment
есть два класса ClassRule.java, имеющих .jar 1 junit-dep-4.10.jar 2 junit-4.12.jar. Как исключить их из градиента? - person user6750923; 04.01.2017
comment
`testCompile ('junit: junit: 4.12') {исключить модуль: 'junit: 4.12'}` попробуйте это - person Raut Darpan; 04.01.2017
comment
Я заменяю junit зависимость на testCompile ('junit:junit:4.12'){ exclude module: 'junit:4.12' }, но получаю ту же ошибку - person user6750923; 04.01.2017
comment
проверьте эту ссылку [stackoverflow.com/questions/19575474/ - person Raut Darpan; 04.01.2017