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
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章