5

I am trying to update my app from the deprecated Android Drive API to the Drive REST API by following the sample app.

When trying to build the signed release APK, I get this lint problem:

httpclient defines classes that conflict with classes now provided by Android. Solutions include finding newer versions or alternative libraries that don't have the same problem (for example, for httpclient use HttpUrlConnection or okhttp instead), or repackaging the library using something like jarjar.

Here are my gradle dependencies:

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.android.support:appcompat-v7:27.1.1'
    implementation 'com.google.android.gms:play-services-auth:16.0.1'
    implementation 'com.android.support:design:27.1.1'
    implementation 'com.android.support:customtabs:27.1.1'
    implementation 'com.google.http-client:google-http-client-gson:1.26.0'
    implementation('com.google.api-client:google-api-client-android:1.26.0') {
        exclude group: 'org.apache.httpcomponents'
    }
    implementation('com.google.apis:google-api-services-drive:v3-rev136-1.25.0') {
        exclude group: 'org.apache.httpcomponents'
    }
}

I'm guessing the problem is caused by:

    implementation 'com.google.http-client:google-http-client-gson:1.26.0'

I've tried the solutions posted here and here, but they don't work.

Like this comment says:

I am not able to get release apk if exclude httpclient

What other solution(s) are there?

Iván Nokonoko
  • 4,888
  • 2
  • 19
  • 27

1 Answers1

8

Try excluding the org.apache.httpcomponents module also from google-http-client-gson. Then, if your projects requires Apache HttpClient classes, use some wrapper to provide them, e.g. this one works great even when targetting the newest SDK.

I use the following block in app\build.gradle and it works fine (I just use older version of google-http-client-gson module):

compile ('com.google.http-client:google-http-client-gson:1.19.0') {
    //Exclude conflicting modules
    exclude module: 'httpclient'
    exclude module: 'commons-logging'
}
//Add HttpClient classes from a different package
compile 'cz.msebera.android:httpclient:4.5.8'

Then you will just have to change all your org.apache.http imports to cz.msebera.android.httpclient, e.g.

import org.apache.http.HttpResponse

becomes

import cz.msebera.android.httpclient.HttpResponse
kibitzerCZ
  • 487
  • 8
  • 20
  • Just excluding the 2 modules from `com.google.api-client:google-api-client` worked for me. I don't use those libraries explicitly in my code, so didn't need any replacement. – Slav Oct 07 '19 at 09:20