Note 04 / Android / Crash fixing / Flutter
Android SDK activities that crash on a bare intent: an AppComponentFactory guard and a manifest gate
A pre-launch test robot opens every activity in the merged manifest with an empty intent, and Play Billing's ProxyBillingActivity throws before any of your code runs. How to reproduce it, guard it narrowly and stop a new SDK from reintroducing it.
- By
- Trần Thế Anh, Software Engineer
- Published
- Work done
- October 2026, GirlX (Flutter app, Android side)
- Stack
- Kotlin, AppComponentFactory, Play Billing 8.0.0, Python manifest check
- Reading
- 6 min, 1,230 words
Some Android crashes come from code you did not write and cannot wrap. The Play Billing library declares ProxyBillingActivity in its manifest. Your merged manifest therefore contains it. If anything starts that activity with an intent that has no extras, it reads a null PendingIntent in onCreate and dies with a NullPointerException from getIntentSender(). It happens before the Flutter engine exists, so there is no Dart code to put a try/catch around.
In real use the activity always receives extras from the billing client. The crash shows up when something opens activities blindly. A pre-launch test robot does exactly that: it walks the activity list in the merged manifest and starts each one with a bare intent. This note covers the fix in one Flutter app, in the order it was done: reproduce, guard narrowly, then add a gate so the next SDK upgrade cannot undo it.
Reproduce before touching anything
On a rooted emulator (API 30) with the release build installed:
adb shell am start -n com.example.app/com.android.billingclient.api.ProxyBillingActivity
adb logcat -b crash -d
The package name is a placeholder. The second command reads the crash buffer, which is a better signal than scrolling the main log. The activity dies with the null getIntentSender() error.
The same loop over every activity in the merged manifest sorts them into two lists. Those that die go into a guard set. Those that survive go into a known-good list, so the gate can tell later which activities were never tested. For this app the dying set was five classes: ProxyBillingActivity, ProxyBillingActivityV2, PlayCoreDialogWrapperActivity, HsdpShimActivity and an AppLovin debugger activity, MaxDebuggerAxonEventsListActivity. Not all of them died on every device. The Play Core wrapper survived on the API 30 emulator with the newer library but had crashed in a sibling app on the same SDK set, so it was guarded anyway: a legitimate launch always carries extras, so the guard costs nothing.
Where to intercept
android:appComponentFactory lets an app say how Android instantiates its activities. The method instantiateActivity(classLoader, className, intent) runs before onCreate, so it is the earliest place an app can stand in for a class. Subclass CoreComponentFactory from androidx (the merged manifest was already using it, so nothing else changes) and register it:
class GuardFactory : CoreComponentFactory() {
override fun instantiateActivity(
cl: ClassLoader, className: String, intent: Intent?
): Activity {
if (className in GUARDED && hasNoExtras(intent)) {
Log.w("Guard", "bare launch blocked: $className")
return StrayLaunchActivity()
}
return super.instantiateActivity(cl, className, intent)
}
}
class StrayLaunchActivity : Activity() {
override fun onCreate(state: Bundle?) {
super.onCreate(null)
finish()
}
}
StrayLaunchActivity draws nothing and closes at once. The factory returns it only when the class is in the guard set and the intent carries no extras. A real purchase always has extras, so it goes through unchanged. Three more details of the original matter and are easy to skip:
- Reading extras can throw. If it does, treat the intent as having data and leave it alone. Blocking a real purchase is worse than letting a robot crash.
- Do not block on a restored activity. After process death Android recreates the activity with its old intent, extras included, so the same rule leaves it alone.
- The manifest has to reference the factory, and the stray activity must not be exported.
Keep the guard narrow on purpose
The tempting version guards every SDK activity. The app’s own notes argue against it, and I agree: a hook that sits in front of every activity the app has is the easiest way to break purchases for everyone. The rule used was that a class enters the guard only if it was seen to die with a bare intent, in this app or in another app with the same SDK set. In that app, fourteen other SDK activities were tried the same way and survived. Eighteen activities of a mediation SDK (Pangle) could not be run on a rooted device, so they were read with javap instead: a bare intent leaves a field null and the activity calls finish() instead of throwing. One of those activities is also launched by the SDK itself with no extras, so guarding it would have blocked a real feature. That finding came from the static read, not from a run, and the code comment says so.
Older Android
appComponentFactory exists from API 28. The same app still supports Android 7 to 8.1. For those a second mechanism, an ActivityLifecycleCallbacks registered in Application, takes advantage of an old behaviour: below API 29 the platform calls onActivityCreated from inside Activity.onCreate, so a callback still has a chance to replace the intent before the SDK reads it. It is more fragile because it depends on an extras key inside the billing library, so it ships with a version check (below) that goes red when the library version changes.
A related crash the factory also fixes
A genuine purchase can crash too. If the Play Store is being updated, the PendingIntent that billing hands over points to an activity that does not resolve, and startIntentSenderForResult throws ActivityNotFoundException. Billing 8.0.0 only catches SendIntentException there. A small subclass of ProxyBillingActivity overrides the call, converts the exception into the one the SDK already handles and the SDK reports a failed purchase to RevenueCat instead of killing the app. The factory returns this subclass whenever it would have instantiated the base class.
The gate
Everything above depends on the manifest staying as expected. A Python script reads the merged manifest of the release build and fails if any of these hold:
- The
appComponentFactoryis not the guard. - The stray activity is missing or exported.
- A class in the guard list is no longer in the manifest, which means an SDK renamed it and the guard protects nothing.
- Any activity in the manifest is in neither the guard set nor the known-good list. A new SDK brought something nobody has tried.
Applicationis not the class that installs the legacy guard.- The billing library version differs from the one the legacy guard was checked against.
- The safe billing subclass is missing.
- A provider or initializer starts an ad SDK on process start without being listed.
- A removed activity came back.
The guard list is read straight from the Kotlin file, between marker comments, so the Kotlin and Python sides cannot drift apart. The “unclassified” rule matters most in practice. Adding five mediation networks added 28 activities to the manifest, and the gate stops the build until someone runs am start -n on each one or decides not to.
Limits
- It does not make a real bug in an SDK go away. It makes a bare launch harmless.
- On API below 28 it relies on bytecode details of one billing version.
- I read the Kotlin and Python sources while writing this and did not rebuild or re-run the app, so the reproduction commands are as the source comments describe them, adapted to a placeholder package name. Crash and user counts are left out on purpose.
The portable idea is small: when a crash happens before your code starts, the earliest hook you control is the component factory, and the way to keep it safe is a short guard list built from observed crashes, plus a script that refuses to ship an unexamined activity.