Retrofit: ProGuard issues on Android 6 Marshmallow caused by removed org.apache.http package

Created on 21 Aug 2015  Â·  7Comments  Â·  Source: square/retrofit

When building for Android 6 Marshmallow with ProGuard enabled, minification fails because Retrofit depends on the newly removed org.apache.http package. Here's ProGuards output:

Warning: retrofit.android.AndroidApacheClient: can't find referenced class android.net.http.AndroidHttpClient
Warning: retrofit.android.AndroidApacheClient: can't find referenced class android.net.http.AndroidHttpClient
Warning: retrofit.client.ApacheClient: can't find referenced class org.apache.http.params.BasicHttpParams
Warning: retrofit.client.ApacheClient: can't find referenced class org.apache.http.params.BasicHttpParams
Warning: retrofit.client.ApacheClient: can't find referenced class org.apache.http.impl.client.DefaultHttpClient
Warning: retrofit.client.ApacheClient: can't find referenced class org.apache.http.impl.client.DefaultHttpClient
Warning: retrofit.client.ApacheClient: can't find referenced class org.apache.http.client.HttpClient
Warning: retrofit.client.ApacheClient: can't find referenced class org.apache.http.HttpResponse
Warning: retrofit.client.ApacheClient: can't find referenced class org.apache.http.StatusLine
Warning: retrofit.client.ApacheClient: can't find referenced class org.apache.http.StatusLine
Warning: retrofit.client.ApacheClient: can't find referenced class org.apache.http.HttpResponse
Warning: retrofit.client.ApacheClient: can't find referenced class org.apache.http.Header
Warning: retrofit.client.ApacheClient: can't find referenced class org.apache.http.Header
Warning: retrofit.client.ApacheClient: can't find referenced class org.apache.http.HttpResponse
Warning: retrofit.client.ApacheClient: can't find referenced class org.apache.http.util.EntityUtils
Warning: retrofit.client.ApacheClient: can't find referenced class org.apache.http.HttpResponse
Warning: retrofit.client.ApacheClient: can't find referenced class org.apache.http.StatusLine
Warning: retrofit.client.ApacheClient: can't find referenced class org.apache.http.Header
Warning: retrofit.client.ApacheClient: can't find referenced class org.apache.http.Header
Warning: retrofit.client.ApacheClient: can't find referenced class org.apache.http.HttpEntity
Warning: retrofit.client.ApacheClient: can't find referenced class org.apache.http.client.HttpClient
Warning: retrofit.client.ApacheClient: can't find referenced class org.apache.http.HttpResponse
Warning: retrofit.client.ApacheClient: can't find referenced class org.apache.http.StatusLine
Warning: retrofit.client.ApacheClient: can't find referenced class org.apache.http.Header
Warning: retrofit.client.ApacheClient: can't find referenced class org.apache.http.util.EntityUtils
Warning: retrofit.client.ApacheClient: can't find referenced class org.apache.http.client.HttpClient
Warning: retrofit.client.ApacheClient: can't find referenced class org.apache.http.client.HttpClient
Warning: retrofit.client.ApacheClient: can't find referenced class org.apache.http.client.HttpClient
Warning: retrofit.client.ApacheClient: can't find referenced class org.apache.http.client.HttpClient
Warning: retrofit.client.ApacheClient: can't find referenced class org.apache.http.client.methods.HttpUriRequest
Warning: retrofit.client.ApacheClient: can't find referenced class org.apache.http.HttpResponse
Warning: retrofit.client.ApacheClient: can't find referenced class org.apache.http.client.HttpClient
Warning: retrofit.client.ApacheClient: can't find referenced class org.apache.http.client.methods.HttpUriRequest
Warning: retrofit.client.ApacheClient: can't find referenced class org.apache.http.HttpResponse
Warning: retrofit.client.ApacheClient: can't find referenced class org.apache.http.client.HttpClient
Warning: retrofit.client.ApacheClient: can't find referenced class org.apache.http.client.methods.HttpUriRequest
Warning: retrofit.client.ApacheClient: can't find referenced class org.apache.http.client.methods.HttpUriRequest
Warning: retrofit.client.ApacheClient: can't find referenced class org.apache.http.HttpResponse
Warning: retrofit.client.ApacheClient: can't find referenced class org.apache.http.Header
Warning: retrofit.client.ApacheClient: can't find referenced class org.apache.http.HttpResponse
Warning: retrofit.client.ApacheClient: can't find referenced class org.apache.http.StatusLine
Warning: retrofit.client.ApacheClient: can't find referenced class org.apache.http.HttpEntity
Warning: retrofit.client.ApacheClient$GenericEntityHttpRequest: can't find referenced class org.apache.http.client.methods.HttpEntityEnclosingRequestBase
Warning: retrofit.client.ApacheClient$GenericEntityHttpRequest: can't find referenced method 'void setURI(java.net.URI)' in program class retrofit.client.ApacheClient$GenericEntityHttpRequest
Warning: retrofit.client.ApacheClient$GenericEntityHttpRequest: can't find referenced class org.apache.http.message.BasicHeader
Warning: retrofit.client.ApacheClient$GenericEntityHttpRequest: can't find referenced class org.apache.http.message.BasicHeader
Warning: retrofit.client.ApacheClient$GenericEntityHttpRequest: can't find referenced method 'void addHeader(org.apache.http.Header)' in program class retrofit.client.ApacheClient$GenericEntityHttpRequest
Warning: retrofit.client.ApacheClient$GenericEntityHttpRequest: can't find referenced method 'void setEntity(org.apache.http.HttpEntity)' in program class retrofit.client.ApacheClient$GenericEntityHttpRequest
Warning: retrofit.client.ApacheClient$GenericEntityHttpRequest: can't find referenced class org.apache.http.client.methods.HttpEntityEnclosingRequestBase
Warning: retrofit.client.ApacheClient$GenericHttpRequest: can't find referenced class org.apache.http.client.methods.HttpRequestBase
Warning: retrofit.client.ApacheClient$GenericHttpRequest: can't find referenced method 'void setURI(java.net.URI)' in program class retrofit.client.ApacheClient$GenericHttpRequest
Warning: retrofit.client.ApacheClient$GenericHttpRequest: can't find referenced class org.apache.http.message.BasicHeader
Warning: retrofit.client.ApacheClient$GenericHttpRequest: can't find referenced class org.apache.http.message.BasicHeader
Warning: retrofit.client.ApacheClient$GenericHttpRequest: can't find referenced method 'void addHeader(org.apache.http.Header)' in program class retrofit.client.ApacheClient$GenericHttpRequest
Warning: retrofit.client.ApacheClient$GenericHttpRequest: can't find referenced class org.apache.http.client.methods.HttpRequestBase
Warning: retrofit.client.ApacheClient$TypedOutputEntity: can't find referenced class org.apache.http.entity.AbstractHttpEntity
Warning: retrofit.client.ApacheClient$TypedOutputEntity: can't find referenced method 'void setContentType(java.lang.String)' in program class retrofit.client.ApacheClient$TypedOutputEntity
Warning: retrofit.client.ApacheClient$TypedOutputEntity: can't find referenced class org.apache.http.entity.AbstractHttpEntity

Most helpful comment

Add these lines in your Proguard config and build will succeed:

-dontwarn org.apache.http.**
-dontwarn android.net.http.AndroidHttpClient

All 7 comments

Add these lines in your Proguard config and build will succeed:

-dontwarn org.apache.http.**
-dontwarn android.net.http.AndroidHttpClient

V2 doesn't reference Apache HTTP client anymore so this is already "fixed". As to V1, either add the Apache shim that adds the APIs to the classpath or simply ignore it as @colriot posted.

@cypressious in addition to the ignores that @colriot posted, I also needed the following:

-dontwarn retrofit.client.ApacheClient$GenericEntityHttpRequest
-dontwarn retrofit.client.ApacheClient$GenericHttpRequest
-dontwarn retrofit.client.ApacheClient$TypedOutputEntity

Thanks, the build now completes. If I have OkHTTP in the classpath, will Retrofit ever reference the removed Apache classes? My guess would be no, but I'd like to make sure.

Nope!

On Tue, Aug 25, 2015 at 5:46 PM Kirill Rakhman [email protected]
wrote:

Thanks, the build now completes. If I have OkHTTP in the classpath, will
Retrofit ever reference the removed Apache classes? My guess would be no,
but I'd like to make sure.

—
Reply to this email directly or view it on GitHub
https://github.com/square/retrofit/issues/1019#issuecomment-134751190.

Hello, I have set following options in my configuration but I am still getting errors. I am using DexGuard and Retrofit 1.9.0

-dontwarn org.apache.http.**
-dontwarn android.net.http.AndroidHttpClient
-dontwarn retrofit.client.ApacheClient$GenericEntityHttpRequest
-dontwarn retrofit.client.ApacheClient$GenericHttpRequest
-dontwarn retrofit.client.ApacheClient$TypedOutputEntity

Unexpected error while evaluating instruction:
Class = [retrofit/client/ApacheClient]
Method = [createRequest(Lretrofit/client/Request;)Lorg/apache/http/client/methods/HttpUriRequest;]
Instruction = [15] areturn
Exception = java.lang.IllegalArgumentException
Unexpected error while performing partial evaluation:
Class = [retrofit/client/ApacheClient]
Method = [createRequest(Lretrofit/client/Request;)Lorg/apache/http/client/methods/HttpUriRequest;]
Exception = java.lang.IllegalArgumentException

Execution failed for task ':app:dexguardReleaseSigned'.

Can't find common super class of retrofit/client/ApacheClient$GenericEntityHttpRequest and retrofit/client/ApacheClient$GenericHttpRequest

Got it working adding useLibrary 'org.apache.http.legacy' in my build.gradle

Was this page helpful?
0 / 5 - 0 ratings