Android¶
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.
Requirements¶
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)
Dependency¶
Manifest additions¶
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.
Platform factory¶
// Android Application.onCreate
class App : Application() {
override fun onCreate() {
super.onCreate()
startKoin {
modules(
workKoinModule(
config = WorkerConfig(logLevel = LogLevel.INFO),
workers = workerRegistry { register<MyWorker> { ctx -> MyWorker(ctx, get()) } },
factory = androidWorkManagerFactory(this@App),
),
)
}
}
}
androidWorkManagerFactory(context) handles:
- WorkManager.getInstance(context) lookup
- Mapping commonMain Constraints → androidx.work.Constraints
- Reflection or registry-based worker instantiation (configurable via
WorkerConfig.androidConfig.useReflectionFactory; defaults to true for v2 compat)
- Wiring WorkObserver SAMs through WorkManager.getWorkInfosByTagFlow(...)
Permissions you may also need¶
POST_NOTIFICATIONS(API 33+) if your foreground worker shows a notificationINTERNET(almost always, for network-constrained workers)ACCESS_NETWORK_STATEforNetworkType.CONNECTED/UNMETEREDconstraints
See also¶
- Platform API Matrix — full per-API support
- True Background Matrix — Android's guarantees vs other platforms
- Foreground Tasks — per-
foregroundServiceTypesetup