My log messages are not removed with proguard configuration

烂漫一生 提交于 2019-12-04 05:33:19
Eric Lafortune

You should use the first line in your project.properties:

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

You should then add these lines to your proguard-project.txt (not the 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 only have any effect if the file does not contain -dontoptimize.

Ant and Eclipse pick up the settings from project.properties. Gradle and Maven require equivalent settings that specify the configuration files, in build.gradle and in pom.xml respectively.

Similar questions and answers:

I can't remember where I found the reference to this method, but I've always used this:

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

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

You can create your own Log utilit class and use it,

What I do when I release my apps is: I create my own Log class with methods i, d, e, w etc and use this Log class instead of the Android one, because then I can use a simple switch like boolean debug = true according to which I write to the LogCat or don't. That way I can leave all my log statements in the app. When you've written your own Log class, to use it all over your app, you can simply replace all,

Remove:

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 handy debugging and diagnostic technique used by developers. Use the logging class provided as part of the Android SDK to log important information about your application to LogCat, but make sure you review your application’s logging implementation prior to publication, as logging has performance drawbacks.

Before releasing your application Review your log carefully so its doesn't leek any confidential data,

Log is very important whenever your application in testing mode, Logs will provide you current state and scenario of your application on current device. So its very helpful whenever you will update your application.

Sometime Google play reject your application if they was found your Logging mechanism violate the rules.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!