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.
This issue is solved in 2 parts:
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
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'
....
}
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:
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:
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With