Skip to content

About

KMP Dynamic App Icon — Lightweight Kotlin Multiplatform library for switching alternate app launcher icons dynamically at runtime on Android and iOS.

Topics

Resources

Stars

1 star

Watchers

0 watching

Forks

Repository files navigation

KMP Dynamic App Icon

Maven Central CI Kotlin License

Lightweight Kotlin Multiplatform library for dynamic app icon switching at runtime—change alternate launcher icons on Android (<activity-alias>) and iOS (UIApplication.setAlternateIconName) from shared Kotlin code.

  • Zero UI/Compose dependency — works with Compose Multiplatform, SwiftUI, XML Views, or pure KMP shared modules.
  • Zero CocoaPods required — uses Apple's native UIKit APIs directly via Kotlin/Native.
  • Safe by default — validates manifest aliases on Android before disabling existing ones (so a typo can never hide your launcher icon), dispatches UIKit calls on the main thread on iOS, and short-circuits when the target icon is already active.

Supported Targets

Platform Target Minimum OS
Android androidTarget API 21 (Android 5.0+)
iOS iosArm64, iosX64, iosSimulatorArm64 iOS 13.0+

Installation

// build.gradle.kts (shared / composeApp)
kotlin {
    sourceSets {
        commonMain.dependencies {
            implementation("io.github.ahmedn-mohamed:kmp-app-icon:0.1.0")
        }
    }
}

Quick Start

1. Define your icons in commonMain

import io.github.ahmednmohamed.appicon.appIconConfig

val AppIcons = appIconConfig {
    default(
        id = "default",
        androidAlias = ".MainActivityDefault",
    )
    alternate(
        id = "ramadan",
        androidAlias = ".MainActivityRamadan",
        iosIconName = "RamadanIcon",
    )
    alternate(
        id = "dark",
        androidAlias = ".MainActivityDark",
        iosIconName = "DarkIcon",
    )
}

2. Create AppIconManager per platform

Android (androidMain):

import io.github.ahmednmohamed.appicon.AppIconManager
import io.github.ahmednmohamed.appicon.createAppIconManager

val iconManager: AppIconManager = createAppIconManager(context, AppIcons)

iOS (iosMain):

import io.github.ahmednmohamed.appicon.AppIconManager
import io.github.ahmednmohamed.appicon.createAppIconManager

val iconManager: AppIconManager = createAppIconManager(AppIcons)

3. Switch or inspect icons from commonMain

import io.github.ahmednmohamed.appicon.AppIconManager
import io.github.ahmednmohamed.appicon.AppIconResult

suspend fun onSelectIcon(iconManager: AppIconManager, iconId: String) {
    if (!iconManager.isSupported()) return

    when (val result = iconManager.setIcon(iconId)) {
        is AppIconResult.Changed -> println("Switched to ${result.icon.id}")
        is AppIconResult.AlreadyActive -> println("Already using ${result.icon.id}")
        AppIconResult.Unsupported -> println("Alternate icons not supported")
        is AppIconResult.Failure -> println("Failed: ${result.reason}")
    }
}

// Read active icon
val current = iconManager.getCurrentIcon()

// Reset back to default
iconManager.resetToDefault()

Platform Setup

Android (AndroidManifest.xml)

  1. Remove the MAIN/LAUNCHER <intent-filter> from your main <activity>.
  2. Add one <activity-alias> per icon pointing to your main activity. Keep only the default alias android:enabled="true":
<activity
    android:name=".MainActivity"
    android:exported="true">
    <!-- Keep deep-link intent-filters here, NOT MAIN/LAUNCHER -->
</activity>

<activity-alias
    android:name=".MainActivityDefault"
    android:enabled="true"
    android:exported="true"
    android:icon="@mipmap/ic_launcher"
    android:roundIcon="@mipmap/ic_launcher_round"
    android:targetActivity=".MainActivity">
    <intent-filter>
        <action android:name="android.intent.action.MAIN" />
        <category android:name="android.intent.category.LAUNCHER" />
    </intent-filter>
</activity-alias>

<activity-alias
    android:name=".MainActivityRamadan"
    android:enabled="false"
    android:exported="true"
    android:icon="@mipmap/ic_launcher_ramadan"
    android:roundIcon="@mipmap/ic_launcher_ramadan_round"
    android:targetActivity=".MainActivity">
    <intent-filter>
        <action android:name="android.intent.action.MAIN" />
        <category android:name="android.intent.category.LAUNCHER" />
    </intent-filter>
</activity-alias>

Note: On Android, PackageManager.setComponentEnabledSetting refreshes the launcher icon asynchronously (usually within 1–5 seconds depending on the OEM launcher). Passing AppIconOptions(androidDontKillApp = true) (the default) avoids immediately terminating the app.

iOS (Info.plist & Xcode)

Option A — Xcode 13+ Asset Catalog

  1. Add your alternate icon sets (e.g. RamadanIcon, DarkIcon) to Assets.xcassets.
  2. In Xcode Build Settings, enable Include All App Icon Assets (ASSETCATALOG_COMPILER_INCLUDE_ALL_APPICON_ASSETS = YES).

Option B — Bundle PNGs + Info.plist (CFBundleIcons)

Include <IconName>@2x.png and <IconName>@3x.png in your app target resources and declare CFBundleIcons (plus CFBundleIcons~ipad if supporting iPad) in Info.plist:

<key>CFBundleIcons</key>
<dict>
    <key>CFBundlePrimaryIcon</key>
    <dict>
        <key>CFBundleIconFiles</key>
        <array>
            <string>AppIcon</string>
        </array>
        <key>UIPrerenderedIcon</key>
        <false/>
    </dict>
    <key>CFBundleAlternateIcons</key>
    <dict>
        <key>RamadanIcon</key>
        <dict>
            <key>CFBundleIconFiles</key>
            <array>
                <string>RamadanIcon</string>
            </array>
            <key>UIPrerenderedIcon</key>
            <false/>
        </dict>
    </dict>
</dict>

License

Apache License 2.0 — see LICENSE.

About

KMP Dynamic App Icon — Lightweight Kotlin Multiplatform library for switching alternate app launcher icons dynamically at runtime on Android and iOS.

Topics

Resources

Stars

1 star

Watchers

0 watching

Forks

Contributors

Languages