ProGuard: duplicate library class definition?

I run my ProGuard for my Android project and receive the following warnings:

Note: duplicate definition of library class [org.apache.http.conn.scheme.HostNameResolver] Note: duplicate definition of library class [org.apache.http.conn.scheme.SocketFactory] Note: duplicate definition of library class [org.apache.http.conn.ConnectTimeoutException] Note: duplicate definition of library class [org.apache.http.params.HttpParams] Note: duplicate definition of library class [android.net.http.SslCertificate$DName] Note: duplicate definition of library class [android.net.http.SslError] Note: duplicate definition of library class [android.net.http.SslCertificate] Note: there were 7 duplicate class definitions. 

I found here to fix this, ignoring it with:

 -keep class org.apache.http.** { *; } -dontwarn org.apache.http.** -keep class android.net.http.** { *; } -dontwarn android.net.http.** 

I see no way to remove duplicates from the libraries used. Even after using dontwarn warnings do not disappear.

Is this handling of this warning correct, simply ignoring it, or can this lead to problems?

+54
java android android-studio proguard android-proguard
09 Oct '15 at 22:03
source share
4 answers

If you add the option proguard -printconfiguration config.txt , you will see that proguard adds

-libraryjars 'D: \ tools \ android \ platform \ android-23 \ android.jar'

-libraryjars 'D: \ tools \ android \ platform \ android-23 \ optional \ org.apache.http.legacy.jar'

your duplicate classes (e.g. SslError) are represented both in android.jar and in org.apache.http.legacy.jar

Proguard adds a second jar, even if you don't useLibrary 'org.apache.http.legacy' The following is an error describing the problem.

So now we can do nothing with this problem. Just ignore this:

 -dontnote android.net.http.* -dontnote org.apache.commons.codec.** -dontnote org.apache.http.** 

There is no need to store classes as long as they are in the library bank (actually, on the phone). dontwarn does not work because it is not a warning, it is a note.

+47
Mar 02 '16 at 9:09
source share

You may have mentioned "-injars" and -libraryjars in your proguard-project.txt, given that the latest build system takes care of mentioning them for you. So you do not need to mention it again.

Source: http://proguard.sourceforge.net/manual/troubleshooting.html#duplicateclass

I think this will help. :)

+5
Nov 18 '15 at 14:42
source share

You can tell gradle not to allow class duplication (take only the first) by adding the following to your build.gradle:

 jar { duplicatesStrategy = DuplicatesStrategy.EXCLUDE } 
+1
Oct 17 '16 at 2:35
source share

You can try this in your build.gradle for everything that is designated as duplicate in logs. I'm not sure if this will work, so try and let it know if it works or not.

 packagingOptions { exclude 'android.net.http.SslCertificate' } 
-5
Mar 02 '16 at 13:28
source share



All Articles