Like @intellij-amiya's answer, using multidex
or proguard
will solve your problem and I personally recommend that.
If you do not want to follow that method, you can manually exclude duplicated dependencies.
Execute the following command in your terminal to find duplicated dependencies.
./gradlew :app:dependencies --configuration compile
or if you on windows,
gradlew.bat :app:dependencies --configuration compile
change :app
as your project name.
Let's assume your gradle dependencies are like this:
compile 'com.android.support:support-compat:26.+'
compile 'com.android.support:support-fragment:26.+'
You will get output like below:
+--- com.android.support:support-compat:26.+ -> 26.0.0-alpha1
| \--- com.android.support:support-annotations:26.0.0-alpha1
\--- com.android.support:support-fragment:26.+ -> 26.0.0-alpha1
+--- com.android.support:support-compat:26.0.0-alpha1 (*)
+--- com.android.support:support-core-ui:26.0.0-alpha1
| +--- com.android.support:support-annotations:26.0.0-alpha1
| \--- com.android.support:support-compat:26.0.0-alpha1 (*)
\--- com.android.support:support-core-utils:26.0.0-alpha1
+--- com.android.support:support-annotations:26.0.0-alpha1
\--- com.android.support:support-compat:26.0.0-alpha1 (*)
And you can see dependencies marked with (*)
, and these dependencies can be excluded. You can see support-compat
is duplicated, and exclude it is done by edit like this:
compile ('com.android.support:support-fragment:26.+') {
exclude module: 'support-compat'
}
Repeating this until you can get the count below 64k
And now the hardest part remains.
In my experience, excluding some dependencies may cause build fail, runtime exceptions, and etc. So you need to check your application working well without problem.
Hope this help.