Gradle Plugin for adding a badge with version to app icons
Example:
Gradle 7.0.2
Android Gradle Plugin 7.0.1.
Add this to your project's build.gradle
buildscript {
repositories {
maven { url 'https://jitpack.io' }
}
dependencies {
classpath 'com.github.Innovattic:App-Badge:TAG'
}
}
Then apply plugin in your app's build.gradle
apply plugin: "com.innovattic.badge"
android {
buildTypes {
debug {}
release {}
}
productFlavors {
stage {}
production {}
}
}
badge {
buildTypes {
debug {
enabled = true
text = "debug"
}
// Do not add badge in release build type.
}
// or
productFlavors {
stage {
enabled = true
text = "stage"
}
production {
enabled = true
text = "production"
}
}
// or
// Variants has the highest priority. If variants config specified,
// others will be ignored.
variants {
stageDebug {
enabled = true
text = "stageDebug"
}
}
}
You can specify manually which icons to process:
badge {
iconNames = ["@mipmap/ic_launcher_cusom"]
}
If you're using plugin in a library module and use icons from this module in you app module, you need to specify icon names in library module.
You can specify text size, label color, text color. Gravity customization isn't available. Bottom used by default.
badge {
buildTypes {
debug {
enabled = true
text = "debug"
fontSize = 12 // Default value: 10
// Note that colors in format "#XXX" not supported,
// you have to specify colors as "#XXXXXX".
textColor = "#FFFFFF"
labelColor = "#000000"
}
}
}
You can find the sample in a separate repo: https://github.com/Innovattic/App-Badge-Sample
To test the plugin, you first need to locally publish the plugin.
Run: ./gradlew publishToMavenLocal
This will publish the plugin to the local /.m2
folder on your machine.
Add the mavenLocal
repository to a client project to test this local version,
which will read from this /.m2
folder. To use the local version, declare your dependency as:
buildscript {
repositories {
mavenLocal()
}
dependencies {
classpath 'com.innovattic.badge:com.innovattic.badge.gradle.plugin:TAG'
}
}
Every time you change the plugin, you need to re-run ./gradlew publishToMavenLocal
in order to update the
version of the plugin published locally on your machine.
Sergey Chuprin - [email protected]
Innovattic – https://www.innovattic.com/
Innovattic - https://www.innovattic.com/
- Nathan Bruning
- Luke Needham