【Android exception】Conflict with dependency 'com.android.support:support-annotations'

The exception reported when compiling and running the Android project:

Error:Execution failed for task ‘:app:preDebugAndroidTestBuild’.
Conflict with dependency ‘com.android.support:support-annotations’ in project ‘:app’. Resolved versions for app (26.1.0) and test app (27.1.1) differ. See https://d.android.com/r/tools/test-apk-dependency-conflicts.html for details.

It means that com.android.support:support-annotationsthe test version about the library is not the same as the final running version.
Solution: Add force to the dependencies of the build.gradle file to force the version number of the specified library, so that the test version and the running version are consistent. as follows:

dependencies{
    configurations.all {
        resolutionStrategy.force 'com.android.support:support-annotations:27.1.1'
    }
}

References:
1. "Problems after Android studio is updated to 2.2"
2. "Official Website - Test Application"

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325771880&siteId=291194637