问题描述
我正在尝试使用 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 删除日志调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!