A. Cedano
A. Cedano

Reputation: 965

How to resolve the error "Could not resolve androidx.test:runner:1.6.2"

When I execute this command in terminal:

./gradlew clean and build --scan

The build fails with this error:

> Could not resolve all artifacts for configuration
> ':app:debugAndroidTestRuntimeClasspath'.
> > Could not resolve androidx.test:runner:1.6.2.   Required by:
>       project :app
>   > Cannot find a version of 'androidx.test:runner' that satisfies the version constraints:
>        Dependency path 'LiturgiaPlusAndroid:app:unspecified' --> 'androidx.test:runner:1.6.2'
>        Constraint path 'LiturgiaPlusAndroid:app:unspecified' --> 'androidx.test:runner:{strictly 1.6.1}' because of the following
> reason: version resolved in configuration ':app:debugRuntimeClasspath'
> by consistent resolution
>        Dependency path 'LiturgiaPlusAndroid:app:unspecified' --> 'androidx.compose.ui:ui-test-junit4:1.7.8'
> (releaseRuntimeElements-published) -->
> 'androidx.compose.ui:ui-test-junit4-android:1.7.8'
> (releaseRuntimeElements-published) -->
> 'androidx.compose.ui:ui-test:1.7.8' (releaseRuntimeElements-published)
> --> 'androidx.compose.ui:ui-test-android:1.7.8' (releaseRuntimeElements-published) -->
> 'androidx.test.espresso:espresso-core:3.6.1' (runtime) -->
> 'androidx.test:runner:1.6.1'
> > Could not resolve androidx.test:runner:{strictly 1.6.1}.   Required by:
>       project :app
>   > Cannot find a version of 'androidx.test:runner' that satisfies the version constraints:
>        Dependency path 'LiturgiaPlusAndroid:app:unspecified' --> 'androidx.test:runner:1.6.2'
>        Constraint path 'LiturgiaPlusAndroid:app:unspecified' --> 'androidx.test:runner:{strictly 1.6.1}' because of the following
> reason: version resolved in configuration ':app:debugRuntimeClasspath'
> by consistent resolution
>        Dependency path 'LiturgiaPlusAndroid:app:unspecified' --> 'androidx.compose.ui:ui-test-junit4:1.7.8'
> (releaseRuntimeElements-published) -->
> 'androidx.compose.ui:ui-test-junit4-android:1.7.8'
> (releaseRuntimeElements-published) -->
> 'androidx.compose.ui:ui-test:1.7.8' (releaseRuntimeElements-published)
> --> 'androidx.compose.ui:ui-test-android:1.7.8' (releaseRuntimeElements-published) -->
> 'androidx.test.espresso:espresso-core:3.6.1' (runtime) -->
> 'androidx.test:runner:1.6.1'
> > Could not resolve androidx.test:runner:1.6.1.   Required by:
>       project :app > androidx.test.espresso:espresso-core:3.6.1
>   > Cannot find a version of 'androidx.test:runner' that satisfies the version constraints:
>        Dependency path 'LiturgiaPlusAndroid:app:unspecified' --> 'androidx.test:runner:1.6.2'
>        Constraint path 'LiturgiaPlusAndroid:app:unspecified' --> 'androidx.test:runner:{strictly 1.6.1}' because of the following
> reason: version resolved in configuration ':app:debugRuntimeClasspath'
> by consistent resolution
>        Dependency path 'LiturgiaPlusAndroid:app:unspecified' --> 'androidx.compose.ui:ui-test-junit4:1.7.8'
> (releaseRuntimeElements-published) -->
> 'androidx.compose.ui:ui-test-junit4-android:1.7.8'
> (releaseRuntimeElements-published) -->
> 'androidx.compose.ui:ui-test:1.7.8' (releaseRuntimeElements-published)
> --> 'androidx.compose.ui:ui-test-android:1.7.8' (releaseRuntimeElements-published) -->
> 'androidx.test.espresso:espresso-core:3.6.1' (runtime) -->
> 'androidx.test:runner:1.6.1'

I don't know what is causing this error.

I don't understand why it refers to androidx.test:runner:1.6.1 if at app/build.gradle I am implementing:

androidTestImplementation 'androidx.test:runner:1.6.2'

I have verified that all dependency versions are up to date and that there are no version differences between related dependencies.

Upvotes: 0

Views: 68

Answers (1)

Jay Dedaniya
Jay Dedaniya

Reputation: 41

The error occurs because there is a version conflict between androidx.test:runner:1.6.2 and androidx.test:runner:1.6.1. The build system cannot find a version that satisfies all dependencies.


- Steps to Fix the Issue

Check Your Dependencies

In your build.gradle (Module: app), check for any androidx.test:runner dependency. If you find multiple versions, update them to the same latest stable version

  • androidTestImplementation 'androidx.test:runner:1.5.2'

Force a Specific Version (Recommended)

If some dependencies internally use an older version, force them to use 1.5.2

dependencies {
    androidTestImplementation 'androidx.test:runner:1.5.2'
    constraints {
        implementation('androidx.test:runner:1.5.2') {
            because 'Fixes version conflicts'
        }
    }
}

Use Dependency Resolution Strategy

You can enforce a specific version using resolutionStrategy in your build.gradle (app):

configurations.all {
    resolutionStrategy {
        force 'androidx.test:runner:1.5.2'
    }
}

This ensures all dependencies use 1.5.2, preventing version conflicts.


Refresh Gradle & Invalidate Cache

  1. Delete gradle cache:
  • Close Android Studio
  • Delete .gradle and .idea folders in your project
  • Restart Android Studio
  • Click File > Invalidate Caches & Restart
  1. Force Gradle to Update Dependencies:
./gradlew clean --refresh-dependencies

Run

./gradlew clean build --scan

Why Use 1.5.2 Instead of 1.6.2?

  • java androidx.test:runner:1.6.2 does not exist in Google's Maven Repository.
  • The latest stable version is 1.5.2, which is compatible with Espresso 3.6.1.

Upvotes: 0

Related Questions