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.

READ :   How To Write Reusable Code For Android SQLite Database

6 Comments


  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

    Reply

  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 ?

    Reply

    1. Yes, my environment compileSdkVersion is 26 also.

      compileSdkVersion 26

      Reply

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

      Reply

  3. I have the same issue when i build my app on ionic and i don’t know what to do if make a changue on configuraciĆ³n.xml or build.gradle

    Reply

Leave a Reply

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.