Android dependency management.

This post is basically about to understand dependency management for android multiple libraries/modules. If you are developing a big android project you may have many different libraries /modules included in your project. When you compiling your project , you need to verify all modules in same versions. for example , if your main app module have following lines :

compileSdkVersion 25
buildToolsVersion "25.0.2"
compile 'com.google.android.gms:play-services:9.0.2'
compile 'com.android.support:support-v4:25.0.1'
compile 'com.android.support:appcompat-v7:25.0.1'

You need to have same versions same as compileSdkVersion

If you have any other modules which have same type of dependencies, for example , Let’s assume you have following dependencies for a module named testModule.

compileSdkVersion 23
buildToolsVersion "25.0.2"
compile 'com.google.android.gms:play-services:9.0.2'
compile 'com.android.support:support-v4:23.0.0'
compile 'com.android.support:appcompat-v7:23.0.3'

You can’t have this kind of modules with different versions . You need to change all module versions to same version (into 25.0.1).

You can change versions if you have modules. But what happens if you have included a library which also uses above dependencies. So that , you can’t directly see those dependencies easily. You may think all libraries in same version. You can debug apps. But problem occur when you are going to release your .apk file. If you have this kind of situation, you will get an error similar to following.

Execution failed for task ‘:app:transformClassesWithJarMergingForDebug’

duplicate entry error ( Execution failed for task ‘:app:transformClassesWithJarMergingForDebug’ )

Now if you read the error carefully you can see it says duplicate entry for android/support …. Which means there is another version of same module. Now how you are going to check these dependencies ? You can easily view the dependency tree by typing following command in your terminal.

./gradlew -q dependencies app:dependencies — configuration compile

Then you will get a dependency tree similar to following

compile - Classpath for compiling the main sources.
+--- com.android.support:multidex:1.0.1
+--- com.google.android.gms:play-services:9.0.2
| +--- com.google.android.gms:play-services-ads:9.0.2
| | +--- com.google.android.gms:play-services-ads-lite:9.0.2
| | | \--- com.google.android.gms:play-services-basement:9.0.2
| | | \--- com.android.support:support-v4:23.0.0 -> 25.1.0
| | | +--- com.android.support:support-compat:25.1.0
| | | | \--- com.android.support:support-annotations:25.1.0
| | | +--- com.android.support:support-media-compat:25.1.0
| | | | +--- com.android.support:support-annotations:25.1.0
| | | | \--- com.android.support:support-compat:25.1.0 (*)
| | | +--- com.android.support:support-core-utils:25.1.0
| | | | +--- com.android.support:support-annotations:25.1.0
| | | | \--- com.android.support:support-compat:25.1.0 (*)
| | | +--- com.android.support:support-core-ui:25.1.0
| | | | +--- com.android.support:support-annotations:25.1.0
| | | | \--- com.android.support:support-compat:25.1.0 (*)
| | | \--- com.android.support:support-fragment:25.1.0
| | | +--- com.android.support:support-compat:25.1.0 (*)
| | | +--- com.android.support:support-media-compat:25.1.0 (*)
| | | +--- com.android.support:support-core-ui:25.1.0 (*)
| | | \--- com.android.support:support-core-utils:25.1.0 (*)
| | +--- com.google.android.gms:play-services-base:9.0.2
| | | +--- com.google.android.gms:play-services-basement:9.0.2 (*)
| | | +--- com.google.firebase:firebase-common:9.0.2
| | | | +--- com.google.android.gms:play-services-basement:9.0.2 (*)
| | | | \--- com.google.android.gms:play-services-tasks:9.0.2
| | | | \--- com.google.android.gms:play-services-basement:9.0.2 (*)
| | | \--- com.google.android.gms:play-services-tasks:9.0.2 (*)
| | \--- com.google.android.gms:play-services-basement:9.0.2 (*)
| +--- com.google.android.gms:play-services-ads-lite:9.0.2 (*)
| +--- com.google.android.gms:play-services-analytics:9.0.2
| | +--- com.google.android.gms:play-services-analytics-impl:9.0.2
| | | +--- com.google.android.gms:play-services-base:9.0.2 (*)
| | | \--- com.google.android.gms:play-services-basement:9.0.2 (*)
| | +--- com.google.android.gms:play-services-base:9.0.2 (*)
| | \--- com.google.android.gms:play-services-basement:9.0.2 (*)
| +--- com.google.android.gms:play-services-analytics-impl:9.0.2 (*)
| +--- com.google.android.gms:play-services-appinvite:9.0.2
| | +--- com.google.android.gms:play-services-base:9.0.2 (*)
| | \--- com.google.android.gms:play-services-basement:9.0.2 (*)
| +--- com.google.android.gms:play-services-auth:9.0.2
| | +--- com.google.android.gms:play-services-auth-base:9.0.2
| | | +--- com.google.android.gms:play-services-base:9.0.2 (*)
| | | \--- com.google.android.gms:play-services-basement:9.0.2 (*)
| | +--- com.google.android.gms:play-services-base:9.0.2 (*)
| | \--- com.google.android.gms:play-services-basement:9.0.2 (*)
| +--- com.google.android.gms:play-services-auth-base:9.0.2 (*)
| +--- com.google.android.gms:play-services-base:9.0.2 (*)
| +--- com.google.android.gms:play-services-cast:9.0.2
| | +--- com.google.android.gms:play-services-base:9.0.2 (*)
| | +--- com.google.android.gms:play-services-basement:9.0.2 (*)
| | \--- com.android.support:mediarouter-v7:23.0.0
| | \--- com.android.support:appcompat-v7:23.0.0 -> 25.1.0
| | +--- com.android.support:support-annotations:25.1.0
| | +--- com.android.support:support-v4:25.1.0 (*)
| | +--- com.android.support:support-vector-drawable:25.1.0
| | | +--- com.android.support:support-annotations:25.1.0
| | | \--- com.android.support:support-compat:25.1.0 (*)
| | \--- com.android.support:animated-vector-drawable:25.1.0
| | \--- com.android.support:support-vector-drawable:25.1.0 (*)
| +--- com.google.android.gms:play-services-basement:9.0.2 (*)
| +--- com.google.firebase:firebase-config:9.0.2
| | +--- com.google.android.gms:play-services-base:9.0.2 (*)
| | +--- com.google.android.gms:play-services-basement:9.0.2 (*)
| | +--- com.google.firebase:firebase-iid:9.0.2
| | | +--- com.google.android.gms:play-services-basement:9.0.2 (*)
| | | \--- com.google.firebase:firebase-common:9.0.2 (*)
| | +--- com.google.firebase:firebase-common:9.0.2 (*)
| | \--- com.google.android.gms:play-services-tasks:9.0.2 (*)
| +--- com.google.firebase:firebase-crash:9.0.2
| | +--- com.google.android.gms:play-services-base:9.0.2 (*)
| | +--- com.google.android.gms:play-services-basement:9.0.2 (*)
| | +--- com.google.firebase:firebase-iid:9.0.2 (*)
| | +--- com.google.firebase:firebase-common:9.0.2 (*)
| | \--- com.google.firebase:firebase-analytics:9.0.2
| | +--- com.google.android.gms:play-services-basement:9.0.2 (*)
| | +--- com.google.firebase:firebase-common:9.0.2 (*)
| | \--- com.google.firebase:firebase-analytics-impl:9.0.2
| | +--- com.google.android.gms:play-services-base:9.0.2 (*)
| | +--- com.google.android.gms:play-services-basement:9.0.2 (*)
| | +--- com.google.firebase:firebase-iid:9.0.2 (*)
| | \--- com.google.firebase:firebase-common:9.0.2 (*)
| +--- com.google.android.gms:play-services-drive:9.0.2
| | +--- com.google.android.gms:play-services-base:9.0.2 (*)
| | \--- com.google.android.gms:play-services-basement:9.0.2 (*)
| +--- com.google.firebase:firebase-auth:9.0.2
| | +--- com.google.android.gms:play-services-base:9.0.2 (*)
| | +--- com.google.android.gms:play-services-basement:9.0.2 (*)
| | +--- com.google.firebase:firebase-auth-common:9.0.2
| | | +--- com.google.android.gms:play-services-base:9.0.2 (*)
| | | +--- com.google.android.gms:play-services-basement:9.0.2 (*)
| | | +--- com.google.firebase:firebase-auth-module:9.0.2
| | | | +--- com.google.android.gms:play-services-base:9.0.2 (*)
| | | | \--- com.google.android.gms:play-services-basement:9.0.2 (*)
| | | \--- com.google.firebase:firebase-common:9.0.2 (*)
| | +--- com.google.firebase:firebase-auth-module:9.0.2 (*)
| | +--- com.google.firebase:firebase-common:9.0.2 (*)
| | \--- com.google.android.gms:play-services-tasks:9.0.2 (*)
| +--- com.google.firebase:firebase-auth-common:9.0.2 (*)
| +--- com.google.firebase:firebase-auth-module:9.0.2 (*)
| +--- com.google.firebase:firebase-database-connection:9.0.2
| | +--- com.google.android.gms:play-services-base:9.0.2 (*)
| | +--- com.google.android.gms:play-services-basement:9.0.2 (*)
| | \--- com.google.firebase:firebase-common:9.0.2 (*)
| +--- com.google.firebase:firebase-database:9.0.2
| | +--- com.google.android.gms:play-services-base:9.0.2 (*)
| | +--- com.google.android.gms:play-services-basement:9.0.2 (*)
| | +--- com.google.firebase:firebase-database-connection:9.0.2 (*)
| | +--- com.google.firebase:firebase-common:9.0.2 (*)
| | \--- com.google.android.gms:play-services-tasks:9.0.2 (*)
| +--- com.google.firebase:firebase-iid:9.0.2 (*)
| +--- com.google.firebase:firebase-messaging:9.0.2
| | +--- com.google.android.gms:play-services-basement:9.0.2 (*)
| | +--- com.google.firebase:firebase-iid:9.0.2 (*)
| | \--- com.google.firebase:firebase-common:9.0.2 (*)
| +--- com.google.firebase:firebase-storage:9.0.2
| | +--- com.google.android.gms:play-services-base:9.0.2 (*)
| | +--- com.google.android.gms:play-services-basement:9.0.2 (*)
| | +--- com.google.firebase:firebase-storage-common:9.0.2
| | | +--- com.google.android.gms:play-services-base:9.0.2 (*)
| | | \--- com.google.android.gms:play-services-basement:9.0.2 (*)
| | +--- com.google.firebase:firebase-common:9.0.2 (*)
| | \--- com.google.android.gms:play-services-tasks:9.0.2 (*)
| +--- com.google.firebase:firebase-storage-common:9.0.2 (*)
| +--- com.google.firebase:firebase-common:9.0.2 (*)
| +--- com.google.android.gms:play-services-fitness:9.0.2
| | +--- com.google.android.gms:play-services-base:9.0.2 (*)
| | +--- com.google.android.gms:play-services-basement:9.0.2 (*)
| | \--- com.google.android.gms:play-services-location:9.0.2
| | +--- com.google.android.gms:play-services-base:9.0.2 (*)
| | +--- com.google.android.gms:play-services-basement:9.0.2 (*)
| | \--- com.google.android.gms:play-services-maps:9.0.2
| | +--- com.google.android.gms:play-services-base:9.0.2 (*)
| | \--- com.google.android.gms:play-services-basement:9.0.2 (*)
| +--- com.google.android.gms:play-services-games:9.0.2
| | +--- com.google.android.gms:play-services-auth-base:9.0.2 (*)
| | +--- com.google.android.gms:play-services-base:9.0.2 (*)
| | +--- com.google.android.gms:play-services-basement:9.0.2 (*)
| | \--- com.google.android.gms:play-services-drive:9.0.2 (*)
| +--- com.google.android.gms:play-services-gcm:9.0.2
| | +--- com.google.android.gms:play-services-base:9.0.2 (*)
| | +--- com.google.android.gms:play-services-basement:9.0.2 (*)
| | \--- com.google.android.gms:play-services-iid:9.0.2
| | +--- com.google.android.gms:play-services-base:9.0.2 (*)
| | \--- com.google.android.gms:play-services-basement:9.0.2 (*)
| +--- com.google.android.gms:play-services-appindexing:9.0.2
| | +--- com.google.android.gms:play-services-base:9.0.2 (*)
| | +--- com.google.android.gms:play-services-basement:9.0.2 (*)
| | +--- com.google.firebase:firebase-common:9.0.2 (*)
| | \--- com.google.android.gms:play-services-tasks:9.0.2 (*)
| +--- com.google.android.gms:play-services-identity:9.0.2
| | +--- com.google.android.gms:play-services-base:9.0.2 (*)
| | \--- com.google.android.gms:play-services-basement:9.0.2 (*)
| +--- com.google.android.gms:play-services-iid:9.0.2 (*)
| +--- com.google.android.gms:play-services-location:9.0.2 (*)
| +--- com.google.android.gms:play-services-maps:9.0.2 (*)
| +--- com.google.firebase:firebase-analytics:9.0.2 (*)
| +--- com.google.firebase:firebase-analytics-impl:9.0.2 (*)
| +--- com.google.android.gms:play-services-nearby:9.0.2
| | +--- com.google.android.gms:play-services-base:9.0.2 (*)
| | \--- com.google.android.gms:play-services-basement:9.0.2 (*)
| +--- com.google.android.gms:play-services-panorama:9.0.2
| | +--- com.google.android.gms:play-services-base:9.0.2 (*)
| | \--- com.google.android.gms:play-services-basement:9.0.2 (*)
| +--- com.google.android.gms:play-services-plus:9.0.2
| | +--- com.google.android.gms:play-services-auth-base:9.0.2 (*)
| | +--- com.google.android.gms:play-services-base:9.0.2 (*)
| | \--- com.google.android.gms:play-services-basement:9.0.2 (*)
| +--- com.google.android.gms:play-services-safetynet:9.0.2
| | +--- com.google.android.gms:play-services-base:9.0.2 (*)
| | \--- com.google.android.gms:play-services-basement:9.0.2 (*)
| +--- com.google.android.gms:play-services-tagmanager-api:9.0.2
| | +--- com.google.android.gms:play-services-basement:9.0.2 (*)
| | \--- com.google.firebase:firebase-analytics:9.0.2 (*)
| +--- com.google.android.gms:play-services-tagmanager:9.0.2
| | +--- com.google.android.gms:play-services-analytics-impl:9.0.2 (*)
| | +--- com.google.android.gms:play-services-basement:9.0.2 (*)
| | \--- com.google.android.gms:play-services-tagmanager-api:9.0.2 (*)
| +--- com.google.android.gms:play-services-tasks:9.0.2 (*)
| +--- com.google.android.gms:play-services-vision:9.0.2
| | +--- com.google.android.gms:play-services-base:9.0.2 (*)
| | \--- com.google.android.gms:play-services-basement:9.0.2 (*)
| +--- com.google.android.gms:play-services-wallet:9.0.2
| | +--- com.google.android.gms:play-services-base:9.0.2 (*)
| | +--- com.google.android.gms:play-services-basement:9.0.2 (*)
| | +--- com.google.android.gms:play-services-identity:9.0.2 (*)
| | \--- com.google.android.gms:play-services-maps:9.0.2 (*)
| \--- com.google.android.gms:play-services-wearable:9.0.2
| +--- com.google.android.gms:play-services-base:9.0.2 (*)
| \--- com.google.android.gms:play-services-basement:9.0.2 (*)
+--- com.android.support:support-v4:25.1.0 (*)
+--- project :CircularImageView_Client
+--- project :facebookSDK
| \--- com.android.support:appcompat-v7:25.1.0 (*)
+--- project :library_pinnlistivew
+--- project :cropLibrary
+--- project :stripeLibrary
+--- project :library-2.4.1
+--- com.github.erd:android-volley:1.0.0
+--- com.interswitchng:payment-android:1.0.0
| +--- com.android.support:appcompat-v7:25.1.0 (*)
| +--- com.android.support:design:25.1.0
| | +--- com.android.support:support-v4:25.1.0 (*)
| | +--- com.android.support:appcompat-v7:25.1.0 (*)
| | +--- com.android.support:recyclerview-v7:25.1.0
| | | +--- com.android.support:support-annotations:25.1.0
| | | +--- com.android.support:support-compat:25.1.0 (*)
| | | \--- com.android.support:support-core-ui:25.1.0 (*)
| | \--- com.android.support:transition:25.1.0
| | +--- com.android.support:support-annotations:25.1.0
| | \--- com.android.support:support-v4:25.1.0 (*)
| +--- com.interswitchng:isw-payment:0.0.6
| | \--- com.interswitchng:isw-core:0.0.6
| | \--- com.google.code.gson:gson:2.4
| \--- com.interswitchng:isw-core:0.0.6 (*)
\--- project :deviceprint-release-2.2.0

I have a .jar library file for com.interswitchng:payment-android:1.0.0 . You can see that library already acquired recyclerview-v7:25.1.0. As well as i have added anotherrecyclerview-v7:23.0.0 library file with different version separately into my project. That is why i get this duplicate entry error. Now you have to resolve this. You can use same version .jar file here to solve it. Sometime even you resolved it you will get the same error. Its because your files may cached in your project. For that you can invalidate project cache.

in order to invalidate project cache, Select from you android studio

File -> Invalidate caches/Restart

Now you are done. Happy Coding