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

前端 未结 27 1489
有刺的猬
有刺的猬 2020-11-22 07:39

According to Google, I must \"deactivate any calls to Log methods in the source code\" before publishing my Android app to Google Play. Extract from section 3 of th

27条回答
  •  长情又很酷
    2020-11-22 08:28

    Christopher's Proguard solution is the best, but if for any reason you don't like Proguard, here is a very low-tech solution:

    Comment logs:

    find . -name "*\.java" | xargs grep -l 'Log\.' | xargs sed -i 's/Log\./;\/\/ Log\./g'
    

    Uncomment logs:

    find . -name "*\.java" | xargs grep -l 'Log\.' | xargs sed -i 's/;\/\/ Log\./Log\./g'
    

    A constraint is that your logging instructions must not span over multiple lines.

    (Execute these lines in a UNIX shell at the root of your project. If using Windows, get a UNIX layer or use equivalent Windows commands)

提交回复
热议问题