Reputation: 2416
I'm looking for a way to tell if my app is running under the debugger or running "normally", under Android Studio..
These two cases are
1. Run the app by clicking the "Run app" button (green arrow)
2. Run the app by clicking the "Debug app" button (gear icon)
I would like to output more verbose diagnostics (using Log.*) while debugging.
I tried checking BuildConfig.DEBUG but that is TRUE in either case. I suspect this is because Android Studio signs the app with the Debug Certificate in both cases.
Does anyone know how to distinguish these two cases at runtime?
Upvotes: 2
Views: 1309
Reputation: 76859
typically one would check for BuildConfig.DEBUG
(or a boolean
variable holding it) and then log:
if(BuildConfig.DEBUG) {Log.d("SomeActivity", "debug message");}
see the documentation... most relevant for debugging is build-config debuggable
true/false
.
the run
button does not start the debugger; no matter the build-config (it just skips all breakpoints).
in multi-module projects, one should check with:
(getContext().getApplicationInfo().flags & ApplicationInfo.FLAG_DEBUGGABLE) != 0
to tell them apart, two build types need to be configured:
android {
...
buildTypes {
debug {
...
renderscriptDebuggable true
jniDebuggable true
debuggable true
}
release {
...
renderscriptDebuggable false
jniDebuggable false
debuggable false
}
}
}
and to precisely answer the question, there even is one method called isDebuggerConnected(), which would always return false
when hitting the run
button (no matter the build-config).
Upvotes: 3
Reputation: 384
"Run app"
This will install the application into your device/emulator
"Debug app"
This will enable you to debug function by placing the break points into your code. which means you will be able to stop execution of code at that point and debug it line by line. To know more about debugging in android see this
Both the application are debug applications. To know more about build type please read this
Upvotes: 0