In my previous blog I had tried to explain what White Labelling is and my approach of implementing it in Lumicall.
This week I went ahead with the implementation by using productFlavors feature in Android. I baked my cake!
I’ve created two flavors :
- Lumicall (which runs like the default version)
To switch to the desired version, there is a build variant window on the bottom left of Android Studio, when you open it, you can change your current active flavor from the ones you defined.
So the idea is, there would be different flavors for each client. And all the client specific resources would go under src/(flavorname) folder.
The client specific resources could be:
- Application name
- Client’s logo (Drawable)
- Details about the client’s organization which would go under “about” tab
- Colors / Themes (Colors.xml)
- Strings (Strings.xml)
- Additional Files which include new features
To understand how to modify these resources in the flavored version, Let’s take an example in which we would like to replace the application name from from Lumicall to, lets say “ClientApp”.
- Go to file : /res/values/strings.xml which has the application name <string name=”app_name”>Lumicall</string>
- To replace it with client’s app name, You’d have to create a new strings.xml file (Note : Same name as that of the existing ‘strings.xml file’) in the directory LumicallWhitelabel/src/whitelabel/res/values/strings.xml
So, in our project, there are two strings.xml file. One is /res/values/strings.xml and one flavored specfic file in LumicallWhitelabel/src/whitelabel/res/values/strings.xml.
Only add the values which would be different in the flavor version.
If there are particular things which you’d like to be same, then there is no need of adding them again with the same value in the flavored file.
-Just define the values you would want to replace. Not the values you would like to be same-
Gradle will take care of the overwriting while merging the resources when you run the flavored version.
Now, the most important thing is changing the Application ID. In my previous blog I explained the difference between ApplicationID and package name.
I also added a snippet from my build.gradle file which would suffix “.whitelabel” at the end of the orignal applicationID. So for configuring ApplicationID for each flavor, add applicationIdSuffix’suffix_you_want’.
Link to the the cake : https://github.com/Urvika-gola/LumicallWhitelabel
Thanks for reading,