Short of diligently commenting out the numerous Log.v() and Log.d() statements I planted throughout an app I have written, is there a more elegant/efficient way of compiling an app to a "release mode", so that my LogCat messages don't show up?
Logcat is a command-line tool that dumps a log of system messages, including stack traces when the device throws an error and messages that you have written from your app with the Log class. This page is about the command-line logcat tool, but you can also view log messages from the Logcat window in Android Studio.
Prevent clearing the log when the app crashes By default when the app got crashed the logcat clear's in the android studio. To prevent this, click the right end chooser(Filter Configuration chooser) in the logcat tab then select Edit Filter Configuration option and enter current app name and package name.
The Logcat window in Android Studio displays system messages, such as when a garbage collection occurs, and messages that you added to your app with the Log class. It displays messages in real time and keeps a history so you can view older messages.
Please check this thread : How do I enable/disable log levels in Android?
Using the latest Android Studio 2.1.3 at this moment, I followed the steps below:
Add the lines below in proguard-rules.pro
-assumenosideeffects class android.util.Log {
*;
}
Edited build.gradle of app module. minifyEnabled has to be set to true to activate proguard. proguard-android-optimize.txt has to be used, in order to allow optimisations in proguard-rules.pro to run.
buildTypes {
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
signingConfig signingConfigs.config
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With