Gravel Android
The Android 14 Crash
Targeting Android 14 crashed apps in production the moment they started a Foreground Service or WorkManager task. The fix was two lines. The cause was invisible at compile time.
The Incident
When Gravel — an Indonesian super-app — targeted Android 14 (API 34), their production app began crashing with runtime exceptions the moment a Foreground Service or WorkManager task attempted to start. The errors were cryptic, the fix was simple, and the underlying cause exposed a pattern affecting thousands of apps simultaneously: Android 14 made foreground service type declarations mandatory, and the requirement was invisible at compile time.
Evidence from the Scene
- MissingForegroundServiceTypeException thrown at runtime after targeting Android 14
- A second crash: 'foregroundServiceType 0x00000010 is not subset of foregroundServiceType 0x00000000'
- Both crashes occurred only after updating targetSdkVersion to 34
- The app compiled cleanly — no compile-time errors or warnings
- WorkManager's setForegroundAsync() call was the trigger for one of the crashes
- The manifest had foregroundServiceType declared, but the code passed a mismatched type
The Suspects
2 of these are the real root causes. The others are plausible-sounding distractors.
foregroundServiceType not declared in AndroidManifest.xml — now mandatory in Android 14
ForegroundInfo object in WorkManager code passing a ServiceInfo type that didn't match the manifest declaration
Missing FOREGROUND_SERVICE_DATA_SYNC permission in the manifest
Targeting Android 14 (API 34) without testing on an Android 14 device or emulator
Using an outdated WorkManager version that didn't support Android 14's new foreground service requirements
The Verdict
Real Root Causes
foregroundServiceType not declared in AndroidManifest.xml — now mandatory in Android 14
Android 14 made android:foregroundServiceType a required attribute in the manifest for any service that calls startForeground(). Previously optional, omitting it now throws MissingForegroundServiceTypeException at runtime — undetectable at compile time.
ForegroundInfo object in WorkManager code passing a ServiceInfo type that didn't match the manifest declaration
Android 14 requires the foreground service type to be declared in both the manifest AND passed in the ForegroundInfo constructor in WorkManager code. A mismatch between the two — even if both are set — throws a runtime type mismatch exception. Both locations must declare the same type.
Plausible But Wrong
Missing FOREGROUND_SERVICE_DATA_SYNC permission in the manifest
Android 14 also introduced new foreground service permissions (e.g., FOREGROUND_SERVICE_DATA_SYNC) — but the crash described here (MissingForegroundServiceTypeException and type mismatch) is specifically caused by missing or inconsistent type declarations, not the permission.
Targeting Android 14 (API 34) without testing on an Android 14 device or emulator
Not testing on Android 14 allowed the issue to reach production — but it's a process failure, not the technical root cause. The root cause is the API change making service type mandatory.
Using an outdated WorkManager version that didn't support Android 14's new foreground service requirements
Outdated WorkManager versions can cause compatibility issues — but even the current version requires the developer to pass the correct ServiceInfo type in ForegroundInfo. The mismatch is a developer error, not a library bug.
Summary
Android 14's foreground service type requirement was a breaking change with zero compile-time enforcement. Apps that had worked perfectly on Android 13 crashed immediately on Android 14 the moment they started a Foreground Service or WorkManager task. The fix: declare android:foregroundServiceType in AndroidManifest.xml AND pass the matching ServiceInfo constant in ForegroundInfo for WorkManager. Two lines, two locations, both required. Google's compliance deadline was May 31, 2024. The lesson: every Android OS targeting upgrade requires testing on the new version before shipping — breaking changes are invisible at compile time.
The Real Decision That Caused This
“Bumping targetSdkVersion to 34 without running foreground service flows on an Android 14 device or emulator, and not reviewing the Android 14 behaviour changes documentation before targeting the new API level.”
Lesson Hint
Chapter 7 (Platform & Performance) covers WorkManager, Foreground Services, and background processing patterns. Chapter 2 (App Architecture) covers Android lifecycle and service architecture.
Want to test yourself before reading the verdict?
Open Interactive Case in Autopsy Lab