“minifyEnabled true”给了我一个问题,为什么会这样?

时间:2017-08-22 09:50:14

标签: android proguard

当我在我的任何变体(调试或发布)中将minifiyEnabled设置为true时,它会给我以下错误 -

Warning:retrofit.appengine.UrlFetchClient: can't find referenced class com.google.appengine.api.urlfetch.HTTPRequest
Warning:retrofit.appengine.UrlFetchClient: can't find referenced class com.google.appengine.api.urlfetch.HTTPHeader
Warning:library class android.webkit.WebView depends on program class android.net.http.SslCertificate
Warning:library class android.webkit.WebViewClient depends on program class android.net.http.SslError
Warning:library class org.apache.http.conn.ssl.SSLSocketFactory depends on program class org.apache.http.conn.scheme.HostNameResolver
Warning:library class org.apache.http.conn.ssl.SSLSocketFactory depends on program class org.apache.http.params.HttpParams
Warning:library class org.apache.http.params.HttpConnectionParams depends on program class org.apache.http.params.HttpParams
Warning:there were 176 unresolved references to classes or interfaces.
Warning:there were 23 instances of library classes depending on program classes.
Warning:there were 6 unresolved references to program class members.
Warning:Exception while processing task java.io.IOException: Please correct the above warnings first.
Error:Execution failed for task ':app:transformClassesAndResourcesWithProguardForProductionDebug'.
> Job failed, see logs for details

如果它的lolipop或更高版本,它在模拟器或设备中工作正常。

如果我禁用或将minifyEnabled设为false,我的问题就解决了,但我真的不想这样。

我的gradle工具是 build:gradle:2.3.0'

multiDexEnabled true

注意 - 我没有在 proguard-rules.pro 文件中保留任何类或属性。

3 个答案:

答案 0 :(得分:1)

经过大量的研究和实验后,我得到了解决方案。我们必须在 proguard-rules.pro 文件中添加保留 dontwarn 声明 -

# Retrofit 1.X
-keep class com.squareup.okhttp.** { *; }
-keep class retrofit.** { *; }
-keep interface com.squareup.okhttp.** { *; }

-dontwarn com.squareup.okhttp.**
-dontwarn okio.**
-dontwarn retrofit.**
-dontwarn rx.**

-keepclasseswithmembers class * {
    @retrofit.http.* <methods>;
}

# If in your rest service interface you use methods with Callback argument.
-keepattributes Exceptions

# If your rest service methods throw custom exceptions, because you've defined an ErrorHandler.
-keepattributes Signature



# Proguard configuration for amazon Jackson 2.x (fasterxml package instead of codehaus package)

-keep class com.amazonaws.** { *; }
-keepnames class com.amazonaws.** { *; }
-dontwarn com.amazonaws.**
-dontwarn com.fasterxml.**


-keep public class com.google.android.gms.* { public *; }
-dontwarn com.google.android.gms.**

-dontwarn org.mockito.**
-dontwarn sun.reflect.**
-dontwarn android.test.**



-dontwarn org.hamcrest.**
-dontwarn android.test.**
-dontwarn android.support.test.**

-keep class org.hamcrest.** {
   *;
}

-keep class org.junit.** { *; }
-dontwarn org.junit.**

-keep class junit.** { *; }
-dontwarn junit.**

-keep class sun.misc.** { *; }
-dontwarn sun.misc.**


-keep public class android.net.http.SslError
-keep public class android.webkit.WebViewClient

-dontwarn android.webkit.WebView
-dontwarn android.net.http.SslError
-dontwarn android.webkit.WebViewClient


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

注意 - 我按照消息中的警告进行操作,然后逐一选择我的proguard规则。

答案 1 :(得分:0)

尝试将以下行添加到您的proguard配置中:

# Platform calls Class.forName on types which do not exist on Android to determine platform.
-dontnote retrofit2.Platform
# Platform used when running on Java 8 VMs. Will not be used at runtime.
-dontwarn retrofit2.Platform$Java8
# Retain generic type information for use by reflection by converters and adapters.
-keepattributes Signature
# Retain declared checked exceptions for use by a Proxy instance.
-keepattributes Exceptions

这是改造图书馆。对于其他外部库,您可以将此方法与您想要忽略的自己的包一起使用;

-dontwarn org.apache.** - 例如

有关ProGuard使用的更多信息,您可以找到here

答案 2 :(得分:0)

如果您定义了正确的 proguard 规则并且仍然存在问题请 minifyEnabled true 仅用于应用级别用于其他模块< / strong>使用 minifyEnabled false

如果发现任何lintError且无法解决,请使用下面的代码

lintOptions {
checkReleaseBuilds false
// Or, if you prefer, you can continue to check for errors in release builds,
// but continue the build even when errors are found:
abortOnError false

}

经过这么多的努力,我已经检查了它和它的作品。