Issue
I have an Android app with multiple flavors, each flavor defines the app_name string on its own strings.xml file. Recently I incorporated a new library that defines its own value for app_name at its own strings.xml file. The problem is that the final value for app_name in the merged resources is the app_name value defined by the library. How I can bring priority to the flavor app_name value?
Currently I'm define specific values for app_name in the individual strings.xml file per flavor.
I expect that the app_name value was the flavor value and not the library value.
UPDATE: My flavors are defined as below:
productFlavors {
doctoronline {
dimension "client"
applicationId 'com.doctoronline.doctoronline'
resValue 'string', 'filebrowser_provider', 'com.doctoronline.doctoronline.aditya.fileprovider'
buildConfigField 'String', 'CORPORATE_DOMAIN', '"e4c4aa0f523941d2a332d15101f12e9e"'
buildConfigField 'String', 'SHORT_NAME', '"DRONLINE"'
buildConfigField 'String', 'WAITING_MESSAGE', '"DRONLINE_WAITING_MESSAGE_PATIENT_DEFAULT"'
}
mapfre {
dimension "client"
applicationId 'com.doctoronline.mapfre'
resValue 'string', 'filebrowser_provider', 'com.doctoronline.mapfre.aditya.fileprovider'
buildConfigField 'String', 'CORPORATE_DOMAIN', '"3282a15f144e288bac4c07b1598e9234"'
buildConfigField 'String', 'SHORT_NAME', '"mapfre"'
buildConfigField 'String', 'WAITING_MESSAGE', '"MAPFRE_WAITING_MESSAGE_PATIENT_DEFAULT"'
}
...
//4 or 5 extra flavors
}
The library that I'm adding is this.
Solution
If you want to change your app name based on product flavor you build, you have two options:
1. using resValue. this helps you to add some resources to your app like string resource, color resource.
2. using manifestPlaceHolder. this helps you to add variables to android manifest file from your build.gradle file and change these variables through build types or product flavors.
this is how to add resValue to your product flavor
productFlavors {
flavor1 {
dimension = 'test'
resValue("string", "app_name", "MY APP NAME")
}
flavor2 {
dimension = 'test'
resValue("string", "app_name", "MY APP NAME")
}
}
if your strings.xml has string with name app_name you have to remove it to avoid duplication res values message.
to check if app name changed through different product flavors change your product falvor and build the project then check what values appear in application tag in the manifest file.
The second way is using manifestPlaceHolder. in your product flavor add manifestPlaceHolder and then use this variable inside your application tag in the manifest file
productFlavors {
flavor1 {
dimension = 'test'
manifestPlaceholders=[appName: 'MY APP NAME']
}
flavor2 {
dimension = 'test'
manifestPlaceholders=[appName: 'MY APP NAME']
}
}
then navigate to your android manifest file
<application
android:name=".DemoApplication"
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="${appName}"
android:supportsRtl="true"
android:theme="@style/AppTheme">
...
</application>
Hope this answer is helpful. Happy coding.
Answered By - Shalan93
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.