Month: May 2018

Resolving Dependency Conflict In Android Studio

Recently I created a new project in Android Studio. And without adding any code, I got the following build error :

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.

Debugging and researching about this issue led me to find new things which I am sharing below :

What is Dependency Management?

Any Android project is a modularized system that relies heavily on libraries, modules and other reusable functionalities. Dependency management is a technique for declaring, resolving and using dependencies required by the project in an automated fashion.

E.g. I created a new Android Project, and could see the following dependencies in my App level gradle file :

Capture1

How to use Build Scan to determine these Dependencies in your Android Project

Gradle provides “Build Scan” as a tool to visualize, navigate and analyze dependency graph of a project.

Inside your Android Project folder in windows, run the following command :

./gradlew build --scan which publishes your build scan at gradle.com

Capture1

And identifies the dependency tree and the conflict as shown below :

Capture1

The above build scan helped me identify that my project was using espresso as a dependency that uses android annotation version 27.1.1 where as the Android support library version in my app was 26.1.0 which resulted in conflict of dependency.

Resolution:

Changing the version of com.android.support:appcompat-v7 to 27.1.1, compileSDKVersion and targetSdkVersion to 27 resolved the conflict.

Capture1