Не удалось запустить приложение с `debugImplementation 'androidx.fragment: фрагмент-тестирование:' + фрагмент_версии` в качестве зависимости - PullRequest
1 голос
/ 13 марта 2020

Я новичок в android.

Я занимаюсь разработкой в ​​Java.

Моя цель - использовать FragmentScenraio в моей тестовой среде.

В руководствах, которые я нашел, я вижу, что мне нужно добавить:

dependencies {
    def fragment_version = "1.2.2"
    // ...
    debugImplementation 'androidx.fragment:fragment-testing:$fragment_version'
}

к моим зависимостям.

Я добавляю его, и проект успешно компилируется.

Проблема в том, что когда я запускаю приложение в Android Studio, я получаю

FAILURE: Build failed with an exception.

* What went wrong:
Could not determine the dependencies of task ':app:preDebugAndroidTestBuild'.
> Could not resolve all task dependencies for configuration ':app:debugAndroidTestRuntimeClasspath'.
   > Could not resolve androidx.test:core:1.3.0-alpha04.
     Required by:
         project :app
         project :app > androidx.test:core-ktx:1.3.0-alpha04
         project :app > androidx.test.ext:junit:1.1.2-alpha04
         project :app > androidx.test.espresso:espresso-intents:3.3.0-alpha04
      > Cannot find a version of 'androidx.test:core' that satisfies the version constraints: 
           Dependency path 'ExamScanner:app:unspecified' --> 'androidx.test:core:1.3.0-alpha04'
           Constraint path 'ExamScanner:app:unspecified' --> 'androidx.test:core:{strictly 1.2.0}' because of the following reason: debugRuntimeClasspath uses version 1.2.0
           Dependency path 'ExamScanner:app:unspecified' --> 'androidx.test:core-ktx:1.3.0-alpha04' --> 'androidx.test:core:1.3.0-alpha04'
           Dependency path 'ExamScanner:app:unspecified' --> 'androidx.test.ext:junit:1.1.2-alpha04' --> 'androidx.test:core:1.3.0-alpha04'
           Dependency path 'ExamScanner:app:unspecified' --> 'androidx.test.espresso:espresso-intents:3.3.0-alpha04' --> 'androidx.test:core:1.3.0-alpha04'
           Dependency path 'ExamScanner:app:unspecified' --> 'androidx.fragment:fragment-testing:1.2.2' --> 'androidx.test:core:1.2.0'

   > Could not resolve androidx.test:core:{strictly 1.2.0}.
     Required by:
         project :app
      > Cannot find a version of 'androidx.test:core' that satisfies the version constraints: 
           Dependency path 'ExamScanner:app:unspecified' --> 'androidx.test:core:1.3.0-alpha04'
           Constraint path 'ExamScanner:app:unspecified' --> 'androidx.test:core:{strictly 1.2.0}' because of the following reason: debugRuntimeClasspath uses version 1.2.0
           Dependency path 'ExamScanner:app:unspecified' --> 'androidx.test:core-ktx:1.3.0-alpha04' --> 'androidx.test:core:1.3.0-alpha04'
           Dependency path 'ExamScanner:app:unspecified' --> 'androidx.test.ext:junit:1.1.2-alpha04' --> 'androidx.test:core:1.3.0-alpha04'
           Dependency path 'ExamScanner:app:unspecified' --> 'androidx.test.espresso:espresso-intents:3.3.0-alpha04' --> 'androidx.test:core:1.3.0-alpha04'
           Dependency path 'ExamScanner:app:unspecified' --> 'androidx.fragment:fragment-testing:1.2.2' --> 'androidx.test:core:1.2.0'

   > Could not resolve androidx.test:monitor:{strictly 1.2.0}.
     Required by:
         project :app
      > Cannot find a version of 'androidx.test:monitor' that satisfies the version constraints: 
           Dependency path 'ExamScanner:app:unspecified' --> 'androidx.test:core:1.3.0-alpha04' --> 'androidx.test:monitor:1.3.0-alpha04'
           Constraint path 'ExamScanner:app:unspecified' --> 'androidx.test:monitor:{strictly 1.2.0}' because of the following reason: debugRuntimeClasspath uses version 1.2.0
           Dependency path 'ExamScanner:app:unspecified' --> 'androidx.test.ext:junit:1.1.2-alpha04' --> 'androidx.test:monitor:1.3.0-alpha04'
           Dependency path 'ExamScanner:app:unspecified' --> 'androidx.test:runner:1.3.0-alpha04' --> 'androidx.test:monitor:1.3.0-alpha04'

   > Could not resolve androidx.test:monitor:1.3.0-alpha04.
     Required by:
         project :app > androidx.test:core:1.3.0-alpha04
         project :app > androidx.test.ext:junit:1.1.2-alpha04
         project :app > androidx.test:runner:1.3.0-alpha04
      > Cannot find a version of 'androidx.test:monitor' that satisfies the version constraints: 
           Dependency path 'ExamScanner:app:unspecified' --> 'androidx.test:core:1.3.0-alpha04' --> 'androidx.test:monitor:1.3.0-alpha04'
           Constraint path 'ExamScanner:app:unspecified' --> 'androidx.test:monitor:{strictly 1.2.0}' because of the following reason: debugRuntimeClasspath uses version 1.2.0
           Dependency path 'ExamScanner:app:unspecified' --> 'androidx.test.ext:junit:1.1.2-alpha04' --> 'androidx.test:monitor:1.3.0-alpha04'
           Dependency path 'ExamScanner:app:unspecified' --> 'androidx.test:runner:1.3.0-alpha04' --> 'androidx.test:monitor:1.3.0-alpha04'

   > Could not resolve androidx.test:core:1.2.0.
     Required by:
         project :app > androidx.fragment:fragment-testing:1.2.2
      > Cannot find a version of 'androidx.test:core' that satisfies the version constraints: 
           Dependency path 'ExamScanner:app:unspecified' --> 'androidx.test:core:1.3.0-alpha04'
           Constraint path 'ExamScanner:app:unspecified' --> 'androidx.test:core:{strictly 1.2.0}' because of the following reason: debugRuntimeClasspath uses version 1.2.0
           Dependency path 'ExamScanner:app:unspecified' --> 'androidx.test:core-ktx:1.3.0-alpha04' --> 'androidx.test:core:1.3.0-alpha04'
           Dependency path 'ExamScanner:app:unspecified' --> 'androidx.test.ext:junit:1.1.2-alpha04' --> 'androidx.test:core:1.3.0-alpha04'
           Dependency path 'ExamScanner:app:unspecified' --> 'androidx.test.espresso:espresso-intents:3.3.0-alpha04' --> 'androidx.test:core:1.3.0-alpha04'
           Dependency path 'ExamScanner:app:unspecified' --> 'androidx.fragment:fragment-testing:1.2.2' --> 'androidx.test:core:1.2.0'


* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 0s

Может кто-нибудь сказать, пожалуйста, что здесь происходит?

Я пытался следовать этому , но он тоже не работал.

Спасибо.

Я добавляю свой файл app / gradle.build:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 28
    buildToolsVersion rootProject.buildToolsVersion
    defaultConfig {
        applicationId "com.example.examscanner"
        minSdkVersion 21
        targetSdkVersion 28
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
    testOptions {
        unitTests {
            includeAndroidResources = true
        }
    }
    compileOptions {
        sourceCompatibility = 1.8
        targetCompatibility = 1.8
    }
}

dependencies {
    def camerax_version = "1.0.0-beta01"
    def fragment_version = "1.2.2"
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'androidx.appcompat:appcompat:1.0.2'
    implementation 'com.google.android.material:material:1.0.0'
    implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
    implementation 'androidx.navigation:navigation-fragment:2.0.0'
    implementation 'androidx.navigation:navigation-ui:2.0.0'
    implementation 'androidx.lifecycle:lifecycle-extensions:2.0.0'
    implementation 'androidx.legacy:legacy-support-v4:1.0.0'
    //noinspection GradleCompatible
    implementation 'com.android.support:recyclerview-v7:28.0.0'
    // CameraX core library using the camera2 implementation
    implementation "androidx.camera:camera-camera2:${camerax_version}"
    // If you want to use the CameraX View class
    implementation "androidx.camera:camera-view:1.0.0-alpha08"
    // If you want to use the CameraX Extensions library
    implementation "androidx.camera:camera-extensions:1.0.0-alpha08"
    // If you want to use the CameraX Lifecycle library
    implementation "androidx.camera:camera-lifecycle:${camerax_version}"
    // RxJava
    implementation "io.reactivex.rxjava2:rxandroid:2.0.1"
    implementation "io.reactivex.rxjava2:rxjava:2.1.3"
    implementation ("androidx.fragment:fragment-testing:"+fragment_version, {
        exclude group: 'androidx.test', module: 'core'
    })

    // androidTest
    androidTestImplementation 'androidx.test:core:' + rootProject.coreVersion
    androidTestImplementation 'androidx.test:core-ktx:' + rootProject.coreVersion
    androidTestImplementation 'androidx.test.ext:junit:' + rootProject.extJUnitVersion
    androidTestImplementation 'androidx.test.ext:junit-ktx:' + rootProject.extJUnitVersion
    androidTestImplementation 'androidx.test:runner:' + rootProject.runnerVersion
    androidTestImplementation 'androidx.test.espresso:espresso-core:' + rootProject.espressoVersion
    androidTestImplementation 'androidx.test.espresso:espresso-intents:'+rootProject.espressoVersion



    // test
    testImplementation 'androidx.test:core:' + rootProject.coreVersion;
    testImplementation 'androidx.test.ext:junit:' + rootProject.extJUnitVersion
    testImplementation 'junit:junit:4.12'
    testImplementation 'org.robolectric:robolectric:' + rootProject.robolectricVersion
    testImplementation 'androidx.test.espresso:espresso-core:' + rootProject.espressoVersion
    testImplementation 'androidx.test.espresso:espresso-intents:' + rootProject.espressoVersion
    testImplementation 'androidx.test.ext:truth:' + rootProject.extTruthVersion
    testImplementation 'org.json:json:20140107'



    debugImplementation 'androidx.fragment:fragment-testing:'+fragment_version
    apply plugin: "androidx.navigation.safeargs"
}

1 Ответ

1 голос
/ 14 марта 2020

Вот важные строки:

Dependency path 'ExamScanner:app:unspecified' --> 'androidx.test:core:1.3.0-alpha04'
Constraint path 'ExamScanner:app:unspecified' --> 'androidx.test:core:{strictly 1.2.0}' because of the following reason: debugRuntimeClasspath uses version 1.2.0
Dependency path 'ExamScanner:app:unspecified' --> 'androidx.test:core-ktx:1.3.0-alpha04' --> 'androidx.test:core:1.3.0-alpha04'
Dependency path 'ExamScanner:app:unspecified' --> 'androidx.test.ext:junit:1.1.2-alpha04' --> 'androidx.test:core:1.3.0-alpha04'
Dependency path 'ExamScanner:app:unspecified' --> 'androidx.test.espresso:espresso-intents:3.3.0-alpha04' --> 'androidx.test:core:1.3.0-alpha04'
Dependency path 'ExamScanner:app:unspecified' --> 'androidx.fragment:fragment-testing:1.2.2' --> 'androidx.test:core:1.2.0'

Давайте распакуем, что означает каждый из них. Последняя строка

Dependency path 'ExamScanner:app:unspecified' --> 'androidx.fragment:fragment-testing:1.2.2' --> 'androidx.test:core:1.2.0'

Говорит, что fragment-testing:1.2.2 зависит от androidx.test:core:1.2.0. Это имеет смысл, это библиотека тестирования.

Вторая строка -

Constraint path 'ExamScanner:app:unspecified' --> 'androidx.test:core:{strictly 1.2.0}' because of the following reason: debugRuntimeClasspath uses version 1.2.0

В которой говорится, что debugRuntimeClasspath использует androidx.test:core:1.2.0 (это то, что вытягивается fragment-testing:1.2.2 , так что это ожидаемо.)

Важной частью является то, что это {strictly 1.2.0} - вы не можете изменить версию, используемую в androidTest или test, так как это потенциально делает недействительным то, что ожидает debug .

Остальные строки указывают, что ваша rootProject.coreVersion версия 1.3.0-alpha04. Но нет версии, которая бы одновременно и {strictly 1.2.0} (ваша Constraint), и 1.3.0-alpha04 была ошибкой.

Вы можете обновить debugImplementation, добавив эти зависимости также в debugImplementation:

debugImplementation 'androidx.test:core:' + rootProject.coreVersion
debugImplementation 'androidx.test:monitor:' + rootProject.coreVersion

Это означает, что ваши версии debug и androidTesttest) будут совпадать, избегая проблемы с ограничениями.

...