Remove Logging with Proguard
a change in the build.gradle, replacing the default proguard-android.txt with proguard-android-optimize.txt did the trick.
buildTypes {
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
...
Note: the default proguard setting in gradle is proguard-android.txt
How to configure proguard to ONLY remove android logging calls
You can remove logging calls with this option in proguard-project.txt
:
-assumenosideeffects class android.util.Log {
public static boolean isLoggable(java.lang.String, int);
public static int v(...);
public static int i(...);
public static int w(...);
public static int d(...);
public static int e(...);
}
This option is only relevant if optimization is not disabled, like in proguard-android.txt
. You have to specify proguard-android-optimize.txt
instead, in project.properties
:
proguard.config=${sdk.dir}/tools/proguard/proguard-android-optimize.txt:proguard-project.txt
You can disable shrinking and obfuscation if you wish. You can also preserve the internal API of your application from optimization if you wish:
-keep class myapp.** { *; }
Disabling these steps and keeping all code of course isn't optimal from a ProGuard point of view.
Remove logs using proguard doesn't work
With help of Guardsquare support I've been able to find out problem. One of libraries has -dontoptimize in its ProGuard config file. Helpful to narrow down this issue is option -printconfiguration [filename]
Doc. for ref - https://www.guardsquare.com/en/products/proguard/manual/usage#generaloptions
Remove all debug logging calls from third-party lib/sdk (Proguard is not working)
ProGuard will only be able to remove logging calls in application code, i.e. code that is being processed and included in your own application. Any logging calls being performed by the Android runtime cannot be removed because the runtime is installed on each device and cannot be modified in advance obviously.
Looking at your rules and gradle file, the setup looks correct and also works for me to remove calls to android.util.Log
. Ensure that you are using a recent version of ProGuard (e.g. 5.2.1 or later). Also you have ProGuard still disabled in your release
buildType, you will need to set minifyEnabled
to true
to enable it.
Using R8 and proguard to remove logging, but turn off everything else
Please remove debuggable true line from release block that's why you are seeing logs in build.
Removing logging with ProGuard doesn't remove the strings being logged
Your solution with different methods for different numbers of arguments is probably the most convenient one. A single method with a variable number of arguments would be nicer, but the current version of ProGuard is not smart enough to remove all the unused code.
The java compiler compiles a variable number of arguments as a single array argument. On the invocation side, this means creating an array of the right size, filling out the elements, and passing it to the method. ProGuard sees that the array is being created and then being used to store elements in it. It doesn't realize (yet) that it then isn't used for actual useful operations, with the method invocation being gone. As a result, the array creation and initialization are preserved.
It's a good practice to check the processed code if you're expecting some particular optimization.
Related Topics
Extending Application to Share Variables Globally
Android Fragment Lifecycle Over Orientation Changes
How to Enable Logging for Apache Commons Httpclient on Android
"Unable to Locate Adb" Using Android Studio
Execution Failed for Task 'App:Mergedebugresources' Crunching Cruncher....Png Failed
What's the Android Adb Shell "Dumpsys" Tool and What Are Its Benefits
Install_Failed_Duplicate_Permission... C2D_Message
Setuservisiblehint Called Before Oncreateview in Fragment
Is There a Better Way to Refresh Webview
Android Navigation Drawer Toggle Icon to Right
What Is the Real Android Studio Gradle Version
How to Catch Sigsegv (Segmentation Fault) and Get a Stack Trace Under Jni on Android
Enable/Disable Zoom in Android Webview
How to Set Relativelayout Layout Params in Code Not in Xml
How to Display Progress Dialog Before Starting an Activity in Android
Difference Between Onstart() and Onresume()
Android Webview Style Background-Color:Transparent Ignored on Android 2.2