How to configure proguard to ONLY remove android logging calls

故事扮演 提交于 2019-11-28 06:28:42

You can remove logging calls with this option in proguard-project.txt:

-assumenosideeffects class android.util.Log {
    public static boolean isLoggable(java.lang.String, int);
    public static int v(...);
    public static int i(...);
    public static int w(...);
    public static int d(...);
    public static int e(...);
}

This option is only relevant if optimization is not disabled, like in proguard-android.txt. You have to specify proguard-android-optimize.txt instead, in project.properties:

proguard.config=${sdk.dir}/tools/proguard/proguard-android-optimize.txt:proguard-project.txt

You can disable shrinking and obfuscation if you wish. You can also preserve the internal API of your application from optimization if you wish:

-keep class myapp.** { *; }

Disabling these steps and keeping all code of course isn't optimal from a ProGuard point of view.

Sandeep Shabd

In build.gradle

buildTypes {

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

In proguard-rules.pro

-dontwarn **
-target 1.7
-dontusemixedcaseclassnames
-dontskipnonpubliclibraryclasses
-dontpreverify
-verbose

-optimizations !code/simplification/arithmetic,!code/allocation/variable
-keep class **
-keepclassmembers class *{*;}
-keepattributes *

#This will not remove error log
-assumenosideeffects class android.util.Log {
   public static boolean isLoggable(java.lang.String, int);
    public static int v(...);
    public static int i(...);
    public static int w(...);
    public static int d(...);
   #public static int e(...);
}
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!