android-coroutines
Installation
SKILL.md
Android Coroutines Expert Skill
Workflow
- Identify scope — Determine the correct CoroutineScope (
viewModelScope,lifecycleScope, or injectedapplicationScope). - Wire data layer — Expose data as
suspendfunctions (one-shot) orFlow(streams) with injected Dispatchers. - Connect UI — Collect flows using
repeatOnLifecycle(Lifecycle.State.STARTED)and expose read-onlyStateFlow. - Verify — Run
./gradlew testand confirm coroutine behavior. If tests fail, check: uncaughtCancellationExceptionin genericcatchblocks,GlobalScopeusage causing leaked coroutines, missingawaitCloseincallbackFlow, or hardcoded Dispatchers breaking test determinism. Run./gradlew detektDebugto catch structural issues.
Critical Rules
1. Dispatcher Injection (Testability)
- NEVER hardcode Dispatchers (e.g.,
Dispatchers.IO,Dispatchers.Default) inside classes. - ALWAYS inject a
CoroutineDispatchervia the constructor. - DEFAULT to
Dispatchers.IOin the constructor argument for convenience, but allow it to be overridden.