在发布的 Android 应用程序中完全禁用 LogCat 输出? [英] Disable LogCat Output COMPLETELY in release Android app?

查看:62
本文介绍了在发布的 Android 应用程序中完全禁用 LogCat 输出?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在向市场发布应用之前关闭我自己的应用的 LogCat 输出很简单.我也知道如何通过标签和/或 ID 有选择地过滤 LogCat 消息,以方便我自己的调试.

Shutting off my own app's LogCat output before releasing an app to the market is straightforward. I also know how to selectively filter LogCat message by tag and/or id for my own debug convenience.

但现在我对一些更困难的事情感兴趣(也许不可能?):禁用所有 LogCat 输出,包括 &尤其是来自 TtsService、GoogleLoginService 等 3rd 方服务的那些.

But now I am interested in something that may be much more difficult (perhaps impossible?): Disable all LogCat output, including & especially those coming from 3rd-party services like TtsService, GoogleLoginService, etc.

这可能吗?

进一步澄清:我有兴趣为自己过滤消息.我对为从 Android Market 下载我的应用程序的任何人禁用 3rd-party 消息很感兴趣.这可能吗?

To further clarify: I am not interested in filtering out messages for myself. I am rather interested in disabling 3rd-party messages for whoever downloads my app from the Android Market. Is this possible?

推荐答案

您可以使用 ProGuard 通过告诉 ProGuard 假设不会有任何问题,完全删除任何不使用返回值的行.

You can use ProGuard to remove completely any lines where a return value is not used, by telling ProGuard to assume that there will be no problems.

以下 proguard.cfg 块指示删除 Log.d、Log.v 和 Log.i 调用.

The following proguard.cfg chunk instructs to remove Log.d, Log.v and Log.i calls.

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

最终结果是这些日志行不在您的发行版 apk 中,因此任何使用 logcat 的用户都看不到 d/v/i 日志.

The end result is that these log lines are not in your release apk, and therefore any user with logcat won't see d/v/i logs.

这篇关于在发布的 Android 应用程序中完全禁用 LogCat 输出?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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