我的日志消息不会通过proguard配置删除 [英] My log messages are not removed with proguard configuration

查看:62
本文介绍了我的日志消息不会通过proguard配置删除的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发我的Android应用程序.

I am developing my Android app.

然后启用&通过以下方式配置proguard:

Then I enable & configure proguard by:

第1步.启用proguard:

project.properties 中,我拥有:

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

我还尝试了以下方法:

# To enable ProGuard to shrink and obfuscate your code, uncomment this (available properties: sdk.dir, user.home):
proguard.config=proguard.cfg

第2步.配置proguard:

proguard.cfg 中,我有:

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

我认为上述配置应删除所有日志.

I think the above configuration should remove all logs.

但是当我在target/文件夹&运行我的应用程序,我仍然可以在logcat控制台中看到我的所有日​​志消息.为什么?

But when I install the APK under target/ folder & run my app, I can still see all my Log messages in logcat console. Why?

推荐答案

您应在 project.properties 中使用第一行:

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

然后您应将以下几行添加到您的 proguard-project.txt 中(不是已弃用的proguard.cfg):

You should then add these lines to your proguard-project.txt (not the deprecated proguard.cfg):

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

仅当文件包含-dontoptimize时,这些选项才有效.

These options only have any effect if the file does not contain -dontoptimize.

Ant和Eclipse从project.properties中获取设置. Gradle和Maven需要等效的设置,分别在build.gradle和pom.xml中指定配置文件.

Ant and Eclipse pick up the settings from project.properties. Gradle and Maven require equivalent settings that specify the configuration files, in build.gradle and in pom.xml respectively.

类似的问题和答案:

  • How to config my proguard-project.txt file to remove just Logs
  • Removing Log call using proguard

这篇关于我的日志消息不会通过proguard配置删除的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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