AI Makes Code Cheap But Judgment Expensive: The Coroutine Mistakes That Break Android Apps
Teams that ship AI-generated Android code will hit these exact failures: invisible coroutine ownership, blocked threads, swallowed cancellation, and leaked exceptions. The rules here are what separate a demo from a production system.
AI has pushed the marginal cost of writing code to near zero, but it has not made the code correct. The coroutine and architecture pitfalls that trip up generated Android code are now well catalogued: launch is used as a thread-switch, repositories launch their own coroutines, and CancellationException gets swallowed in a generic catch block. The result is code that compiles, passes unit tests, and then ANRs or leaks once it hits production.
The fix is a set of design contracts. Data layers must be main-safe, meaning they own their blocking work and expose suspend functions or cold flows. Repositories expose suspend, not launch, so the caller controls lifecycle and cancellation. Blocking Java primitives like BlockingQueue and ReentrantLock have no place in suspend chains; channel and mutex suspend instead. Exceptions are mapped at the edge of the data layer, and ViewModel only turns results into UI states. Cold flows are the default, with stateIn reserved for cases that genuinely share a hot source.
The deeper point is that AI produces locally correct code. What it cannot produce is the judgment about ownership, lifecycle, and error boundaries. Those decisions still fall on the engineer, and they are exactly the ones that determine whether the system survives real use.
AI-generated coroutine code most often fails on semantic conflations, not syntax: launch is used as a thread-switch and suspend is treated as a guarantee of non-blocking, both of which pass compilation and unit tests.
The ownership principle is the real architectural contract: any design that hides who cancels a coroutine or who waits for its result is a flaw, even if it uses the same API names.
Local correctness is a trap: code that compiles and passes tests can still violate lifecycle and error-boundary rules that only surface under load or after a screen is destroyed.