debuggable=true in a release Android app: how to remove the flag
Why the debuggable attribute must stay off in a release build, where it comes from, the Gradle setting that controls it, and the commands that prove the flag is gone from the APK.
Why the debuggable attribute must stay off in a release build, where it comes from, the Gradle setting that controls it, and the commands that prove the flag is gone from the APK.
The report line looks like this: debuggable=true in release manifest, category manifest, severity medium. APKSonar raises it when the decoded manifest of the package contains android:debuggable="true". The Android documentation defines the attribute as the answer to whether the application can be debugged, even when it runs on a device in user mode. The default value is false. A release build with the flag on is a debug build that reached the store.
Debugging a process means reading its memory and data while it runs: sessions, tokens, everything the app holds. On a release build that is exactly what the flag permits.
AndroidManifest.xml, often to attach a debugger to a "release-like" build once.The build system normally sets this attribute without any help: on for the debug build type, off for release. An explicit attribute in the source manifest is the usual reason it turns up where it should not.
Step 1. Find every place that mentions the attribute:
grep -rn "android:debuggable" --include="AndroidManifest.xml" .Step 2. Delete the attribute from the source manifests. Leave the decision to the build types.
Step 3. Declare the build types. The documentation names the debuggable flag for Groovy and isDebuggable for the Kotlin script:
android {
buildTypes {
debug {
isDebuggable = true
}
release {
isDebuggable = false
}
}
}In Groovy the same block reads debuggable false inside the release build type.
Step 4. Rebuild the artifact you publish, with the release task of the module. Check that the release build type is signed with the release keystore.
Decode the manifest of the built APK and search for the attribute:
jadx -s -d out app-release.apk
grep -n "debuggable" out/resources/AndroidManifest.xmlThe flag -s skips the sources. The expected result is no output at all, or a line with android:debuggable="false". The SDK tool apkanalyzer manifest print app-release.apk prints the same manifest in XML format. The last check is the scan: upload the rebuilt APK and the finding is gone from the report.
One line in the release pipeline stops the next regression. It goes after the build and before the upload to the store:
apkanalyzer manifest print app-release.apk \
| grep -q 'android:debuggable="true"' \
&& { echo "debuggable in release manifest"; exit 1; }The same pattern guards the cleartext flag. How to decode the manifest without the SDK tools is shown in the jadx guide.
Frequently asked
It removes the finding in that one file. The build types are the better place: the debug variant needs the flag on, the release variant off, and Gradle sets the attribute for each of them. One hard-coded value has to serve both variants and fails at that.
No. R8 renames classes and methods in the code. It does not stop a debugger from attaching to a process whose manifest says debuggable.
The two findings often come together. A build that kept the debug flag is frequently a debug variant that was published by mistake, and a debug variant is signed with the debug keystore. Fix the build variant and both lines disappear.
Keep the flag in the debug build type, where it belongs. Instrumented tests run against the debug variant. The release artifact that goes to the store is built without it.
From other categories