使用 proguard 删除日志调用 [英] Removing Log call using proguard

查看:48
本文介绍了使用 proguard 删除日志调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 proguard 删除我的所有日​​志:我在 proguard-project.txt 中输入了以下行:

I am trying to use proguard to strip all my logs: I have entered the following line in my proguard-project.txt:

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

我的 project.properties 看起来像这样:

And my project.properties looks like this:

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

尽管如此,日志仍继续显示在我的应用程序中.我到底做错了什么?

Inspite of this the logs continue to show in my application. What exactly am I doing wrong here?

推荐答案

你不应该指定*"通配符,因为它包括像Object#wait()"这样的方法.最好明确列出方法:

You shouldn't specify the '*' wildcard, because that includes methods like 'Object#wait()'. Better explicitly list the methods:

-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(...);
}

此选项仅在未禁用优化的情况下才相关,例如在 proguard-android.txt 中.你必须指定 proguard-android-optimize.txt 代替:

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

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

或使用现代 Android Gradle 插件

buildTypes {
    releaseSomeBuildType {
        ...
        proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'your-proguard-file.pro'
    }
}   

这篇关于使用 proguard 删除日志调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆