Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

Tags:

android

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.

like image 823
hashTag_bibu Avatar asked May 01 '18 13:05

hashTag_bibu


People also ask

How do I use annotations on Android support?

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.

What are dependencies in android?

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.


2 Answers

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 compileSdkVersionline 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

like image 146
emadabel Avatar answered Oct 10 '22 14:10

emadabel


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.

Configurations.all block

  1. 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.

  2. 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.

like image 30
Harsh Jain Avatar answered Oct 10 '22 14:10

Harsh Jain