Android的调试日志真的在运行时剥离吗?

Android的调试日志真的在运行时剥离吗?,第1张

概述Android文档( http://developer.android.com/reference/android/util/Log.html)说: Verbose should never be compiled into an application except during development. Debug logs are compiled in but stripped at ru Android文档( http://developer.android.com/reference/android/util/Log.html)说:

Verbose should never be compiled into an application except during development. DeBUG logs are compiled in but stripped at runtime. Error,warning and info logs are always kept

我刚刚做了一个测试.在我的活动中,我写道:

private static String test(String what) {    Log.e("test","I am called with argument: " + what);    return what;}@OverrIDepublic voID onCreate(Bundle savedInstanceState) {    super.onCreate(savedInstanceState);    setContentVIEw(R.layout.activity_main);    Log.v("test","log level: " + test("v"));    Log.d("test","log level: " + test("d"));    Log.i("test","log level: " + test("i"));    Log.w("test","log level: " + test("w"));    Log.e("test","log level: " + test("e"));}

我将我的项目导出为一个apk文件,然后我在手机上安装了这个apk.我在手机上运行这个应用程序,然后我看了日志.在那里我看到函数测试被全部五次调用,并且对Log.something函数的所有五个调用导致其文本被写入日志.

那么Log.d调用在运行时是否真的被剥离?

解决方法 这个问题报道了 here,并于2012年3月在 ADT 17.0.0提供了一个解决方案

Added a feature that allows you to run some code only in deBUG mode. Builds Now generate a class called BuildConfig containing a DEBUG constant that is automatically set according to your build type. You can check the (BuildConfig.DEBUG) constant in your code to run deBUG-only functions.

总结

以上是内存溢出为你收集整理的Android的调试日志真的在运行时剥离吗?全部内容,希望文章能够帮你解决Android的调试日志真的在运行时剥离吗?所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1133142.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-30
下一篇 2022-05-30

发表评论

登录后才能评论

评论列表(0条)

保存