无法以`debugImplementation'androidx.fragment:fragment-testing:'+ fragment_version`作为依赖项运行应用程序

问题描述 投票:0回答:1

我是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

有人可以告诉我这是怎么回事吗?

我曾尝试遵循this,但它也不起作用。

谢谢。

我正在添加我的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"
}

java android android-studio build.gradle android-espresso
1个回答
0
投票

这些是重要的行:

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}-您无法更改androidTesttest中使用的版本,因为这可能会使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

这意味着您的debugandroidTest(以及test)版本将全部匹配,从而避免了约束问题。

© www.soinside.com 2019 - 2024. All rights reserved.