I have Android debuggable set to false, yet the condition true. What is wrong here?
Application:
//debugable false or true, nothing changes
if ((applicationFlags & ApplicationInfo.FLAG_DEBUGGABLE) != 0) {
Log.d(TAG, "debugable");
}
Manifest:
<application android:debuggable="false" ...
The answer to this very question is already given on SO.
See Android 'debuggable' default value.
.
Declaring your application as "debuggable" in your Android Manifest enables you to debug your Android applications on an Android-powered device , just as you would on the emulator
When using Eclipse, running your app directly from the Eclipse IDE automatically enables debugging.
If you manually enable debugging in the manifest file, be sure to disable it before you build for release (your published application should usually not be debuggable).
The debuggable flag in the manifest gets changed automatically, you can remove it completely, which is also recommended by Google.
If you debug your application, the flag is true. If you export the applicaton, the flag is false.
Related
When I try to use profiler in Android Studio, I am able to see my connected device but I am getting "No debuggable process" in the Profiler. Can someone please help me why i am getting "No debuggable process".
You can try any/all of the following:
Invalidating cache and restarting your Android Studio: To do this, from the menu bar select File > Invalidate Caches / Restart
Restart your phone
Disable and enable USB debugging
Restart your computer
You can also check if your app is marked as debuggable in build.gradle. To do this, just go to your app-level build.gradle file, and under buildTypes check if the debuggable property is set to false, if yes change it to true. Something like:
buildTypes{
release {
debuggable false
}
debug {
debuggable false
}
}
Alternatively, to do the same you can also do it the old way by adding the following line to your Manifest file under the Application tag:
android:debuggable="true"
This should fix it.
I am trying to launch my application in debug mode by using the little debug icon on the right of the run icon. i assumed this is the way to start debug mode.
The problem is that i am checking BuildConfig.DEBUG to see if i am in debug mode but it's always true and when i want to check in generated build.config file i found : public static final boolean DEBUG = Boolean.parseBoolean("true");
My question is : am i doing something wrong in launching debug? is it not the way we do it? how can i use debug mode?
You're confusing debugging with a debug build.
BuildConfig.DEBUG is an indication of whether or not your app is a debug build or a release build, it doesn't have anything to do with launching the app to debug. Even launching the app by just running it will also have BuildConfig.DEBUG as true, because it's still a debug build, this will only change once you actually create a signed release.
The icon you're referring to attaches the android debugger to the process, allowing you to use breakpoints, but it generates the same output as it would by simply running the app as well.
BuildConfig.DEBUG will only be false once you create a signed release build, so it has nothing to do with launching the app to debug
Thanks to Adam Burley's comment that lead me to figure out why my build always had BuildConfig.DEBUG = true, even when doing a signed release build.
If you have either of the following set for a buildType in your build.gradle:
testCoverageEnabled true
debuggable true
Then your DEBUG value will be true for that buildType, no matter if it's a signed release build or not.
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?
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).
"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
By default, when I change Build Variants to release I don't get any Logs on the logcat, but I do need to read release logs of my app, how can I enable this?
Add android:debuggable="true" (default is false) to your Manifest inside the <application> tag.
From the docs:
android:debuggable
Whether or not the application can be debugged,
even when running on a device in user mode — "true" if it can be, and
"false" if not.
respectively
You can disable debugging by removing the android:debuggable attribute
from the tag in your manifest file, or by setting the
android:debuggable attribute to false in your manifest file.
Edit
You may need to add the following to your build.gradle file inside the android{...} tag:
lintOptions {
checkReleaseBuilds false
}
And as a side-note: Right on the device the Logs are always written, no matter if your application's debuggable is set to false or true. But via the LogCat in Android Studio it's only possible if debuggable is set to true. (Just tested this)
You should add
android {
buildTypes {
release {
debuggable true
In this case you can use Log. or System.out.println and see logs.
If you cannot run release version (app is disabled), and error is shown: "apk is not signed. Please configure the signing information for the selected flavor using the Project Structure dialog", see app-release-unsigned.apk is not signed.
I do not like the other solution because then you are not testing how the App really is deployed.
A better solution is to open the Android Device Monitor where you can see the logs even when in release configuration with debuggable=false.
Find it here:
Tools -> Android -> Android Device Monitor
Update:
Android Device Monitor was removed in Android Studio 3.2. However, it is still present in SDK, and you can use it to see the logs (it is located in $ANDROID_SDK/tools/)
debuggable true in build.gradle works well, except that BuildConfig.DEBUG is also going to be true. This might be a problem if your app relies on BuildConfig.DEBUG to do something only when it's a debug build.
In such a case, try Log.wtf(BuildConfig.APPLICATION_ID, "something went wrong"), which will print to logcat even if it's a release build.
This approach will obviously help you to get logs while testing the production build. But be careful while uploading your app to Google Play Store, Toggle debuggable to false before uploading to production.
buildTypes {
debug {
manifestPlaceholders = [crashlyticsCollectionEnabled: "false"]
}
release {
manifestPlaceholders = [crashlyticsCollectionEnabled: "false"]
lintOptions {
checkReleaseBuilds false
abortOnError false
}
shrinkResources true
minifyEnabled true
debuggable true
signingConfig signingConfigs.productionrelease
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
set crashlyticsCollectionEnabled to false to avoid your crashes to report to Google Play-Store while debugging.
I am trying to get application's debuggable attribute value from code:
packageInfo = context.getPackageManager().getPackageInfo(packageName, 0);
int flags = packageInfo.applicationInfo.flags;
isDebugMode = (flags & ApplicationInfo.FLAG_DEBUGGABLE) != 0;
And I have noticed that when debuggable attribute is not specified in manifest this code defines it as true. And documentation says that it is false by default.
What's wrong?
From SDK Tools : ( SDK Tools, Revision 8 (December 2010) )
Support for a true debug build.
Developers no longer need to add the
android:debuggable attribute to the
<application> tag in the manifest —
the build tools add the attribute automatically. In Eclipse/ADT, all
incremental builds are assumed to be
debug builds, so the tools insert
android:debuggable="true". When
exporting a signed release build,
the tools do not add the attribute.
In Ant, a ant debug command
automatically inserts the
android:debuggable="true" attribute,
while ant release does not. If android:debuggable="true" is manually
set, then ant release will actually do
a debug build, rather than a release
build.