美文网首页
Android两步去掉Release版本Log日志

Android两步去掉Release版本Log日志

作者: 简单点的笨演员 | 来源:发表于2021-02-07 12:00 被阅读0次

在APP项目的release配置中开启混淆配置,已经开启的就不用管了:

    buildTypes {
        debug {
        }
        release {
            // Enables code shrinking, obfuscation, and optimization for only
            // your project's release build type.
            minifyEnabled true

            // Enables resource shrinking, which is performed by the
            // Android Gradle plugin.
            shrinkResources true

            // Includes the default ProGuard rules files that are packaged with
            // the Android Gradle plugin. To learn more, go to the section about
            // R8 configuration files.
            proguardFiles getDefaultProguardFile(
                    'proguard-android-optimize.txt'),
                    'proguard-rules.pro'
        }
    ....

在代码混淆配置proguard-rules.pro添加下面的代码:

#-------------- 去掉所有打印 -------------
-assumenosideeffects class android.util.Log {
    public static *** d(...);
#    public static *** e(...);
    public static *** i(...);
    public static *** v(...);
    public static *** println(...);
    public static *** w(...);
    public static *** wtf(...);
}
-assumenosideeffects class android.util.Log {
   public static *** d(...);
   public static *** v(...);
}

-assumenosideeffects class android.util.Log {
#    public static *** e(...);
    public static *** v(...);
}

-assumenosideeffects class android.util.Log {
    public static *** i(...);
    public static *** v(...);
}

-assumenosideeffects class android.util.Log {
    public static *** w(...);
    public static *** v(...);
}
-assumenosideeffects class java.io.PrintStream {
    public *** println(...);
    public *** print(...);
}

参考:
https://blog.csdn.net/abccjf/article/details/79524573

相关文章

网友评论

      本文标题:Android两步去掉Release版本Log日志

      本文链接:https://www.haomeiwen.com/subject/wqkztltx.html