Receber por email
← Voltar para o catálogo

android-kotlin

Use this skill when building Android applications with Kotlin. Triggers on Jetpack Compose UI, Room database, Kotlin coroutines, Play Store publishing, MVVM/MVI architecture, ViewModel, StateFlow, Hilt dependency injection, Navigation Compose, Material 3, APK/AAB builds, ProGuard, and Android app lifecycle management. Covers modern Android development with declarative UI, reactive state, structure

185estrelas
Atualizado há 4 meses

Ver no GitHub ↗ Licença: MIT

Como adicionar

/plugin marketplace add AbsolutelySkilled/AbsolutelySkilled

O comando exato pode variar conforme o repositório. Confira o README no GitHub.

Para o autor da skill

Cole no README do seu repo

Mostra que sua skill está catalogada na Skillteca, gera backlink e tráfego rastreável.

[![Skillteca](https://www.skillteca.com.br/api/badge/android-kotlin/svg)](https://www.skillteca.com.br/skills/android-kotlin)

Alerta por categoria

Receba novas skills de Design e Frontend toda segunda

1 email curto, só com as skills novas de Design e Frontend. 4 minutos de leitura, sem spam, cancela com 1 clique.

Você confirma o email no primeiro envio. Sem spam. Cancela com 1 clique.

Ler descrição completa

When this skill is activated, always start your first response with the 🧢 emoji.

Android Kotlin

Modern Android development uses Kotlin as the primary language with Jetpack Compose for declarative UI, Room for local persistence, coroutines for structured concurrency, and a layered architecture (MVVM or MVI) to separate concerns. This skill covers the full lifecycle of building, testing, and publishing Android apps - from composable functions and state management through database design and Play Store release. It assumes Kotlin-first development with Android Studio and Gradle as the build system.

When to use this skill

Trigger this skill when the user:

  • Wants to build or modify a Jetpack Compose UI (screens, components, themes)
  • Needs to set up Room database with entities, DAOs, and migrations
  • Asks about Kotlin coroutines, Flows, or StateFlow for async work
  • Wants to structure an Android project with MVVM or MVI architecture
  • Needs to publish an app to Google Play Store (AAB, signing, release tracks)
  • Asks about ViewModel, Hilt/Dagger dependency injection, or Navigation Compose
  • Wants to handle Android lifecycle (Activity, Fragment, process death)
  • Needs to optimize app performance (startup time, memory, ProGuard/R8)

Do NOT trigger this skill for:

  • Cross-platform frameworks (Flutter, React Native, KMP shared logic) - use their dedicated skills
  • Backend Kotlin development (Ktor, Spring Boot) without Android UI concerns

Setup & authentication

Environment

# Required: Android Studio (latest stable) with SDK 34+
# Required: JDK 17 (bundled with Android Studio)
# Required: Gradle 8.x (via wrapper)

# Key SDK environment variables
export ANDROID_HOME=$HOME/Android/Sdk  # Linux
export ANDROID_HOME=$HOME/Library/Android/sdk  # macOS

Project-level build.gradle.kts (Kotlin DSL)

plugins {
    id("com.android.application") version "8.7.0" apply false
    id("org.jetbrains.kotlin.android") version "2.1.0" apply false
    id("org.jetbrains.kotlin.plugin.compose") version "2.1.0" apply false
    id("com.google.dagger.hilt.android") version "2.51.1" apply false
    id("com.google.devtools.ksp") version "2.1.0-1.0.29" apply false
}

App-level build.gradle.kts essentials

android {
    namespace = "com.example.app"
    compileSdk = 35
    defaultConfig {
        minSdk = 26
        targetSdk = 35
    }
    buildFeatures { compose = true }
}

dependencies {
    // Compose BOM - single version for all Compose libs
    val composeBom = platform("androidx.compose:compose-bom:2024.12.01")
    implementation(composeBom)
    implementation("androidx.compose.material3:material3")
    implementation("androidx.compose.ui:ui-tooling-preview")
    debugImplementation("androidx.compose.ui:ui-tooling")

    // Architecture
    implementation("androidx.lifecycle:lifecycle-viewmodel-compose:2.8.7")
    implementation("androidx.navigation:navigation-compose:2.8.5")

    // Room
    implementation("androidx.room:room-runtime:2.6.1")
    implementation("androidx.room:room-ktx:2.6.1")
    ksp("androidx.room:room-compiler:2.6.1")

    // Hilt
    implementation("com.google.dagger:hilt-android:2.51.1")
    ksp("com.google.dagger:hilt-android-compiler:2.51.1")
    implementation("androidx.hilt:hilt-navigation-compose:1.2.0")

    // Coroutines
    implementation("org.jetbrains.kotlinx:kotlinx-coroutines-android:1.9.0")
}

Core concepts

Jetpack Compose replaces XML layouts with composable functions. UI is a function of state: when state changes, Compose recomposes only the affected parts of the tree. Key primitives are @Composable functions, remember, mutableStateOf, and LaunchedEffect for side effects. Material 3 provides the design system (colors, typography, shapes).

Room is the persistence layer built on SQLite. Define @Entity classes for tables, @Dao interfaces for queries, and a @Database abstract class to tie them together. Room validates SQL at compile time and returns Flow<T> for reactive queries. Always define migrations for schema changes in production.

Coroutines and Flow provide structured concurrency. Use viewModelScope for ViewModel-scoped work, Dispatchers.IO for blocking I/O, and StateFlow to expose reactive state to the UI. Never launch coroutines from composables directly - use LaunchedEffect or collect flows with collectAsStateWithLifecycle().

Architecture (MVVM) separates UI (Compose), state holder (ViewModel), and data (Repository/Room). The ViewModel exposes StateFlow<UiState> and the composable collects it. User events flow up as lambdas, state flows down as data. This unidirectional data flow makes state predictable and testable.

Common tasks

Build a Compose screen with state

data class TaskListUiState(
    val tasks: List<Task> = emptyList(),
    val isLoading: Boolean = false,
)

@HiltViewModel
class TaskListViewModel @Inject constructor(
    private val repository: TaskRepository,
) : ViewModel() {
    private val _uiState = MutableStateFlow(TaskListUiState())
    val uiState: StateFlow<TaskListUiState> = _uiState.asStateFlow()

    init {
        viewModelScope.launch {
            repository.getTasks().collect { tasks ->
                _uiState.update { it.copy(tasks = tasks, isLoading = false) }
            }
        }
    }

    fun addTask(title: String) {
        viewModelScope.launch {
            repository.insert(Task(title = title))
        }
    }
}

@Composable
fun TaskListScreen(viewModel: TaskListViewModel = hiltViewModel()) {
    val uiState by viewModel.uiState.collectAsStateWithLifecycle()

    LazyColumn {
        items(uiState.tasks, key = { it.id }) { task ->
            Text(text = task.title, modifier = Modifier.padding(16.dp))
        }
    }
}
Always use collectAsStateWithLifecycle() instead of collectAsState() - it
respects the lifecycle and stops collection when the UI is not visible.

Set up Room database

@Entity(tableName = "tasks")
data class Task(
    @PrimaryKey(autoGenerate = true) val id: Long = 0,
    val title: String,
    val isCompleted: Boolean = false,
    val createdAt: Long = System.currentTimeMillis(),
)

@Dao
interface TaskDao {
    @Query("SELECT * FROM tasks ORDER BY createdAt DESC")
    fun getAll(): Flow<List<Task>>

    @Insert(onConflict = OnConflictStrategy.REPLACE)
    suspend fun insert(task: Task)

    @Delete
    suspend fun delete(task: Task)
}

@Database(entities = [Task::class], version = 1)
abstract class AppDatabase : RoomDatabase() {
    abstract fun taskDao(): TaskDao
}
Mark DAO query methods returning Flow as non-suspend. Mark write operations
(@Insert, @Update, @Delete) as suspend.

Set up Hilt dependency injection

@Module
@InstallIn(SingletonComponent::class)
object DatabaseModule {
    @Provides
    @Singleton
    fun provideDatabase(@ApplicationContext context: Context): AppDatabase =
        Room.databaseBuilder(context, AppDatabase::class.java, "app.db")
            .addMigrations(MIGRATION_1_2)
            .build()

    @Provides
    fun provideTaskDao(db: AppDatabase): TaskDao = db.taskDao()
}

@Module
@InstallIn(SingletonComponent::class)
object RepositoryModule {
    @Provides
    @Singleton
    fun provideTaskRepository(dao: TaskDao): TaskRepository =
        TaskRepositoryImpl(dao)
}
Annotate the Application class with @HiltAndroidApp and each Activity with
@AndroidEntryPoint.

Set up Navigation Compose

@Composable
fun AppNavHost(navController: NavHostController = rememberNavController()) {
    NavHost(navController = navController, startDestination = "tasks") {
        composable("tasks") {
            TaskListScreen(onTaskClick = { id ->
                navController.navigate("tasks/$id")
            })
        }
        composable(
            "tasks/{taskId}",
            arguments = listOf(navArgument("taskId") { type = NavType.
Compartilhar X LinkedIn