The ABC SDK provides a seamless way to dynamically badge your Android application icon with notification counts (e.g., "1", "99", "10+"). It uses a sophisticated Activity Alias mechanism to swap launcher icons on the fly without breaking the user experience.
Unique to this SDK, badged icons are generated at build time using your app's actual launcher icon, ensuring a perfect visual match.
Features
- Build-Time Generation: Automatically generates badged PNGs from your app's existing icon during the build process.
- Dynamic Badging: Shows counts from 1 to
ABC_MAX_VALUE. - Overflow Handling: Automatically shows "MAX+" (e.g., "10+") if the count exceeds the configured limit.
- Adaptive Icon Support: Generated assets work seamlessly with standard launcher configurations.
- Robust Integration: Triple-injection strategy ensures compatibility with complex multi-module and multi-variant projects.
- Namespace Aware: Correctly resolves activities even when
applicationIdandnamespacediffer.
Integration Guide
1. Add the Gradle Plugin
The ABC Plugin handles the generation of badged icons and the necessary manifest aliases.
Groovy DSL (build.gradle)
plugins {
id 'com.android.application'
id 'com.mathokkil.abc-plugin' version '1.1.44'
}
Kotlin DSL (build.gradle.kts)
plugins {
id("com.android.application")
id("com.mathokkil.abc-plugin") version "1.1.44"
}
Note: The plugin provides full Adaptive Icon support. It preserves your layered XML structure (background and foreground) and adds the badge as a third layer on top. This ensures that launcher effects like parallax and scaling remain intact.
2. Add the SDK Dependency
Groovy DSL
dependencies {
implementation 'com.mathokkil:android-badge-count:1.1.44'
}
Kotlin DSL
dependencies {
implementation("com.mathokkil:android-badge-count:1.1.44")
}
3. Configure Settings
In the defaultConfig block of your app's build file, add the required
configuration using manifestPlaceholders.
Parameters:
ABC_LAUNCH_ACTIVITY: The full class name of your main Launcher activity (e.g.,com.example.MainActivity).ABC_MAX_VALUE: The maximum number to display before showing the "+" overflow (e.g., "10").ABC_ICON: The path to your base launcher icon (e.g., "@mipmap/ic_launcher").
Groovy DSL (build.gradle)
android {
defaultConfig {
manifestPlaceholders = [
ABC_LAUNCH_ACTIVITY: "com.yourpackagename.MainActivity",
ABC_MAX_VALUE: "10",
ABC_ICON: "@mipmap/ic_launcher"
]
}
}
Kotlin DSL (build.gradle.kts)
android {
defaultConfig {
manifestPlaceholders["ABC_LAUNCH_ACTIVITY"] = "com.yourpackagename.MainActivity"
manifestPlaceholders["ABC_MAX_VALUE"] = "10"
manifestPlaceholders["ABC_ICON"] = "@mipmap/ic_launcher"
// Alternative syntax:
// manifestPlaceholders += mapOf(
// "ABC_LAUNCH_ACTIVITY" to "com.yourpackagename.MainActivity",
// "ABC_MAX_VALUE" to "10",
// "ABC_ICON" to "@mipmap/ic_launcher"
// )
}
}
Usage
Call ABCManager.setBadgeCount(context, count) whenever you want to update the
badge.
count <= 0: Clears the badge (Restores original icon).count > 0 && count <= ABC_MAX_VALUE: Shows the number.count > ABC_MAX_VALUE: ShowsABC_MAX_VALUE++(e.g., "10+").
import com.mathokkil.abc.ABCManager
// Set count to 5
ABCManager.setBadgeCount(this, 5)
// Clear badge
ABCManager.setBadgeCount(this, 0)
// Set badge after a delay (e.g., 5 seconds)
ABCManager.setBadgeCount(this, 8, 5000L)
// Set badge when app goes to background (UI Hidden)
ABCManager.setBadgeCount(this, 3, waitUntilAppStop = true)
Troubleshooting & Best Practices
"Component class does not exist" Error
If you see a java.lang.IllegalArgumentException stating that a component does
not exist:
- Force Clean: Run
./gradlew cleanor Build > Clean Project in Android Studio. Manifest merge results are cached aggressively, and a clean build is often required after configuration changes. - Verify Activity Name: Ensure
ABC_LAUNCH_ACTIVITYis the fully qualified class name. - Check Merged Manifest: Open your merged
AndroidManifest.xml(inbuild/intermediates/merged_manifest/) and search for_Alias1. If they are missing, the plugin was not applied correctly or had a conflict.
Verification
You can verify the active ABC version in your merged manifest by looking for:
<meta-data android:name="com.mathokkil.abc.VERSION" android:value="1.1.44" />
How It Works
- App Build Time: The
com.mathokkil.abc-pluginscans your project for the icon and launcher configuration. - Asset Generation: It generates high-resolution badged PNGs for legacy support and creates layered Adaptive Icon XMLs for Android 8+.
- Triple Injection: The plugin injects assets and aliases into your app through SourceSets, Task Metadata, and direct Overlay injection.
- Run Time:
ABCManagerenables the specific alias corresponding to the requested count viaPackageManager.
Technical Requirements
- Min SDK: 21
- Gradle: 8.0+
- Java: 17+ (for build process)
- Language: Kotlin / Java