Android系统。检测,如果我在释放或调试模式 [英] Android. detect if I am in release or debug mode

查看:112
本文介绍了Android系统。检测,如果我在释放或调试模式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何检测机器人,如果我在释放模式和调试模式?

How can I detect in android if I am in Release mode or Debug mode?

推荐答案

最简单的和最佳的长期解决方案,就是使用 BuildConfig.DEBUG 。这是一个布尔值将是的调试版本,否则:

The simplest, and best long-term solution, is to use BuildConfig.DEBUG. This is a boolean value that will be true for a debug build, false otherwise:

if (BuildConfig.DEBUG) {
  // do something for a debug build
}

有报道称,这个值是不是100%可靠的基于Eclipse的版本,虽然我个人有没有遇到过的问题,所以我不能说有多少的问题,它确实是的。

There have been reports that this value is not 100% reliable from Eclipse-based builds, though I personally have not encountered a problem, so I cannot say how much of an issue it really is.

如果您使用的是Android的工作室,或者如果你是在命令行中使用摇篮,你可以添加你自己的东西,以 BuildConfig 或以其他方式调整的调试发布生成类型,以帮助区分这些情况在运行时。

If you are using Android Studio, or if you are using Gradle from the command line, you can add your own stuff to BuildConfig or otherwise tweak the debug and release build types to help distinguish these situations at runtime.

从非法参数的解决方案是基于 Android的价值:可调试标记在清单中。如果这是你希望如何区分调试建设从释放的身材,然后根据定义,这是最好的解决方案。但是,请记住,展望未来,可调试标记是真正从什么摇篮/ Android的工作室认为调试打造成为一个独立的概念。任何构建类型可以选择设置可调试标记的任何值,它是有道理的,是开发商和为构建类型。

The solution from Illegal Argument is based on the value of the android:debuggable flag in the manifest. If that is how you wish to distinguish a "debug" build from a "release" build, then by definition, that's the best solution. However, bear in mind that going forward, the debuggable flag is really an independent concept from what Gradle/Android Studio consider a "debug" build to be. Any build type can elect to set the debuggable flag to whatever value that makes sense for that developer and for that build type.

这篇关于Android系统。检测,如果我在释放或调试模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆