ProGuard:库类的重复定义?

con*_*ile 78 java android proguard android-studio android-proguard

我为我的Android项目运行ProGuard并收到以下警告:

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.
Run Code Online (Sandbox Code Playgroud)

我发现这里解决了这个问题而忽略了它:

-keep class org.apache.http.** { *; }
-dontwarn org.apache.http.**
-keep class android.net.http.** { *; }
-dontwarn android.net.http.**
Run Code Online (Sandbox Code Playgroud)

我没有看到从已使用的库中删除重复项的方法.即使使用dontwarn警告后也不会消失.

这是处理此警告的正确方法,只是忽略它或者这会导致问题吗?

Fla*_*vio 89

如果你添加一个proguard选项,-printconfiguration config.txt你会看到proguard添加

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

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

您的重复类(例如SslError)在android.jar和org.apache.http.legacy.jar中都有显示

Proguard即使你不添加第二个jar useLibrary 'org.apache.http.legacy' 这里是一个描述问题的漏洞.

所以现在我们对这个问题无能为力.只是忽略它:

-dontnote android.net.http.*
-dontnote org.apache.commons.codec.**
-dontnote org.apache.http.**
Run Code Online (Sandbox Code Playgroud)

只要它们位于库jar(实际上是电话库)中就没有必要保留这些类.dontwarn不起作用,因为它不是警告,它是一个注释.

  • 大!谢谢.这个答案应该标记为正确答案! (6认同)

小智 6

可能你在proguard-project.txt中提到过"-injars"和"libjjjars",考虑到最新的构建系统会为你提起它们.所以你不需要再提一下它.

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

我认为这会有所帮助.:)