When developing an Android application, you may set Flavor for each environment such as development environment, staging environment, and production environment. Here's a summary of how to change the app name and app icon so that you can tell at a glance which apps have different environments.
Set Flavor in build.gradle
of the app.
This time, as an example, we will prepare three environments: dev
(development), stg
(staging), and prod
(production).
build.gradle
android {
//abridgement
//Add from here
flavorDimensions "environment"
productFlavors {
dev {
dimension "environment"
applicationIdSuffix ".dev"
versionNameSuffix ".dev"
}
stg {
dimension "environment"
applicationIdSuffix ".stg"
versionNameSuffix ".stg"
}
prod {
dimension "environment"
}
}
//Add up to here
}
Create a strings.xml
file for each Flavor.
Right-click res / values-> New-> Values Resource File as shown below.
Then set File name
to strings
and select dev
for Source set
.
This dev
was set in Flavor earlier.
This will create a strings.xml
for the dev
environment.
You can change the app name by setting the app name for each environment in ʻapp_name of this
strings.xml`.
Similarly, create strings.xml
for stg
and set the app name.
(You must set Build Variants
to stgDebug
to see strings.xml (stg)
)
The prod
environment wants to use the default strings.xml
, so we don't create a separate strings.xml
.
As shown below, it is OK if the application name is changed for each environment.
This time, I used a library called easylauncher-gradle-plugin.
First, add the settings to the project's build.gradle
.
build.gradle
buildscript {
//abridgement
dependencies {
//abridgement
classpath 'com.akaita.android:easylauncher:1.3.1' // <-Add here
}
}
Then add the settings to your app's build.gradle
.
build.gradle
plugins {
//abridgement
id 'com.akaita.android.easylauncher' // <-Add here
}
android {
//abridgement
//Flavor settings added earlier
flavorDimensions "environment"
productFlavors {
dev {
dimension "environment"
applicationIdSuffix ".dev"
versionNameSuffix ".dev"
}
stg {
dimension "environment"
applicationIdSuffix ".stg"
versionNameSuffix ".stg"
}
prod {
dimension "environment"
}
}
}
//Add from here
easylauncher {
iconNames "@mipmap/ic_launcher_foreground"
foregroundIconNames "@mipmap/ic_launcher_foreground"
defaultFlavorNaming = true
buildTypes {
debug {}
release {}
}
productFlavors {
dev {
filters = grayRibbonFilter()
}
stg {
filters = greenRibbonFilter()
}
prod {
enable false //Do not label in production
}
}
}
//Add up to here
//abridgement
With the settings up to this point, the icon will change for each app. This time, we have also set an appropriate icon.
It's very easy to understand! Please refer to Documentation for other settings of the library.
Recommended Posts