在Android的调试日志,在运行时真的剥离? [英] are Android's debug logs really stripped at runtime?

查看:184
本文介绍了在Android的调试日志,在运行时真的剥离?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Android的文件(<一href="http://developer.android.com/reference/android/util/Log.html">http://developer.android.com/reference/android/util/Log.html )说:

Android documentation ( http://developer.android.com/reference/android/util/Log.html ) says:

冗长不应该被编译成不同的开发过程中的应用程序。调试日志编译,但在运行时剥离。错误,警告和信息日志始终保持

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

我只是做了一个测试。在我的活动我写了:

I just did a test. In my activity I wrote:

private static String test(String what) {
    Log.e("test", "I am called with argument: " + what);
    return what;
}
@Override
public 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功能,导致其文本被写入日志。

I exported my project as an apk file, then I installed this apk on my phone. I run this application on my phone, then I looked at logs. There I saw that the function test was called all five times and all five calls to Log.something functions resulted in its text being written to logs.

那么,Log.d调用真正在运行时剥离?

So are Log.d calls really stripped at runtime?

推荐答案

这个问题已经提交的这里和溶液中 ADT 17.0.0 提供2012

This issue was reported here and a solution was provided in ADT 17.0.0 in Mar 2012

增加了一个功能,可以让您仅在调试模式下运行一些code。现在建立产生一类叫做BuildConfig包含DEBUG常量,它是根据你的编译类型自动设置。您可以检查(BuildConfig.DEBUG)定在code到运行调试,只等功能。

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的调试日志,在运行时真的剥离?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆