Removing Logging from Production Code in Android?
android
Solution
The IMO best solution is to write code like below wherever you call your logging methods.
if (SOME_LOG_CONSTANT) Log.d(TAG, "event:" + someSlowToEvaluateMethod());
By changing 1 constant you strip away every logging that you don't want. That way the part behind `if (false)` should not even get into your .class file since the compiler can completely remove it (it is unreachable code).
This also means that you can exclude whole code blocks from your release software if you wrap them in that `if`. That's something even proguard can't do.
the `SOME_LOG_CONSTANT` can be `BuildConfig.DEBUG` if you use SDK Tools r17 and above. That constant is automatically changed for you depending on build type. Thx @Christopher
Problem
What is the best way to remove logging from production android application. It appears that proguard does not do this completely, strings still get written, so I was wondering what is best solution to remove the logging from production code?