Guide for building native Android apps with Kotlin, Jetpack Compose, MVVM + Clean Architecture, and backend API integration
Expert guidance for building production-ready native Android applications using modern architecture patterns and Jetpack libraries.
This skill helps you understand and implement Android apps following best practices:
First, understand the three-layer architecture:
**Data Layer** (`data/`):
**Domain Layer** (`domain/`):
**Presentation Layer** (`presentation/`):
**DI Layer** (`di/`):
Review the network configuration:
```kotlin
// di/NetworkModule.kt
@Module
@InstallIn(SingletonComponent::class)
object NetworkModule {
@Provides
fun provideRetrofit(): Retrofit {
return Retrofit.Builder()
.baseUrl("https://api.example.com/v1/")
.addConverterFactory(GsonConverterFactory.create())
.client(okHttpClient)
.build()
}
}
```
Key patterns:
For each feature, follow this pattern:
**Step 3.1 - Define API Interface**:
```kotlin
// data/api/FeatureApi.kt
interface FeatureApi {
@GET("endpoint")
suspend fun getData(): Response<DataDto>
@POST("endpoint")
suspend fun postData(@Body data: DataDto): Response<ResultDto>
}
```
**Step 3.2 - Create DTOs**:
```kotlin
// data/dto/feature/DataDto.kt
data class DataDto(
val id: String,
val name: String
)
```
**Step 3.3 - Domain Model**:
```kotlin
// domain/model/Data.kt
data class Data(
val id: String,
val name: String
)
```
**Step 3.4 - Repository Interface**:
```kotlin
// domain/repository/FeatureRepository.kt
interface FeatureRepository {
suspend fun getData(): Resource<Data>
}
```
**Step 3.5 - Repository Implementation**:
```kotlin
// data/repository/FeatureRepositoryImpl.kt
class FeatureRepositoryImpl @Inject constructor(
private val api: FeatureApi
) : FeatureRepository {
override suspend fun getData(): Resource<Data> {
return try {
val response = api.getData()
if (response.isSuccessful) {
Resource.Success(response.body()!!.toDomain())
} else {
Resource.Error("Error: ${response.code()}")
}
} catch (e: Exception) {
Resource.Error(e.message ?: "Unknown error")
}
}
}
```
**Step 3.6 - ViewModel**:
```kotlin
// presentation/screens/feature/FeatureViewModel.kt
@HiltViewModel
class FeatureViewModel @Inject constructor(
private val repository: FeatureRepository
) : ViewModel() {
private val _state = mutableStateOf(FeatureState())
val state: State<FeatureState> = _state
fun loadData() {
viewModelScope.launch {
when (val result = repository.getData()) {
is Resource.Success -> {
_state.value = state.value.copy(
data = result.data,
isLoading = false
)
}
is Resource.Error -> {
_state.value = state.value.copy(
error = result.message,
isLoading = false
)
}
}
}
}
}
```
**Step 3.7 - Composable Screen**:
```kotlin
// presentation/screens/feature/FeatureScreen.kt
@Composable
fun FeatureScreen(
viewModel: FeatureViewModel = hiltViewModel()
) {
val state = viewModel.state.value
LaunchedEffect(Unit) {
viewModel.loadData()
}
// UI implementation with Material 3 components
}
```
Check `app/build.gradle.kts` for:
For push notifications:
1. Ensure `google-services.json` is in `app/`
2. Check `service/` directory for FCM service implementation
3. Verify token registration on login
```bash
./gradlew test
./gradlew connectedAndroidTest
./gradlew assembleDebug
./gradlew assembleRelease
```
1. **Separation of Concerns**: Data, domain, and presentation layers are isolated
2. **Single Responsibility**: Each class has one clear purpose
3. **Dependency Inversion**: Depend on abstractions (repository interfaces), not implementations
4. **Testability**: ViewModels and repositories can be unit tested
5. **Reactive UI**: Compose reacts to state changes automatically
**Add a new screen**:
1. Create ViewModel with state
2. Create Composable screen
3. Add to navigation graph
4. Wire up repository if needed
**Add a new API endpoint**:
1. Add method to appropriate `Api` interface
2. Create/update DTOs
3. Add repository method
4. Call from ViewModel
**Handle authentication**:
**Image upload**:
1. Update version code and name in `build.gradle.kts`
2. Verify signing configuration
3. Test on multiple devices and Android versions
4. Run Lint and fix issues
5. Generate signed AAB for Play Store
Leave a review
No reviews yet. Be the first to review this skill!
# Download SKILL.md from killerskills.ai/api/skills/android-app-architecture-guide/raw