buildconfig.java debug_ADT何时将BuildConfig.DEBUG设置为false?

I would want to propose a simple workaround if you use proguard during APK export.

Proguard provides a way to remove calls to specific functions in release mode. Any calls for debugging logs can be removed with following setting in proguard-project.txt.

# Remove debug logs

-assumenosideeffects class android.util.Log {

public static *** d(...);

public static *** v(...);

}

And optimization setting in project.properties.

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

With this, you don't need to concern any unnecessary String computation passing to debug log to which @Jeremyfa pointed. The computations are just removed in release build.

So the workaround for BuildConfig.DEBUG uses the same feature of proguard like following.

public class DebugConfig {

private static boolean debug = false;

static {

setDebug(); // This line will be removed by proguard in release.

}

private static void setDebug() {

debug = true;

}

public static boolean isDebug() {

return debug;

}

}

And following setting in proguard-project.txt.

-assumenosideeffects class com.neofect.rapael.client.DebugConfig {

private static *** setDebug();

}

I would prefer using this to disabling the Build Automatically option, because this doesn't depend on the builder's individual IDE setting but is maintained as committed file which are shared among developers.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值