During a code audit of a Flutter app, we found that roughly 4% of its Android users were running a build signed with the debug keystore. It was a Flutter release signing bug, and no one had noticed. The build was green, the Play Console accepted the upload, and the app worked. The only symptom was that the signing certificate on those installs wasn't the one the team thought it was.
We're keeping the client anonymous, and we won't pretend we have precise numbers beyond that rough share. This post covers the mechanism, why it slipped through every normal check, and the CI gate we now add to every pipeline we touch.
The setup: three flavors and one fallback
The app had three product flavors (dev, staging, prod) and a standard release build type. Signing was configured in android/app/build.gradle roughly like this:
signingConfigs {
release {
keyAlias keystoreProperties['keyAlias']
keyPassword keystoreProperties['keyPassword']
storeFile keystoreProperties['storeFile'] ? file(keystoreProperties['storeFile']) : null
storePassword keystoreProperties['storePassword']
}
}
buildTypes {
release {
signingConfig signingConfigs.release
}
}
flavorDimensions "env"
productFlavors {
prod {
dimension "env"
signingConfig signingConfigs.release
}
staging {
dimension "env"
signingConfig signingConfigs.debug
}
}
That looks harmless, and it's close to what a lot of Flutter projects accumulate. Someone added the staging flavor with signingConfigs.debug so QA builds would install without keystore setup. The release build type was already pointing at the real key, so nobody thought about precedence.
Precedence is the trap. In the Android Gradle Plugin, a flavor-level signingConfig overrides the build type's, not the reverse. For any variant that includes that flavor, the debug key wins, regardless of whether the build type is release. AGP doesn't warn about this. The variant stagingRelease is a valid, fully optimized, debug-signed artifact.
How it reached users
The Flutter release signing bug alone wouldn't have shipped anything. It needed a second, boring mistake. The release workflow had been copy-pasted from an older setup, and its build step was:
flutter build appbundle --release --flavor ${{ inputs.flavor || 'staging' }}
The default was staging, left over from when the pipeline was only used for internal distribution. When a manual dispatch left the input blank, which happened on a hotfix run, the pipeline built stagingRelease, signed it with the debug key, and uploaded it.
The upload succeeded for a specific reason. The app used Play App Signing, so Play re-signs what users download with the app signing key. But the upload key check is separate, and the team had at some point registered the debug certificate as an additional upload key while troubleshooting an unrelated issue. That registration made the bad upload valid. We won't claim every setup is this exposed, because your Play configuration changes the blast radius. But "Play would have rejected it" is an assumption, not a guarantee, and it was wrong here.
Direct APK distribution is worse. Anything sideloaded, distributed through an MDM, or hosted on a download page carries the signing certificate you built it with. A debug certificate means anyone with the default Android debug keystore, which is publicly known to be generated with a predictable path and password on every dev machine, can produce an update that installs over yours.
Why nothing caught it
- The build passed. A debug-signed release is not a build error. Gradle did exactly what the config said.
- The app worked. Signing doesn't change runtime behavior, so QA saw nothing.
- Code review missed it. The flavor block was added in one PR and the workflow default in another, months apart. Neither diff looked wrong alone.
- The version looked right.
versionCodeincremented correctly, so release notes and dashboards were consistent.
We found it by running apksigner verify --print-certs against an artifact pulled from CI and noticing the certificate subject was CN=Android Debug. That's a ten-second check, and it should have been in the pipeline from day one.
The CI check that now blocks it
We added two assertions after the build and before any upload step. The first checks the certificate, the second checks that the artifact is what the pipeline thinks it is.
1. Verify the signature
APK=build/app/outputs/flutter-apk/app-prod-release.apk
apksigner verify --print-certs "$APK" | tee certs.txt
if grep -qi "CN=Android Debug" certs.txt; then
echo "Debug-signed artifact. Failing." >&2
exit 1
fi
ACTUAL=$(grep "SHA-256 digest" certs.txt | head -1 | awk '{print $NF}')
[ "$ACTUAL" = "$EXPECTED_CERT_SHA256" ] || { echo "Cert mismatch"; exit 1; }
The deny-list on CN=Android Debug catches the known failure. The pinned SHA-256 of the expected release certificate, stored as a CI variable, catches the unknown ones, such as the wrong key, a rotated key nobody announced, or a different debug keystore on the runner. Pinning is the stronger check, and the deny-list gives a clearer error message.
2. Assert the manifest
aapt2 dump badging "$APK" | grep -q "package: name='com.example.app'" \
|| exit 1
aapt2 dump xmltree "$APK" --file AndroidManifest.xml \
| grep -q "debuggable" && { echo "debuggable flag set"; exit 1; }
This confirms the package ID matches the production application ID, with no flavor suffix such as .staging, and that android:debuggable isn't set. A debug-signed artifact and a debuggable one often travel together, and either is a release blocker.
We also removed the default from the workflow. The flavor input is now required, and the job fails on an empty value. A default that silently picks the least-protected variant is a bug waiting for a busy day.
Fixing the Gradle config
The root fix is to stop assigning signingConfigs.debug at the flavor level. Put signing on the build type and let non-production flavors use a separate, explicitly named config:
- Define
signingConfigs.qabacked by a committed, low-value keystore for internal builds. - Make
releasefail loudly if the keystore properties are missing, instead of falling back tonulland then to debug. Throw aGradleExceptionin thereleasesigning block whenstoreFileis absent. - Remove Play upload-key registrations you can't explain.
The loud failure matters most. Many Flutter templates and Stack Overflow answers use a ternary that falls back quietly. That's convenient on a laptop and dangerous in CI, where nobody is watching the console.
What to take from it
None of this is exotic, which is why it's worth writing down. Flutter hides the Gradle layer well enough that teams stop looking at it, and signing config is exactly the kind of file that gets edited once and trusted forever. If you ship Android builds, run apksigner verify --print-certs on your last release artifact today. It takes a minute, and the answer is either reassuring or very useful.
At orithLabs, this kind of review is a regular part of our code audit and architectural troubleshooting work. We read the Gradle files, the workflows, and the Play configuration together, because failures like this one sit in the gaps between them. If you'd like a second pair of eyes on your pipeline, you can talk to the engineers directly.