Error occurs only when I'm trying to take release or debug apk of my app. I can run or debug it on my device straight from Android Studio. From this question, I understood that this might be due to duplicate dependencies. So I tried to check whether there are any duplicate dependencies by running:
./gradlew -q :app:dependencies
I got the following dependency tree:
_releaseApk - ## Internal use, do not manually configure ##
+--- com.android.support:appcompat-v7:25.3.1
| +--- com.android.support:support-annotations:25.3.1
| +--- com.android.support:support-v4:25.3.1
| | +--- com.android.support:support-compat:25.3.1
| | | \--- com.android.support:support-annotations:25.3.1
| | +--- com.android.support:support-media-compat:25.3.1
| | | +--- com.android.support:support-annotations:25.3.1
| | | \--- com.android.support:support-compat:25.3.1 (*)
| | +--- com.android.support:support-core-utils:25.3.1
| | | +--- com.android.support:support-annotations:25.3.1
| | | \--- com.android.support:support-compat:25.3.1 (*)
| | +--- com.android.support:support-core-ui:25.3.1
| | | +--- com.android.support:support-annotations:25.3.1
| | | \--- com.android.support:support-compat:25.3.1 (*)
| | \--- com.android.support:support-fragment:25.3.1
| | +--- com.android.support:support-compat:25.3.1 (*)
| | +--- com.android.support:support-media-compat:25.3.1 (*)
| | +--- com.android.support:support-core-ui:25.3.1 (*)
| | \--- com.android.support:support-core-utils:25.3.1 (*)
| +--- com.android.support:support-vector-drawable:25.3.1
| | +--- com.android.support:support-annotations:25.3.1
| | \--- com.android.support:support-compat:25.3.1 (*)
| \--- com.android.support:animated-vector-drawable:25.3.1
| \--- com.android.support:support-vector-drawable:25.3.1 (*)
+--- com.android.support:cardview-v7:25.3.1
| \--- com.android.support:support-annotations:25.3.1
+--- com.android.support:recyclerview-v7:25.3.1
| +--- com.android.support:support-annotations:25.3.1
| +--- com.android.support:support-compat:25.3.1 (*)
| \--- com.android.support:support-core-ui:25.3.1 (*)
+--- com.android.support:design:25.3.1
| +--- com.android.support:support-v4:25.3.1 (*)
| +--- com.android.support:appcompat-v7:25.3.1 (*)
| +--- com.android.support:recyclerview-v7:25.3.1 (*)
| \--- com.android.support:transition:25.3.1
| +--- com.android.support:support-annotations:25.3.1
| \--- com.android.support:support-v4:25.3.1 (*)
+--- pl.droidsonroids.gif:android-gif-drawable:1.2.7
+--- com.google.android.gms:play-services-ads:10.2.6
| +--- com.google.android.gms:play-services-ads-lite:10.2.6
| | \--- com.google.android.gms:play-services-basement:10.2.6
| | \--- com.android.support:support-v4:25.2.0 -> 25.3.1 (*)
| +--- com.google.android.gms:play-services-base:10.2.6
| | +--- com.google.android.gms:play-services-basement:10.2.6 (*)
| | \--- com.google.android.gms:play-services-tasks:10.2.6
| | \--- com.google.android.gms:play-services-basement:10.2.6 (*)
| +--- com.google.android.gms:play-services-clearcut:10.2.6
| | +--- com.google.android.gms:play-services-base:10.2.6 (*)
| | \--- com.google.android.gms:play-services-basement:10.2.6 (*)
| +--- com.google.android.gms:play-services-basement:10.2.6 (*)
| \--- com.google.android.gms:play-services-gass:10.2.6
| \--- com.google.android.gms:play-services-basement:10.2.6 (*)
+--- com.google.android.gms:play-services-location:10.2.6
| +--- com.google.android.gms:play-services-base:10.2.6 (*)
| +--- com.google.android.gms:play-services-basement:10.2.6 (*)
| \--- com.google.android.gms:play-services-tasks:10.2.6 (*)
\--- com.google.firebase:firebase-core:10.2.6
\--- com.google.firebase:firebase-analytics:10.2.6
+--- com.google.firebase:firebase-analytics-impl:10.2.6
| +--- com.google.android.gms:play-services-basement:10.2.6 (*)
| +--- com.google.firebase:firebase-iid:10.2.6
| | +--- com.google.android.gms:play-services-basement:10.2.6 (*)
| | \--- com.google.firebase:firebase-common:10.2.6
| | +--- com.google.android.gms:play-services-basement:10.2.6 (*)
| | \--- com.google.android.gms:play-services-tasks:10.2.6 (*)
| +--- com.google.firebase:firebase-common:10.2.6 (*)
| \--- com.google.android.gms:play-services-tasks:10.2.6 (*)
+--- com.google.android.gms:play-services-basement:10.2.6 (*)
\--- com.google.firebase:firebase-common:10.2.6 (*)
How to deduce which are the duplicate dependencies in my project from this tree? Are they the ones that end in asterisk?
Edit: My Gradle File is given below
apply plugin: 'com.android.application'
android {
compileSdkVersion 25
buildToolsVersion "25.0.3"
defaultConfig {
applicationId "com.mycompany.myapp"
minSdkVersion 19
targetSdkVersion 25
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:appcompat-v7:25.3.1'
compile 'com.android.support:cardview-v7:25.3.1'
compile 'com.android.support:recyclerview-v7:25.3.1'
compile 'com.android.support:design:25.3.1'
compile 'pl.droidsonroids.gif:android-gif-drawable:1.2.7'
compile 'com.google.android.gms:play-services-ads:10.2.6'
compile 'com.google.android.gms:play-services-location:10.2.6'
compile 'com.google.firebase:firebase-core:10.2.6'
testCompile 'junit:junit:4.12'
}
apply plugin: 'com.google.gms.google-services'
Edit 2: Full gradle error:
Error:Execution failed for task ':app:transformClassesWithDexForDebug'.
com.android.build.api.transform.TransformException: com.android.ide.common.process.ProcessException: java.util.concurrent.ExecutionException: com.android.dex.DexException: Multiple dex files define Landroid/support/v7/util/ThreadUtil$MainThreadCallback;
Edit 3: Since support/v7/util/ThreadUtil.java belongs to RecyclerView module, I tried to exclude the RecyclerView module under design library with the following:
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:appcompat-v7:25.3.1'
compile 'com.android.support:cardview-v7:25.3.1'
compile 'com.android.support:recyclerview-v7:25.3.1'
compile ('com.android.support:design:25.3.1') {
exclude module: 'recyclerview-v7'
}
compile 'pl.droidsonroids.gif:android-gif-drawable:1.2.7'
compile 'com.google.android.gms:play-services-ads:10.2.6'
compile 'com.google.android.gms:play-services-location:10.2.6'
compile 'com.google.firebase:firebase-core:10.2.6'
testCompile 'junit:junit:4.12'
}
Still doesn't work.