Therefore, it used to be possible to force debug mode on or off by setting it true or false in the manifest file: Being set true to allow the app to be debugged in the IDE, and set to false to turn off debugging when the final Android app's APK was generated. Usually the android:debuggable attribute was not present, it was set automatically by the build tools. The debug bit used to be set via the android:debuggable attribute on the application element in AndroidManifest.xml (use the Studio Project explorer to find AndroidManifest.xml). To use it in code perform a boolean And on flags with ApplicationInfo.FLAG_DEBUGGABLE, if the result is not zero the app is in debug mode ( getApplicationInfo() is available from Context): boolean InDebug=(getApplicationInfo().flags & ApplicationInfo.FLAG_DEBUGGABLE)!=0 The Old Way of Overriding the Android Debug Flag With ApplicationInfo the flags field has a debug bit. When entering code in Studio add import statements when prompted by pressing Alt-Enter.) Android Debug vs Release Using ApplicationInfo Flags
The example code can be changed to meet your own requirements. This article assumes that the latest Android Studio is installed, a basic app can be created and run (here called Check Debuggable), and the code in this article can be correctly copied into Android Studio. (For this Android tutorial try the given code in a simple app. To detect Android debug vs release mode there are two objects that expose the debug flag, the ApplicationInfo class (since API Level 1) and BuildConfig (subsequent SDK releases). It is possible to wrap calls to logging code, and StrictMode set up, in code that checks for debug mode. This article contains example code to show how debug mode and release mode can be determined at app runtime.ĭistinguishing Android Debug Mode Vs Release Mode
When developing an Android app there are occasional times when detecting debug mode vs release mode is helpful. In release mode any debug logging, StrictMode, and the debugging option must be disabled. The app will execute in release mode when installed from Google Play.
while running in the Android Studio Integrated Development Environment (IDE). Android Debug Vs Release Build Check in Running CodeĪn Android app will execute in debug mode in the development environment, i.e.