Search code examples
androidproguardandroid-proguard

proguard-android-optimize build failed


i am trying to disable all logs

-assumenosideeffects class android.util.Log {

public static *** v(...);
public static *** i(...);
public static *** w(...);
public static *** d(...);
public static *** e(...);

}

 -assumenosideeffects class android.util.Log { *; }

but when i set

          proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'

build faild error

    UNEXPECTED TOP-LEVEL EXCEPTION:
Error:java.lang.InterruptedException: Too many errors
at com.android.dx.command.dexer.Main.processAllFiles(Main.java:600)
... 4 more
Error:Execution failed for task ':app:transformClassesWithDexForDebug'.

com.android.build.api.transform.TransformException: com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command '/Library/Java/JavaVirtualMachines/jdk1.8.0_66.jdk/Contents/Home/bin/java'' finished with non-zero exit value 2

with this proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' its build but logs are visible

The recommended solution is to recompile the class from source, using an up-to-date compiler and without specifying any "-target" type options. The consequence of ignoring this warning is that reflective operations on this class will incorrectly indicate that it is not an inner class.

Uncaught translation error: com.android.dx.cf.code.SimException: local variable type mismatch: attempt to set or access a value of type java.lang.Object using a local variable of type int. This is symptomatic of .class transformation tools that ignore local variable information.


Solution

  • Please use the following proguard for the reference as during optimizations, native methods need to keep as it is.

    -dontusemixedcaseclassnames
    -optimizationpasses 5
    -allowaccessmodification
    -keep public class * extends android.app.Activity
    -keep public class * extends android.app.Application
    -keep public class * extends android.app.Service
    -keep public class * extends android.content.BroadcastReceiver
    -keep public class * extends android.content.ContentProvider
    -keep public class * extends android.preference.Preference
    -keep public class * extends android.support.v4.app.Fragment
    -keep public class * extends android.app.Fragment
    # For native methods, see http://proguard.sourceforge.net/manual/examples.html#native
    -keepclasseswithmembernames class * {
     native <methods>;
    }
    -keep public class * extends android.view.View {
     public <init>(android.content.Context);
     public <init>(android.content.Context, android.util.AttributeSet);
     public <init>(android.content.Context, android.util.AttributeSet, int);
     public void set*(...);
    }
    -keepclasseswithmembers class * {
     public <init>(android.content.Context, android.util.AttributeSet);
    }
    -keepclasseswithmembers class * {
     public <init>(android.content.Context, android.util.AttributeSet, int);
    }
    -keepclassmembers class * extends android.app.Activity {
     public void *(android.view.View);
    }
    # For enumeration classes, see http://proguard.sourceforge.net/manual/examples.html#enumerations
    -keepclassmembers enum * {
     public static **[] values();
     public static ** valueOf(java.lang.String);
    }
    -keep class * implements android.os.Parcelable {
     public static final android.os.Parcelable$Creator *;
    }
    

    hope this helps.