问题
I'm trying to add a specific module into my Android project (this one over here: https://github.com/danysantiago/sendgrid-android), but while the project seems to build correctly, I get the following error when I try to run the project:
Error:Execution failed for task ':app:transformDexArchiveWithExternalLibsDexMergerForDebug'. com.android.builder.dexing.DexArchiveMergerException: Unable to merge dex
I'm able to confirm that it's this specific module that is causing the error, since the project works if I comment the following line out of the gradle:
compile 'com.github.danysantiago:sendgrid-android:1'
What I've tried so far:
- I've cleaned and rebuilt the project.
- Added multiDexEnabled true to android{defaultConfig{}}
- Added implementation 'com.android.support:multidex:1.0.2' to dependencies{}
Unfortunately, none of those items worked, and I wasn't able to find any other solutions on StackOverflow that solved the issue. Any help with this issue would be greatly appreciated!
回答1:
You need to exclude the httpclient from the library with this:
compile ('com.github.danysantiago:sendgrid-android:1'){
exclude group: 'org.apache.httpcomponents', module: 'httpclient'
}
回答2:
Update in your gradle
defaultConfig {
..............
multiDexEnabled true
}
dexOptions should add..
dexOptions {
//incremental = true;
preDexLibraries = false
javaMaxHeapSize "4g"
}
dependency add
compile 'com.android.support:multidex:1.0.1'
Also In Your AndroidManifest.xml add this lines android:name
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme"
android:name="android.support.multidex.MultiDexApplication"
>
来源:https://stackoverflow.com/questions/48494163/unable-to-merge-dex-error-in-android-studio-when-adding-a-specific-compile-in