Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ParseApacheHttpClient issue with Android Marshmallow: can't find referenced method SSLSocketFactory.getHttpSocketFactory

I'm working on Android Marshmallow support in my Android app but I have dependencies which are using the deprecated Apache HTTP client (including Parse).

As recommended here, I've added:

useLibrary 'org.apache.http.legacy'

in my app/build.gradle but I can't still compile an apk:

:app:compileFreeStoreDebugJavaWithJavac UP-TO-DATE
:app:compileRetrolambdaFreeStoreDebug UP-TO-DATE
:app:compileFreeStoreDebugSources UP-TO-DATE
:app:proguardFreeStoreDebug
Note: there were 7 duplicate class definitions.
      (http://proguard.sourceforge.net/manual/troubleshooting.html#duplicateclass)
Warning: com.parse.ParseApacheHttpClient: can't find referenced method 'org.apache.http.conn.ssl.SSLSocketFactory getHttpSocketFactory(int,android.net.SSLSessionCache)' in library class android.net.SSLCertificateSocketFactory
Warning: there were 1 unresolved references to library class members.
         You probably need to update the library versions.
         (http://proguard.sourceforge.net/manual/troubleshooting.html#unresolvedlibraryclassmember)
Exception while processing task
java.io.IOException: Please correct the above warnings first.
    at proguard.Initializer.execute(Initializer.java:473)
    at proguard.ProGuard.initialize(ProGuard.java:233)
    at proguard.ProGuard.execute(ProGuard.java:98)
    at proguard.gradle.ProGuardTask.proguard(ProGuardTask.java:1074)
    at com.android.build.gradle.tasks.AndroidProGuardTask.doMinification(AndroidProGuardTask.java:139)
    at com.android.build.gradle.tasks.AndroidProGuardTask$1.run(AndroidProGuardTask.java:115)
    at com.android.builder.tasks.Job.runTask(Job.java:48)
    at com.android.build.gradle.tasks.SimpleWorkQueue$EmptyThreadContext.runTask(SimpleWorkQueue.java:41)
    at com.android.builder.tasks.WorkQueue.run(WorkQueue.java:227)
    at java.lang.Thread.run(Thread.java:745)

Thanks.

like image 282
pgreze Avatar asked Oct 26 '15 17:10

pgreze


1 Answers

This issue is solved in 2 parts:

  1. adding back the legacy Apache library
  2. updating ProGuard configuration for Parse.com

I'm going to address both parts below for completeness.

For those looking for the quick fix, the solution is to add the following line to your ProGuard configuation file:

-dontwarn android.net.SSLCertificateSocketFactory

1 - Apache Library

Android-M removes support for the Apache HTTP library. As mentioned in the question, the fix is to use the legacy support JAR by updating your build.gradle. Here is the code with a bit more context:

android {
    compileSdkVersion 23
    buildToolsVersion "23.0.2"
    useLibrary 'org.apache.http.legacy'
    ....
}

2 - Update ProGuard Configuration

The actual error comes from ProGuard, when it is trying to process Parse.com.

Warning: com.parse.ParseApacheHttpClient: 
can't find referenced method 'org.apache.http.conn.ssl.SSLSocketFactory getHttpSocketFactory(int,android.net.SSLSessionCache)' 
in library class android.net.SSLCertificateSocketFactory

Parse is now open source, so checking the issues gives this page on GitHub:

  • Issue with android M compilesdkversion 23 #231

The discussion explains that this is just a ProGuard config item, and can be safely fixed by updating your config as per the related issue:

  • Update proguard-rules.pro for android-23 #234

Here is the change (line 3 fixes our issue, line 4 fixes related issue):

-keepattributes *Annotation*
-keepattributes Signature
-dontwarn android.net.SSLCertificateSocketFactory
-dontwarn android.app.Notification
-dontwarn com.squareup.**
-dontwarn okio.**

As explained in this comment, it is safe to ignore the warnings since those classes are only ever used on Android versions that still contain the mentioned classes.

like image 173
Richard Le Mesurier Avatar answered Nov 15 '22 18:11

Richard Le Mesurier