Android Development Skill
Production-ready Android development with Kotlin 2.0+, Jetpack Compose, and modern architecture patterns.
When Active
Use when building Android features, UI components, or platform-specific functionality. Auto-activated for:
- Kotlin files (.kt, .kts)
- Android project structure (build.gradle.kts, AndroidManifest.xml)
- Android commands (
/cook android, /test android)
Quick Start Templates
Build Configuration
UI Components
Architecture
Data Layer
Architecture Patterns
MVVM Pattern
Reference: mvvm-architecture.md
Layer responsibilities:
- UI Layer: Composables collect state, emit user actions
- ViewModel Layer: Holds StateFlow, processes actions, calls repositories
- Domain Layer: Business logic, use cases, domain models
- Data Layer: Repository implementations, Room, Retrofit
// Example Flow
User clicks button
↓
Composable calls ViewModel function
↓
ViewModel updates StateFlow
↓
Composable recomposes with new state
Compose Best Practices
Reference: compose-best-practices.md
Key concepts:
- State Hoisting: Move state up, pass down callbacks
- Recomposition: Use remember, derivedStateOf, keys in lists
- Side Effects: LaunchedEffect, DisposableEffect, rememberCoroutineScope
- Modifiers: Order matters, always accept Modifier parameter
Error Handling
Reference: error-handling.md
Patterns:
- Result Wrapper: Sealed class for Success/Error/Loading
- Custom Exceptions: Domain-specific error types
- User Messages: Convert exceptions to friendly text
- Retry Logic: Exponential backoff for network errors
- Validation: Form validation with detailed errors
Test Examples
Unit Tests
UI Tests
Testing patterns:
- Use
runTest for coroutine tests
- Use
Turbine for Flow assertions
- Use
MockK for mocking
- Use Fake implementations for complex dependencies
- Test state transitions, not implementation
Tech Stack
Core (Required)
- Language: Kotlin 2.0+
- Min SDK: Android 7.0+ (API 24)
- Target SDK: Android 14+ (API 34)
- UI: Jetpack Compose + Material 3
- Architecture: MVVM with ViewModel + StateFlow
Jetpack Libraries
- Compose: UI toolkit (BOM for version management)
- Navigation: Type-safe navigation with Compose
- ViewModel: Lifecycle-aware state management
- Room: Local database with Flow
- Hilt: Dependency injection
Networking & Serialization
- Retrofit: HTTP client
- OkHttp: Networking layer with interceptors
- Kotlinx Serialization: JSON serialization (preferred over Gson)
Concurrency
- Coroutines: Structured concurrency
- Flow: Reactive streams
Testing
- JUnit: Unit testing framework
- MockK: Kotlin mocking library
- Turbine: Flow testing assertions
- Compose Testing: UI testing with semantics
- Espresso: Android UI testing (if needed)
Usage Instructions & Version Compatibility
See references/usage-and-compatibility.md for step-by-step setup guides (project, features, database, API, error handling, tests) and version compatibility matrix.
Best Practices
- Keep files under 200 lines - Split large files into smaller modules
- Use sealed interfaces for state - Type-safe state representation
- Hoist state appropriately - Balance reusability and simplicity
- Provide keys in lazy lists - Optimize recomposition
- Use Flow for reactive data - Observe database changes efficiently
- Map DTOs to domain models - Keep layers isolated
- Handle errors gracefully - Always provide user-friendly messages
- Test each layer independently - Mock dependencies appropriately
- Use Material 3 design - Follow system theme and dynamic colors
- Optimize for performance - Profile with Android Studio Profiler, minimize recomposition
Common Patterns
ViewModel with Flow
@HiltViewModel
class MyViewModel @Inject constructor(
private val repository: MyRepository
) : ViewModel() {
val uiState: StateFlow<UiState> = repository.observeData()
.map { data -> UiState.Success(data) }
.catch { emit(UiState.Error(it.message ?: "Error")) }
.stateIn(
scope = viewModelScope,
started = SharingStarted.WhileSubscribed(5000),
initialValue = UiState.Loading
)
}
Compose with State Collection
@Composable
fun MyScreen(viewModel: MyViewModel = hiltViewModel()) {
val uiState by viewModel.uiState.collectAsStateWithLifecycle()
when (val state = uiState) {
is UiState.Loading -> LoadingView()
is UiState.Success -> SuccessView(state.data)
is UiState.Error -> ErrorView(state.message)
}
}
Repository with Caching
class MyRepository @Inject constructor(
private val api: ApiService,
private val dao: MyDao
) {
fun observeData(): Flow<List<Item>> = dao.observeAll()
suspend fun refresh() {
val items = api.fetchItems()
dao.insertAll(items)
}
}
References
Build Commands
./gradlew assembleDebug # Build debug APK
./gradlew installDebug # Install on device
./gradlew build # Full build with tests
./gradlew test # Run unit tests
./gradlew connectedAndroidTest # Run instrumentation tests
./gradlew jacocoTestReport # Generate coverage report
./gradlew lint # Run Android linter
./gradlew ktlintCheck # Run Kotlin linter
Coverage Goals
- Minimum: 80% overall coverage
- ViewModels: 90%+ (business logic)
- Utilities: 95%+ (pure functions)
- UI: 70%+ (composables)
Sub-Skill Routing
When this skill is active and user intent matches a sub-skill, delegate:
| Intent |
Sub-Skill |
When |
| UI components |
android-ui-lib |
Theme Compose components, design tokens |
Rules
- Use StateFlow, not LiveData for state management
- Coroutines for async operations and Flow for data streams
- Jetpack Compose for all UI (no XML layouts)
- Use MockK for mocking in tests
- Keep composables small and focused
- Use Material 3 design system
- Support both light and dark themes
1---2name: android-development-33description: Use when working with .kt/.kts files, Gradle builds, Jetpack Compose, or Android-specific features45metadata:6 source: https://skillmd.com/skills/majiayu000/android-development-37 agent-affinity: [epost-implementer, epost-tester, epost-debugger, epost-reviewer]8 keywords: [android, kotlin, jetpack-compose, mvvm, hilt, room, retrofit]9 platforms: [android]10 triggers: [".kt", ".kts", "build.gradle", "AndroidManifest.xml", "android"]11---1213# Android Development Skill1415Production-ready Android development with Kotlin 2.0+, Jetpack Compose, and modern architecture patterns.1617## When Active1819Use when building Android features, UI components, or platform-specific functionality. Auto-activated for:20- Kotlin files (.kt, .kts)21- Android project structure (build.gradle.kts, AndroidManifest.xml)22- Android commands (`/cook android`, `/test android`)2324## Quick Start Templates2526### Build Configuration27- **[build-gradle-app.kts](./assets/build-gradle-app.kts)** - App module with Compose, Hilt, Room, Retrofit28- **[build-gradle-lib.kts](./assets/build-gradle-lib.kts)** - Library module for shared code2930### UI Components31- **[compose-screen-template.kt](./assets/compose-screen-template.kt)** - Complete screen with loading/error/success states32- **[navigation-template.kt](./assets/navigation-template.kt)** - Type-safe Navigation with nested graphs3334### Architecture35- **[viewmodel-template.kt](./assets/viewmodel-template.kt)** - ViewModel with StateFlow and error handling36- **[hilt-module-template.kt](./assets/hilt-module-template.kt)** - Dependency injection setup3738### Data Layer39- **[room-entity-dao-template.kt](./assets/room-entity-dao-template.kt)** - Database with migrations40- **[retrofit-service-template.kt](./assets/retrofit-service-template.kt)** - API service with error handling4142## Architecture Patterns4344### MVVM Pattern45Reference: [mvvm-architecture.md](./references/mvvm-architecture.md)4647Layer responsibilities:48- **UI Layer**: Composables collect state, emit user actions49- **ViewModel Layer**: Holds StateFlow, processes actions, calls repositories50- **Domain Layer**: Business logic, use cases, domain models51- **Data Layer**: Repository implementations, Room, Retrofit5253```kotlin54// Example Flow55User clicks button56 ↓57Composable calls ViewModel function58 ↓59ViewModel updates StateFlow60 ↓61Composable recomposes with new state62```6364### Compose Best Practices65Reference: [compose-best-practices.md](./references/compose-best-practices.md)6667Key concepts:68- **State Hoisting**: Move state up, pass down callbacks69- **Recomposition**: Use remember, derivedStateOf, keys in lists70- **Side Effects**: LaunchedEffect, DisposableEffect, rememberCoroutineScope71- **Modifiers**: Order matters, always accept Modifier parameter7273### Error Handling74Reference: [error-handling.md](./references/error-handling.md)7576Patterns:77- **Result Wrapper**: Sealed class for Success/Error/Loading78- **Custom Exceptions**: Domain-specific error types79- **User Messages**: Convert exceptions to friendly text80- **Retry Logic**: Exponential backoff for network errors81- **Validation**: Form validation with detailed errors8283## Test Examples8485### Unit Tests86- **[viewmodel-test-example.kt](./scripts/viewmodel-test-example.kt)** - Test ViewModels with Turbine87- **[repository-test-example.kt](./scripts/repository-test-example.kt)** - Test repositories with fakes/mocks8889### UI Tests90- **[compose-ui-test-example.kt](./scripts/compose-ui-test-example.kt)** - Compose testing with semantics9192Testing patterns:93- Use `runTest` for coroutine tests94- Use `Turbine` for Flow assertions95- Use `MockK` for mocking96- Use Fake implementations for complex dependencies97- Test state transitions, not implementation9899## Tech Stack100101### Core (Required)102- **Language**: Kotlin 2.0+103- **Min SDK**: Android 7.0+ (API 24)104- **Target SDK**: Android 14+ (API 34)105- **UI**: Jetpack Compose + Material 3106- **Architecture**: MVVM with ViewModel + StateFlow107108### Jetpack Libraries109- **Compose**: UI toolkit (BOM for version management)110- **Navigation**: Type-safe navigation with Compose111- **ViewModel**: Lifecycle-aware state management112- **Room**: Local database with Flow113- **Hilt**: Dependency injection114115### Networking & Serialization116- **Retrofit**: HTTP client117- **OkHttp**: Networking layer with interceptors118- **Kotlinx Serialization**: JSON serialization (preferred over Gson)119120### Concurrency121- **Coroutines**: Structured concurrency122- **Flow**: Reactive streams123124### Testing125- **JUnit**: Unit testing framework126- **MockK**: Kotlin mocking library127- **Turbine**: Flow testing assertions128- **Compose Testing**: UI testing with semantics129- **Espresso**: Android UI testing (if needed)130131## Usage Instructions & Version Compatibility132133See `references/usage-and-compatibility.md` for step-by-step setup guides (project, features, database, API, error handling, tests) and version compatibility matrix.134135## Best Practices1361371. **Keep files under 200 lines** - Split large files into smaller modules1382. **Use sealed interfaces for state** - Type-safe state representation1393. **Hoist state appropriately** - Balance reusability and simplicity1404. **Provide keys in lazy lists** - Optimize recomposition1415. **Use Flow for reactive data** - Observe database changes efficiently1426. **Map DTOs to domain models** - Keep layers isolated1437. **Handle errors gracefully** - Always provide user-friendly messages1448. **Test each layer independently** - Mock dependencies appropriately1459. **Use Material 3 design** - Follow system theme and dynamic colors14610. **Optimize for performance** - Profile with Android Studio Profiler, minimize recomposition147148## Common Patterns149150### ViewModel with Flow151```kotlin152@HiltViewModel153class MyViewModel @Inject constructor(154 private val repository: MyRepository155) : ViewModel() {156 val uiState: StateFlow<UiState> = repository.observeData()157 .map { data -> UiState.Success(data) }158 .catch { emit(UiState.Error(it.message ?: "Error")) }159 .stateIn(160 scope = viewModelScope,161 started = SharingStarted.WhileSubscribed(5000),162 initialValue = UiState.Loading163 )164}165```166167### Compose with State Collection168```kotlin169@Composable170fun MyScreen(viewModel: MyViewModel = hiltViewModel()) {171 val uiState by viewModel.uiState.collectAsStateWithLifecycle()172173 when (val state = uiState) {174 is UiState.Loading -> LoadingView()175 is UiState.Success -> SuccessView(state.data)176 is UiState.Error -> ErrorView(state.message)177 }178}179```180181### Repository with Caching182```kotlin183class MyRepository @Inject constructor(184 private val api: ApiService,185 private val dao: MyDao186) {187 fun observeData(): Flow<List<Item>> = dao.observeAll()188189 suspend fun refresh() {190 val items = api.fetchItems()191 dao.insertAll(items)192 }193}194```195196## References197198- [Android Developer Docs](https://developer.android.com)199- [Kotlin Coroutines Guide](https://kotlinlang.org/docs/coroutines-guide.html)200- [Jetpack Compose](https://developer.android.com/jetpack/compose)201- [Material 3 Design](https://m3.material.io)202- [Now in Android Sample](https://github.com/android/nowinandroid)203204## Build Commands205206```bash207./gradlew assembleDebug # Build debug APK208./gradlew installDebug # Install on device209./gradlew build # Full build with tests210./gradlew test # Run unit tests211./gradlew connectedAndroidTest # Run instrumentation tests212./gradlew jacocoTestReport # Generate coverage report213./gradlew lint # Run Android linter214./gradlew ktlintCheck # Run Kotlin linter215```216217## Coverage Goals218- **Minimum**: 80% overall coverage219- **ViewModels**: 90%+ (business logic)220- **Utilities**: 95%+ (pure functions)221- **UI**: 70%+ (composables)222223## Sub-Skill Routing224225When this skill is active and user intent matches a sub-skill, delegate:226227| Intent | Sub-Skill | When |228|--------|-----------|------|229| UI components | `android-ui-lib` | Theme Compose components, design tokens |230231## Rules232- Use StateFlow, not LiveData for state management233- Coroutines for async operations and Flow for data streams234- Jetpack Compose for all UI (no XML layouts)235- Use MockK for mocking in tests236- Keep composables small and focused237- Use Material 3 design system238- Support both light and dark themes