gpt4 book ai didi

java - 无法使用 `debugImplementation ' androidx.fragment :fragment-testing :'+fragment_version` as a dependency 运行应用程序

转载 作者:行者123 更新时间:2023-12-03 21:58:59 27 4
gpt4 key购买 nike

我是安卓新手。

我正在用 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"
}

最佳答案

这些是重要的行:

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

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

关于java - 无法使用 `debugImplementation ' androidx.fragment :fragment-testing :'+fragment_version` as a dependency 运行应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60675204/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com