My log messages are not deleted using proguard configuration

I am developing an Android application.

Then I turn on and configure proguard with:

Step 1. Enable proguard:

In project.properties I have:

proguard.config=${sdk.dir}/tools/proguard/proguard-android-optimize.txt:proguard-project.txt 

I also tried the following:

 # To enable ProGuard to shrink and obfuscate your code, uncomment this (available properties: sdk.dir, user.home): proguard.config=proguard.cfg 

Step 2. Configure proguard:

In proguard.cfg I have:

 -assumenosideeffects class android.util.Log { *; } 

I think the above configuration should remove all the logs.

But when I install the APK in the target/ folder and run my application, I still see all the log messages in the logcat console. Why?

+6
source share
3 answers

You should use the first line in project.properties :

 proguard.config=${sdk.dir}/tools/proguard/proguard-android-optimize.txt:proguard-project.txt 

Then you should add these lines to proguard-project.txt (not deprecated proguard.cfg):

 -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(...); } 

These options are effective only if the file does not contain -dontoptimize.

Ant, and Eclipse selects settings from project.properties. Gradle and Maven require equivalent settings that define configuration files in build.gradle and in pom.xml, respectively.

Related questions and answers:

+9
source

I can’t remember where I found a link to this method, but I always used this:

 -assumenosideeffects class android.util.Log { public static *** d(...); public static *** v(...); } 

in my configuration. It removes debug and verbose logging that I wrote

+1
source

You can create your own log utility class and use it,

What I do when I release my applications: I create my own log class using methods i, d, e, w, etc. and use this log class instead of Android, because then I can use a simple switch , such as boolean debug = true , according to which I write LogCat , or not. That way, I can leave all my log statements in the application. When you wrote your own journal class to use it throughout your application, you can simply replace everything,

Delete:

 import android.util.Log; 

Add

 import your.package.Log; 

Like this:

  public class Log { public static void i(String logTag, String logString) { if (isLogsEnabled) { Log.i(logTag, logString); } } public static void v(String logTag, String logString) { if (isLogsEnabled) { Log.v(logTag, logString); } } // you can add method for w,d,wtf also... } 

Logging is a very convenient debugging and diagnostic method used by developers. Use the logging class provided as part of the Android SDK to register important information about your application with LogCat, but before publishing, make sure you look at the application implementation, as the log has performance flaws.

Before launching the application, carefully review the log so that it does not use any sensitive data,

The log is very important, when your application is in test mode, the logs will provide the current status and script of your application on the current device. Therefore, it is very useful when updating your application.

Once a Google game rejected your application if they were found that your logging mechanism was breaking the rules.

0
source

All Articles