0

I am trying to generate a signed APK with minifyEnabled set to true in Gradle:

buildTypes {
        release {
            minifyEnabled true
            shrinkResources true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }

and added these to my proguard file:

-dontwarn okio.**
-dontwarn retrofit.**

but I get these errors:

Information:Gradle tasks [:app:assembleRelease]
Warning:retrofit2.Platform$Java8: can't find referenced method 'boolean isDefault()' in library class java.lang.reflect.Method
Warning:retrofit2.Platform$Java8: can't find referenced class java.lang.invoke.MethodHandles$Lookup
Warning:retrofit2.Platform$Java8: can't find referenced class java.lang.invoke.MethodHandle
Warning:retrofit2.Platform$Java8: can't find referenced class java.lang.invoke.MethodHandles
Warning:retrofit2.Platform$Java8: can't find referenced class java.lang.invoke.MethodHandle
Warning:retrofit2.Platform$Java8: can't find referenced class java.lang.invoke.MethodHandles$Lookup
Warning:retrofit2.Platform$Java8: can't find referenced class org.codehaus.mojo.animal_sniffer.IgnoreJRERequirement
Warning:there were 8 unresolved references to classes or interfaces.
Warning:there were 1 unresolved references to library class members.
Warning:Exception while processing task java.io.IOException: Please correct the above warnings first.
Error:Execution failed for task ':app:transformClassesAndResourcesWithProguardForRelease'.
> java.io.IOException: Please correct the above warnings first.
Information:BUILD FAILED

and can't build the apk file. We can't have minifyEnabled as true and use retrofit library? how can this be fixed?

user7660671
  • 1
  • 1
  • 1
  • [check this](http://stackoverflow.com/questions/33877134/errorexecution-failed-for-task-androidtransformclassesandresourceswithprogua) – Mehran Zamani Mar 05 '17 at 08:05

2 Answers2

1

You can have minifyEnabled as true and use any number of libraries. Just one thing to make note of its to add the proguard rules of every library in the proguard-rules.pro file. Check retrofits proguard handling here.

Lastly adding a proguard-rules.pro for your reference this is for the project im handling. (You might also need to notify proguard to exclude your POJO classes. Check example)

# Add project specific ProGuard rules here.
# By default, the flags in this file are appended to flags specified
# in /Users/yogeshmalpani/Library/Android/sdk/tools/proguard/proguard-android.txt
# You can edit the include path and order by changing the proguardFiles
# directive in build.gradle.
#
# For more details, see
#   http://developer.android.com/guide/developing/tools/proguard.html

# Add any project specific keep options here:
-dontwarn com.squareup.okhttp.**
-keep class com.pushwoosh.** { *; }
-keep class com.arellomobile.** { *; }
-dontwarn com.pushwoosh.**
-dontwarn com.arellomobile.**
-dontwarn butterknife.internal.**
-keep class **$$ViewInjector { *; }
-keepnames class * { @butterknife.InjectView *;}
-keepattributes *Annotation*,EnclosingMethod,Signature,SourceFile,LineNumberTable
-keepnames class com.fasterxml.jackson.** { *; }
 -dontwarn com.fasterxml.jackson.databind.**
 -keep class org.codehaus.** { *; }
 -keepclassmembers public final enum org.codehaus.jackson.annotate.JsonAutoDetect$Visibility {
 public static final org.codehaus.jackson.annotate.JsonAutoDetect$Visibility *; }
# My POJO class directory
-keep public class com.app_name.model.pojo.** {
  public void set*(***);
  public *** get*();
  public protected private *;
}
# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
#   public *;
#}
MadScientist
  • 2,134
  • 14
  • 27
0

I think you are using retrofit 2,

-dontwarn okio.**
-dontwarn retrofit2.**
-keep class retrofit2.** { *; }
-keepattributes Signature
-keepattributes Exceptions
sadat
  • 4,004
  • 2
  • 29
  • 49