I'm new to android.
I'm developing in Java.
My goal is to use FragmentScenraio in my test framework.
In the guides I've found I see I need to add:
dependencies {
def fragment_version = "1.2.2"
// ...
debugImplementation 'androidx.fragment:fragment-testing:$fragment_version'
}
to my dependecies.
I'm adding it and the project builds succefuly.
The problem is that when I'm running the app in Android Studio I'm getting
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
Can someone please tell me what is going on here?
I tried to follow this, but it didn't work either.
Thanks.
I'm adding my app/gradle.build file:
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"
}
These are the important lines:
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'
Let's unpack what each means. The last line
Dependency path 'ExamScanner:app:unspecified' --> 'androidx.fragment:fragment-testing:1.2.2' --> 'androidx.test:core:1.2.0'
Says that fragment-testing:1.2.2
depends on androidx.test:core:1.2.0
. This makes sense, it is a testing library.
The second line is
Constraint path 'ExamScanner:app:unspecified' --> 'androidx.test:core:{strictly 1.2.0}' because of the following reason: debugRuntimeClasspath uses version 1.2.0
Which says that the debugRuntimeClasspath
uses androidx.test:core:1.2.0
(that's what is pulled in by fragment-testing:1.2.2
, so that's expected).
The important part is that this is a {strictly 1.2.0}
- you can't change the version used in androidTest
or test
since this potentially invalidate what the debug
expects.
The rest of the lines indicate that your rootProject.coreVersion
version is 1.3.0-alpha04
. But there's no version that is both {strictly 1.2.0}
(your Constraint
) and 1.3.0-alpha04
, hence the error.
You can upgrade your debugImplementation
by adding those dependencies to debugImplementation
as well:
debugImplementation 'androidx.test:core:' + rootProject.coreVersion
debugImplementation 'androidx.test:monitor:' + rootProject.coreVersion
This means that your debug
and androidTest
(and test
) versions will all match, avoiding the constraint issue.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With