Search code examples
androidproguard

"minifyEnabled true" gives me issue, why so?


when I am setting minifiyEnabled to true in my any variant (debug or release) it gives me below error -

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

It is working fine in emulator or device if its lolipop or higher.

My problem resolved if i disable or make minifyEnabled to false, but I don't really want so.

My gradle tool is build:gradle:2.3.0'

And multiDexEnabled true

Note - I am not keeping any class or attribute in my proguard-rules.pro file.


Solution

  • After a lot of recherches and experiments I have got the solution. We have to add keep and dontwarn statments in our proguard-rules.pro file -

    # 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.**
    

    Note - I followed the warnings in messages and by picking one by one put my proguard rule accordingly.