Fix Conflict With Dependency Error When Creating Android Project

When you create a new android project in android studio, you may encounter error message like below.

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.

ErrorExecution failed for task 'apppreDebugAndroidTestBuild' dependency conflict

This error message confused me and waste me a lot of time. But it is really easy to fix if you follow below instructions.

  1. Double click the project build.gradle file in left panel.
  2. Change the dependency library version from v7:26.1.0 to v7:27.1.1 as the error message said. Then save the build.gradle file.
    change dependency version in build.gradle file
  3. Now click Build —> Rebuild Project menu item in android studio top menu bar, the error disappear.

If you do not fix this error, you can not use the layout xml designer. You can only edit layout xml in text.

4 thoughts on “Fix Conflict With Dependency Error When Creating Android Project”

  1. You are Great. I was trying to fix this from the past 3 days but i was failed everytime. But this simple trick works. Thank You

  2. Hi, what is your compileSdkVersion?
    After doing what you said, I get this error :
    ” The support library should not use a different version (27) than the compileSdkVersion (26) ”
    But I see on your example that your targetSdkVersion is 26 so I guess your compileSdkVersion is 26 as well ?

    1. Same Errorr Show in my Gradle File Compliesdkversion show 27 and compile version ‘com.android.support:appcompat-v7:27.+’ but when i rebuild my project then its show error how i can resolve plz anyone tell me and testCompile ‘junit:junit:4.12’ its show error how its resolve plz say

Leave a Comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.