简体   繁体   English

Android调试/发布版本的应用程序

[英]Android debug / release version of application

I have one question about finding if your application is in release mode or in debug. 我有一个问题要查找您的应用程序是处于发布模式还是调试状态。 I need to find a way to detect the applications mode automatically with a function. 我需要找到一种通过功能自动检测应用程序模式的方法。 For now I'm using a simple way declaring a boolean which everytime I have to change true/false . 现在,我正在使用一种简单的方法来声明一个boolean ,每次我必须更改true/false But sometimes me, or the other developer may forget to change it. 但是有时候,我或其他开发人员可能忘记更改它。 Actually I need this because, I'm using an error handler in my app which is sending to our server exceptions which are uncaught. 实际上,我需要这样做是因为,我在我的应用程序中使用了一个错误处理程序,该错误处理程序会将未捕获的异常发送到我们的服务器。 And I don't want to do this in debug mode. 而且我不想在调试模式下执行此操作。

So is there any way I can detect this with some functions which my app will do automatically, without using any variables like I do? 那么,有什么方法可以使用我的应用程序将自动执行的某些功能检测到此情况,而无需像我一样使用任何变量?

There is no general solution but you may use isDebuggerConnected . 没有通用的解决方案,但是您可以使用isDebuggerConnected

BUT this solution would also trigger/show the debug features if your users connect their phones to the PC and uses ddms themselves. 但是,如果您的用户将手机连接到PC并自己使用ddms,则此解决方案还将触发/显示调试功能。

Maybe you sould combine this with one of the checks Aleks G suggested, and popup a Toast-message on every start that reminds you to disable debug ;-) 也许您将这与Aleks G建议的一项检查结合在一起,并在每次启动时弹出Toast消息,提醒您禁用调试;-)

Why not use this? 为什么不使用这个?

if (BuildConfig.DEBUG) {
    // what shall happen in debug version
} else {
    // release version
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在Android中发布和调试应用程序的版本。 两张证书 - Release and debug version of the application in Android. Two certificates Android运行时错误,发布版本,但不是调试版本 - Android runtime error with release version but not debug version 如何在Android设备上管理调试和发布版本? - how to manage debug and release version on android device? Android Studio:运行/调试应用程序的发布版本 - Android Studio: run/debug release version of app Android应用程序的发布 - 调试版本 - Release-Debug Builds for Android Application Yelp API搜索在Android调试版本中有效,但在发行版本中无效 - Yelp API search working in Android debug version but not in release version Android Studio - Google Maps API 适用于调试版本,但不适用于发布版本 - Android Studio - Google Maps API works for debug version but not for release version 应用程序发行版上的Android Altbeacon库BeaconSimulator - Android Altbeacon Library BeaconSimulator on release version of application android studio调试版本运行良好,但发行版本崩溃 - android studio debug variant runs well but release version crashing Android Retrofit:发布版和调试版都响应200,但发布版返回空值 - Android Retrofit: Response 200 in both release and debug version but release version have empty value returned
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM