0

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:

  1. I've cleaned and rebuilt the project.
  2. Added multiDexEnabled true to android{defaultConfig{}}
  3. 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!

Salmononius2
  • 295
  • 5
  • 14
  • the library contains the following `compile 'org.apache.httpcomponents:httpclient-android:4.3.5.1' compile 'org.apache.httpcomponents:httpmime:4.3.5'`. Try removing or exclude it – ישו אוהב אותך Jan 29 '18 at 04:03
  • @ישואוהבאותך Unfortunately, this didn't work for me. Still getting the same error. Was I doing the exclusion correctly? This is my code: compile ('com.github.danysantiago:sendgrid-android:1') { exclude module: 'org.apache.httpcomponents:httpclient-android:4.3.5.1' exclude module: 'org.apache.httpcomponents:httpmime:4.3.5' } – Salmononius2 Jan 29 '18 at 14:50
  • try this: `compile ('com.github.danysantiago:sendgrid-android:1'){ exclude group: 'org.apache.httpcomponents', module: 'httpclient' exclude group: 'org.apache.httpcomponents', module: 'httpmime' }` – ישו אוהב אותך Jan 30 '18 at 01:41
  • @ישואוהבאותך Thank you so much, this worked! (Although as it turns out, I only needed to exclude httpclient and not httpmime). If you want to put this as an answer, I'll give it an upvote and mark it as correct. – Salmononius2 Feb 01 '18 at 15:29
  • Congrats!, I've make the comment as answer ;) – ישו אוהב אותך Feb 02 '18 at 02:46

3 Answers3

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'
}
ישו אוהב אותך
  • 28,609
  • 11
  • 78
  • 96
0

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"
>
Arjun saini
  • 4,223
  • 3
  • 23
  • 51
0

There is a new Android SendGrid library utilising Sendgrid's v3 API. The updated library negates the issues when implementing older libraries into applications that target newer Android API version.

The library can be imported with jitpack

allprojects {
    repositories {
        ...
        maven { url "https://jitpack.io" }
    }
}

dependencies {
     implementation 'com.github.jakebreen:android-sendgrid:1.2.2'
}

https://github.com/Jakebreen/android-sendgrid

JakeB
  • 2,043
  • 3
  • 12
  • 19