Android hide logs in the application when upload t

2019-03-31 21:16发布

My application has lots of Log.i(); statements added for debugging. Now if such an application need to be uploaded to market

  1. Should these logs be removed, and if yes is there an easy way than manual removal

  2. If not removed, will those logs be coming if the application is run by the user after installing from the market

( i tried to see the logs for some applications and i couldnt see any logs from the applications. I could see only android logs like from activity manager . But i dont see why the logs will not be displayed if they are not removed from the code)

2条回答
乱世女痞
2楼-- · 2019-03-31 22:09

Yes, a good practice is to remove all the log methods called during testing,

And yes when the user downloads the application it would show all the logs to him/her that you made.

What you can do is Create a static Class with static method in that class,

when ever you want to make a log call simply call that method from anywhere by ClassName.Method

And once you are finished with testing simply COMMENT the Definition in the static method written in the Static class.

查看更多
来,给爷笑一个
3楼-- · 2019-03-31 22:13

Preetha, the logs will be kept on the phone and any user/developer can check them out by installing apps like Catlog even without using adb! This is a problem as you stand to give unnecessary and at times, confidential data to users/other developers.

Simple way to solve this?

a. Use Proguard to automatically block all logs, more information in this stackoverflow thread

Here you can automatically block all logs at the bytecode level in Proguard

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

The above, for example would remove any verbose logging, more in this thread

b. I use a if(DEBUG) Log.i for all my logs, so that with one change of the boolean DEBUG i can switch on/off all logs

c. A trivial solution: replace all Log.i with //Log.i :)

查看更多
登录 后发表回答