I am new to Android App Development. When I tried to create a new project,Android Project...the following message popped up..
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. Information:Gradle tasks [:app:generateDebugSources, :app:generateDebugAndroidTestSources, :app:mockableAndroidJar]
This is the screenshot of my project click here to see screenshot of the error i got
i also tried adding this code to my dependency.. androidTestCompile 'com.android.support:support-annotations:23.3.0' this didn't work out. I also tried 27.1.1 and 26.1.0.. that didn't work out either.
To enable annotations in your project, add the support-annotations dependency to your library or app. Any annotations you add then get checked when you run a code inspection or lint task.
In Android Studio, dependencies allows us to include external library or local jar files or other library modules in our Android project. For example: Suppose I want to show some images in ImageView. But I'm using Glide Library to enhance the smoothness of application.
Based on your screenshot i found two working solutions:
First solution: add to dependencies of your gradle module this line
compile 'com.android.support:support-annotations:27.1.1'
and sync your project
Note: if you are using Android studio 3+ change compile
to implementation
Second solution: Configure project-wide properties found in the documentation https://developer.android.com/studio/build/gradle-tips.html#configure-project-wide-properties
in project gradle add this line:
// This block encapsulates custom properties and makes them available to all // modules in the project. ext { // The following are only a few examples of the types of properties you can define. compileSdkVersion = 26 // You can also use this to specify versions for dependencies. Having consistent // versions between modules can avoid behavior conflicts. supportLibVersion = "27.1.1" }
Then to access this section change compileSdkVersion
line to be
compileSdkVersion rootProject.ext.compileSdkVersion
and at dependencies
section change the imported library to be like this:
compile "com.android.support:appcompat-v7:${rootProject.ext.supportLibVersion}"
and sync your project
Note: if you are using Android studio 3+ change compile
to implementation
For the difference between compile
and implementation
look at this What's the difference between implementation and compile in gradle
Add the below line in your app.gradle file before depencencies block.
configurations.all { resolutionStrategy { force 'com.android.support:support-annotations:26.1.0' } }
There's also screenshot below for a better understanding.
the configurations.all block will only be helpful if you want your target sdk to be 26. If you can change it to 27 the error will be gone without adding the configuration block in app.gradle file.
There is one more way if you would remove all the test implementation from app.gradle file it would resolve the error and in this also you dont need to add the configuration block nor you need to change the targetsdk version.
Hope that helps.
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