-
Notifications
You must be signed in to change notification settings - Fork 2
android
title: "Android" description: "worker-kmp on Android is a thin adapter over androidx.work.WorkManager + JobScheduler — OS-scheduled, reboot-persistent, survives process death."
worker-kmp on Android is a thin adapter over androidx.work.WorkManager (+ JobScheduler).
OS-scheduled, persistent across reboots, and survives app process death — the
WorkManager you already know, exposed through the commonMain API.
-
minSdk≥ 21 (Android 5.0 Lollipop) - AndroidX WorkManager 2.9+ (transitively included by
cmp-worker-android) - AndroidX Startup (transitively included; used for zero-config initialization)
// commonMain
api(libs.worker.kmp)
api(libs.worker.koin)
// androidMain
api(libs.worker.android)For most workers, no Manifest changes are required — cmp-worker-android declares the
necessary <provider> and <receiver> entries via manifest-merger.
For foreground service workers (long-running tasks), add the following:
<!-- AndroidManifest.xml -->
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
<!-- API 34+: declare service type -->
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_DATA_SYNC" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_MEDIA_PLAYBACK" />
<!-- … add other types your foreground workers use -->
<application>
<!-- The library's foreground service is auto-declared via manifest-merger.
Consumers may override foregroundServiceType per build variant: -->
<service
android:name="androidx.work.impl.foreground.SystemForegroundService"
tools:replace="android:foregroundServiceType"
android:foregroundServiceType="dataSync" />
</application>See Foreground Tasks for the full per-type matrix.
The worker wiring lives in your commonMain shared init via WorkerKmpAuto.install() (see the
Quick start / Single-API Guide).
The Android app class's only worker-related job is to bind the Koin androidContext — the
generated Android installer reads the Application from that binding and selects
androidWorkManagerFactory automatically:
// androidMain — no worker code; just supply the Koin Android context.
class App : Application() {
override fun onCreate() {
super.onCreate()
initApp { androidContext(this@App) } // commonMain initApp calls WorkerKmpAuto.install()
}
}Under the hood the generated installer uses androidWorkManagerFactory(context), which handles:
-
WorkManager.getInstance(context)lookup - Mapping commonMain
Constraints→androidx.work.Constraints - Registry-based worker instantiation from the
@WorkerKmpWorkerscodegen - Wiring
WorkObserverSAMs throughWorkManager.getWorkInfosByTagFlow(...)
-
POST_NOTIFICATIONS(API 33+) if your foreground worker shows a notification -
INTERNET(almost always, for network-constrained workers) -
ACCESS_NETWORK_STATEforNetworkType.CONNECTED/UNMETEREDconstraints
- Platform API Matrix — full per-API support
- True Background Matrix — Android's guarantees vs other platforms
-
Foreground Tasks — per-
foregroundServiceTypesetup
Getting Started
Platform Support
Features
Operations
Release