Release-Debug Builds for Android Application

前端 未结 5 735
一生所求
一生所求 2021-01-04 21:22

In C++ I would normally setup 2 builds - debug and release with each having DEBUG and RELEASE predefined respectively. I would then use these defin

5条回答
  •  不知归路
    2021-01-04 21:52

    There's no (by default) any preprocessor for Java, so no #ifdef stuff at compile time. But if you do not mind leaving debug code in your app, then you can check if app is release or debug at runtime with this code:

    Boolean release = (getApplicationInfo().flags & ApplicationInfo.FLAG_DEBUGGABLE);
    

    which checks debuggable flag value. And said flad is automatically set to false for release builds and true for debug builds.

    If you want to get rid of some debug code, you may try using ProGuard to strip certain classes or methods. And by default ProGuard is involved in building process for release builds only.

提交回复
热议问题