For eleven days, every Android release of our small Flutter app shipped with ads switched off.
Nothing crashed. No review flagged it. The rewarded-ad button simply was not there, and we only noticed during an audit of what each shipped build actually contained.
The cause was one word in a shell script: ADS="${ADS:-false}". Here is how a sensible default and a sensible guard combined into a silent failure, and the small changes that closed it.
What the build script looked like
Our release scripts take a few switches from environment variables and pass them to Flutter as --dart-defines. Ads were one of them:
ADS="${ADS:-false}" case "$ADS" in true|false) ;; *) echo "ADS must be true|false" >&2; exit 1 ;; esac ADS_DEFINES="" if [ "$ADS" = true ]; then . release/admob.env case "$ADMOB_ANDROID_APP_ID" in *3940256099942544*) echo "Google test ID in a release build" >&2; exit 1 ;; esac ADS_DEFINES="--dart-define=ADS=true --dart-define=ADMOB_ANDROID_APP_ID=$ADMOB_ANDROID_APP_ID ..." fi flutter build appbundle --release $ADS_DEFINES And on the native side, android/app/build.gradle falls back to Google's sample app ID when no ID is passed:
def admobAppId = dartDefines["ADMOB_ANDROID_APP_ID"] ?: "ca-app-pub-3940256099942544~3347511713" In Dart, the feature hangs off the same define:
const bool kAdsBuild = bool.fromEnvironment('ADS', defaultValue: false); Every one of those lines is reasonable on its own.
Why false was the right default once
The ADS switch was added in October, before the app had ads at all. On iOS, an ad build needs NSUserTrackingUsageDescription and SKAdNetworkItems in Info.plist. If those keys ship in a build that declares "Data Not Collected" in App Store privacy details, App Store Connect can reject the submission. So the script only inserted those keys when ADS=true, and false was the safe default. It kept ad-free builds clean.
A week later we prepared the rewarded ad. We added the real AdMob IDs and a check that refuses to build if a Google test ID slips in. That check went inside the if [ "$ADS" = true ] block, because that is where the IDs are read.
The first ad release went out with the real ID, so it was presumably built with ADS=true typed on the command line. After that, releases were built the normal way, sh release/build_android.sh, and the default took over.
Reproducing it
I cut the script down to the decision it makes and ran it four ways:
The first run is what our release job did. The second is what we assumed it did. Look at what the default path produces:
- The manifest gets Google's sample app ID, through the gradle fallback.
-
kAdsBuildisfalse, so the rewarded-ad button is never built into the widget tree. - The test-ID guard prints nothing, because it never runs. It lives on the branch we did not take.
That last point is the real bug. We had a guard against exactly this outcome, and the default path went around it.
How we found it
Not from the code. We were auditing every app we sell, comparing the intended business model with what each store build really contains. So instead of reading source, we looked at what the store was actually serving. Google Play lets you download the generated APKs for each release. For each version we checked the manifest:
unzip -p base.apk AndroidManifest.xml | strings | grep ca-app-pub # or: apkanalyzer manifest print base.apk | grep -A1 APPLICATION_ID The last release before the problem had our real app ID. The next four builds we pulled all had 3940256099942544. That gave us the exact window and the cause in one pass.
The fix
Three small changes, in the same commit:
-ADS="${ADS:-false}" +ADS="${ADS:-true}" The release default is now the configuration we actually ship. An ad-free test build has to say ADS=false out loud.
echo "########## ADS=$ADS AdMob app ID=${ADMOB_ANDROID_APP_ID:-(ads off, Google test ID)} ##########" The decision is printed in a line you cannot scroll past in the build log.
// test/release_ads_default_test.dart for (final f in ['release/build_android.sh', 'release/build_ios.sh']) { test('$f defaults ADS to true', () { final s = File(f).readAsStringSync(); expect(s, contains(r'ADS="${ADS:-true}"')); expect(s, isNot(contains(r'ADS="${ADS:-false}"'))); }); } A string test on a shell script looks crude. It is also the cheapest way to stop someone, including us in three months, from flipping the default back for a good local reason. The next release has to prove the fix the same way: by pulling the APK from the store and reading its manifest.
What I'd tell myself in October
- The default is the release. Whatever a script does with no arguments is what ships, because sooner or later someone runs it with no arguments. Make that path the production configuration, and make test builds opt out.
- A guard inside the opt-in branch only checks the opt-in path. If a check exists to stop a bad artifact, put it after the branch, on the final values: "is this manifest about to ship a sample ID?" no matter how we got there.
- "Safe" depends on the stage.
falsewas safe while the app had no ads. The day ads became revenue, the same line became the risky one, and nobody reread it. - Verify the artifact, not the source. Pulling the built APK from the store was a short job and gave a definitive answer. Reading the scripts had only confirmed that each line was reasonable.
If you have release switches with ${VAR:-default}, it is worth a minute to ask, for each one, whether the default is what you ship.
We build and maintain mobile apps and small products, and write up our own mistakes like this one. If you need a team that checks the shipped build, not just the code: https://devjar.dev/go/G-1882
