1

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?

Smittey
  • 2,475
  • 10
  • 28
  • 35
Iqbal
  • 11
  • 1
  • seems this will remove the logs for log.d() alone – Priya Nov 12 '15 at 11:26
  • Unfortunately, even the log.d is not being deleted. It seems I'm doing something fundamentally wrong. – Iqbal Nov 12 '15 at 12:59
  • check if this link helps http://stackoverflow.com/questions/9855834/when-does-adt-set-buildconfig-debug-to-false – Priya Nov 12 '15 at 13:15
  • still if you are logging based on a boolean you can set that variable LOG_ENABLED to false before taking release apk – Priya Nov 12 '15 at 13:16

1 Answers1

0
  • in general now I would go with [this solution] 0

  • in your snippet I think you may have to explicit the boolean type:

    public static final boolean LOG_ENABLED = BuildConfig.DEBUG;

to have it working, as in these other answers: [1], [2]

  • historically BuildConfig.DEBUG; has been affected by known issues - also with libraries - and a solution for both Eclipse and Android Studio can be found for example here
Dharman
  • 30,962
  • 25
  • 85
  • 135
Antonino
  • 3,178
  • 3
  • 24
  • 39