且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

发布-调试版本的Andr​​oid应用程序

更新时间: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.