发布-调试版本的Android应用程序 [英] Release-Debug Builds for Android Application
问题描述
在C ++中我通常会设置2建造 - 调试,并与各具有 DEBUG
和发布
$ P $发布分别pdefined。然后我会使用这些定义来确定常量值,如日志启用/禁用,服务器的URL等。
In C++ I would normally setup 2 builds - debug and release with each having DEBUG
and RELEASE
predefined respectively. I would then use these definitions to determine constant values, like logging enabled/disabled, server URL and etc.
现在,用Java / Android的我注释掉一些东西建筑发行之前。这不是一个好办法,我可以告诉。我可能会忘了什么东西。
Right now, in Java/Android I comment out some stuff before building release. That is not a good way, I can tell. I may forget something.
什么是确保没有一个普遍的做法是建立一个发布版本时,忘了(签字)或调试版本(符号)?
What is a common practice for ensuring nothing is forgotten when building a release version (signed) or debug version (unsigned)?
推荐答案
有没有(默认)任何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.
这篇关于发布-调试版本的Android应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!