How to remove all debug logging calls before building the release version of an Android app?

问题:

According to Google, I must " deactivate any calls to Log methods in the source code " before publishing my Android app to Google Play.根据 Google 的说法,在将我的 Android 应用程序发布到 Google Play 之前,我必须“取消对源代码中对 Log 方法的任何调用”。 Extract from section 3 of the publication checklist :摘自出版物清单第 3 节:

Make sure you deactivate logging and disable the debugging option before you build your application for release.在构建要发布的应用程序之前,请确保停用日志记录并禁用调试选项。 You can deactivate logging by removing calls to Log methods in your source files.您可以通过在源文件中删除对 Log 方法的调用来停用日志记录。

My open-source project is large and it is a pain to do it manually every time I release.我的开源项目很大,每次发布都手动做很痛苦。 Additionally, removing a Log line is potentially tricky, for instance:此外,删除 Log 行可能很棘手,例如:

if(condition)
  Log.d(LOG_TAG, "Something");
data.load();
data.show();

If I comment the Log line, then the condition applies to the next line, and chances are load() is not called.如果我注释 Log 行,则条件适用于下一行,并且有可能不调用 load()。 Are such situations rare enough that I can decide it should not exist?这种情况是否罕见到我可以决定它不应该存在?

So, is there a better source code-level way to do that?那么,有没有更好的源代码级方法来做到这一点? Or maybe some clever ProGuard syntax to efficiently but safely remove all Log lines?或者也许一些聪明的 ProGuard 语法可以有效但安全地删除所有日志行?


解决方案:

参考一: https://en.stackoom.com/question/AGNc
参考二: https://stackoom.com/question/AGNc
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章