更新时间:2023-11-14 19:09:22
有没有(默认)任何preprocessor的Java,所以没有的#ifdef
的东西在编译时间。但是,如果你不介意离开调试code。在您的应用程序,那么你可以检查,如果应用程序是在运行时使用这个code释放或调试:
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);
它检查可调试
标志值。并表示FLAD自动设置为假
的发布版本和真
的调试版本。
which checks debuggable
flag value. And said flad is automatically set to false
for release builds and true
for debug builds.
如果你想摆脱一些调试code,你可以尝试使用ProGuard的剥离某些类或方法。并且默认ProGuard的参与建设过程中仅释放版本。
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.