remove logging from release apk file using gradle

时间:2015-11-12 10:46:52

标签: android gradle

I am trying to remove logging from the release apk file. I followed the advice of using BuildConfig.DEBUG variable, which will be true for debug builds and false otherwise.

In a Constants file, I have:

public static final LOG_ENABLED = BuildConfig.DEBUG;

And then I check the variable before logging.

if(Constants.LOG_ENABLED){
   // print Log
}

Then, in the gradle build file, I have added android

{ buildTypes { release { minifyEnabled true shrinkResources true } } } . I then ran gradle assembleRelease, but the logging still remains inside the apk file?

Can someone kindly show me the error of my ways?

1 个答案:

答案 0 :(得分:0)

Ciao

很抱歉参加晚会,但是:

  • 现在通常我会选择this solution
  • 在您的代码段中,我认为您可能必须明确使用boolean类型:

    public static final boolean LOG_ENABLED = BuildConfig.DEBUG;

使其正常工作,如以下其他答案:[1],[2]

希望有帮助

祝你有美好的一天,
安东尼诺