AndroidX.test dependency error
See original GitHub issueDescription
When adding the newest alpha releases to my project I encounter the below error, when trying to execute tests from androidTest
directory:
Cannot find a version of 'androidx.test:monitor' that satisfies the version constraints:
Dependency path 'App:app:unspecified' --> 'androidx.test:monitor:1.1.2-alpha02'
Constraint path 'App:app:unspecified' --> 'androidx.test:monitor:{strictly 1.1.1}' because of the following reason: debugRuntimeClasspath uses version 1.1.1
Dependency path 'App:app:unspecified' --> 'androidx.test:runner:1.1.2-alpha02' --> 'androidx.test:monitor:1.1.2-alpha02'
Dependency path 'App:app:unspecified' --> 'androidx.test.ext:junit-ktx:1.1.1-alpha02' --> 'androidx.test.ext:junit:1.1.1-alpha02' --> 'androidx.test:monitor:1.1.2-alpha02'
Dependency path 'App:app:unspecified' --> 'androidx.test:core-ktx:1.1.1-alpha02' --> 'androidx.test:core:1.1.1-alpha02' --> 'androidx.test:monitor:1.1.2-alpha02'
Here are the dependencies I’m using:
...
// Versions
espresso_version = '3.2.0-alpha02'
androidx_test_runner_version = '1.1.2-alpha02'
androidx_test_rules_version = '1.1.2-alpha02'
androidx_test_monitor_version = '1.1.2-alpha02'
androidx_test_orchestrator_version = '1.1.2-alpha02'
androidx_test_ext_core_version = '1.1.1-alpha02'
androidx_test_ext_junit_version = '1.1.1-alpha02'
// Dependencies
androidTestImplementation "androidx.test:runner:$androidx_test_runner_version"
androidTestImplementation "androidx.test:rules:$androidx_test_rules_version"
androidTestImplementation "androidx.test:monitor:$androidx_test_monitor_version"
androidTestImplementation "androidx.test.ext:junit-ktx:$androidx_test_ext_junit_version"
androidTestImplementation "androidx.test:core-ktx:$androidx_test_ext_core_version"
androidTestImplementation "androidx.test.espresso:espresso-core:$espresso_version"
...
Falling back on the stable versions removes the error:
espresso_version = '3.1.1'
androidx_test_runner_version = '1.1.1'
androidx_test_rules_version = '1.1.1'
androidx_test_monitor_version = '1.1.1'
androidx_test_orchestrator_version = '1.1.1'
androidx_test_ext_core_version = '1.1.0'
androidx_test_ext_junit_version = '1.1.0'
This issue was originally posted on the googlesamples project
Is your debug app pulling in another version of androidx.test:monitor?
No, not to my knowledge. Also why is this problem only present in the alpha release and not the newest stable release?
Steps to Reproduce
- Add the above mentioned dependencies
- Add a testcase to androidTest directory (look below for example)
- Execute testcase - error occurs before tests are executed
Example:
import com.example.utils.DatabaseTestRule
import com.example.utils.hasTable
import org.junit.Assert.assertTrue
import org.junit.Rule
import org.junit.Test
class MeasurementEntityTest {
@get: Rule
val databaseRule: DatabaseTestRule = DatabaseTestRule()
private val tableName = "measurements"
@Test
fun whenDatabaseCreated_shouldMeasurementTableExist() {
assertTrue("Table $tableName does not exist", databaseRule.appDatabase.hasTable(tableName))
}
}
DatabaseTestRule (if relevant):
class DatabaseTestRule : TestWatcher() {
val appDatabase = Room
.inMemoryDatabaseBuilder(
ApplicationProvider.getApplicationContext(),
AppDatabase::class.java
).build()
val measurementRepository = appDatabase.measurementRepository
override fun starting(description: Description) {
Timber.d("DatabaseTestRule initializing")
}
override fun finished(description: Description) {
appDatabase.close()
Timber.d("DatabaseTestRule tearing down")
}
}
Expected Results
The test executes
Actual Results
The following error occurs:
Cannot find a version of 'androidx.test:monitor' that satisfies the version constraints:
Dependency path 'app:app:unspecified' --> 'androidx.test:monitor:1.2.0-alpha03'
Constraint path 'app:app:unspecified' --> 'androidx.test:monitor:{strictly 1.1.1}' because of the following reason: debugRuntimeClasspath uses version 1.1.1
Dependency path 'app:app:unspecified' --> 'androidx.test:runner:1.2.0-alpha03' --> 'androidx.test:monitor:1.2.0-alpha03'
Dependency path 'app:app:unspecified' --> 'androidx.test.ext:junit-ktx:1.1.1-alpha03' --> 'androidx.test.ext:junit:1.1.1-alpha03' --> 'androidx.test:monitor:1.2.0-alpha03'
Dependency path 'app:app:unspecified' --> 'androidx.test:core-ktx:1.2.0-alpha03' --> 'androidx.test:core:1.2.0-alpha03' --> 'androidx.test:monitor:1.2.0-alpha03'
AndroidX Test and Android OS Versions
espresso_version = '3.2.0-alpha02'
androidx_test_runner_version = '1.1.2-alpha02'
androidx_test_rules_version = '1.1.2-alpha02'
androidx_test_monitor_version = '1.1.2-alpha02'
androidx_test_orchestrator_version = '1.1.2-alpha02'
androidx_test_ext_core_version = '1.1.1-alpha02'
androidx_test_ext_junit_version = '1.1.1-alpha02'
Btw. It’s the same with newest alpha03 release
Emulator running:
Name: 7_WSVGA_Tablet_API_25
CPU/ABI: Google APIs Intel Atom (x86)
Path: /Users/tbs/.android/avd/7_WSVGA_Tablet_API_25.avd
Target: google_apis [Google APIs] (API level 25)
Skin: 600x1024
SD Card: 100 MB
fastboot.chosenSnapshotFile:
runtime.network.speed: full
hw.accelerometer: yes
hw.device.name: 7in WSVGA (Tablet)
hw.lcd.width: 1024
hw.initialOrientation: Portrait
image.androidVersion.api: 25
tag.id: google_apis
hw.mainKeys: no
hw.camera.front: emulated
avd.ini.displayname: 7 WSVGA (Tablet) API 25
hw.gpu.mode: auto
hw.ramSize: 512
PlayStore.enabled: false
fastboot.forceColdBoot: no
hw.cpu.ncore: 2
hw.keyboard: yes
hw.sensors.proximity: yes
hw.dPad: no
hw.lcd.height: 600
vm.heapSize: 48
skin.dynamic: yes
hw.device.manufacturer: Generic
hw.gps: yes
skin.path.backup: _no_skin
hw.audioInput: yes
image.sysdir.1: system-images/android-25/google_apis/x86/
showDeviceFrame: no
hw.camera.back: emulated
AvdId: 7_WSVGA_Tablet_API_25
hw.lcd.density: 160
hw.arc: false
hw.device.hash2: MD5:886bf70516706f933c01ecec92c4cad1
fastboot.forceChosenSnapshotBoot: no
fastboot.forceFastBoot: yes
hw.trackBall: no
hw.battery: yes
hw.sdCard: yes
tag.display: Google APIs
runtime.network.latency: none
disk.dataPartition.size: 800M
hw.sensors.orientation: yes
avd.ini.encoding: UTF-8
hw.gpu.enabled: yes
Link to a public git repo demonstrating the problem:
NA
Issue Analytics
- State:
- Created 4 years ago
- Comments:13 (3 by maintainers)
Top Results From Across the Web
Unable to resolve dependency androidx.test:core:1.9.0-alpha01
Try changing this: test_version = '1.9.0-alpha01'. To this: test_version = '1.4.1-alpha04'. (I think the version you declared doesn't exist: ...
Read more >Set up project for AndroidX Test - Android Developers
In order to use AndroidX Test, you must modify your app project's dependencies within your development environment.
Read more >Adding dependency androidx.appcompat ... - Issue Tracker
Adding dependency androidx.appcompat:appcompat:1.6.0-alpha03 to Jetpack Compose project results in duplicate class error.
Read more >Easy Instrumented Tests (UI Tests) for Android in 2021
In the android.defaultConfig block add the testInstrumentationRunner for be able to “launch” our tests, in the case you use a custom application class...
Read more >testCompile with aar dependency - Google Groups
When testing with Robolectric, I am getting a NoClassDefFound error for an aar dependency ... compile('com.crashlytics.sdk.android:crashlytics:2.5.2@aar') {
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Found and easy an convenient solution:
Just found the cause. It’s this dependency:
Removing it removes the error.