How to change appname or app icon for different flavor version?
来源:互联网 发布:尼康处理raw软件 编辑:程序博客网 时间:2024/06/06 12:39
1. resValue in defaultConfig
declare a resValue in your defaultConfig which will become the Application’s name. (Attention: if you choose to name it app_name, be sure to delete the original app_name property from your strings.xml file, or it will clash.)
defaultConfig {
// applicationId, versionCode, etc.
(...)// define your base Applications name hereresValue 'string', 'app_name', 'MyApp'
}
2.resValue in productFlavors
set your productFlavors as you did already. You can leave them empty if it is ok for you to concat your App’s name with the flavor’s name only, or provide an explicit resValue, which will override the value from defaultConfig.
productFlavors {
dev {
// resValue ‘string’, ‘app_name’, ‘MyAppDevFlavor’
}
prod { // resValue 'string', 'app_name', 'MyAppProdFlavor'}
}
3. configure the resValue’s name at gradle configuration time
configure the resValue’s name at gradle configuration time
android.applicationVariants.all { variant ->
// get app_name field from defaultConfig
def appName = variant.mergedFlavor.resValues.get(‘app_name’).getValue()
// concat new App name with each flavor's nameappName = "${appName}"variant.productFlavors.each { flavor -> appName += " ${flavor.name}"}// optionally add buildType nameappName += " ${variant.buildType.name}"// your requirement: if buildType == debug, add DEV to App nameif(variant.buildType.name == "debug") { appName += " DEV"}// set new resValevariant.resValue 'string', 'app_name', appName
}
4.In your AndroidManifest, set the app_name field:
5. use manefestPlaceholders
5.http://stackoverflow.com/questions/24785270/how-to-change-app-name-per-gradle-build-type
android {
buildTypes {
release {
manifestPlaceholders = [appName: “My Standard App Name”]
}
debug {
manifestPlaceholders = [appName: “Debug”]
}
}
}
Then in your AndroidManifest.xml put:
6. user flavor res folder
Make sure you created the folders in the right path.
It should be app/src/flavor1/res.
To make more sense your main resources are located in src/main/res.
7.总结
三种方式:
1.manifestPlaceholders
2. resValue
3. 文件 res
NOTE:
1.buildTypes和productFlavors 中均可以使用前两种方式,且第二种要好,因为第一种方式是直接替换不利于国际化资源串引用。
2.如果两者都声明了app_name,则最后以buildTypes的设定为准。
原因是Gradle的资源合并功能中在权重上:
BuildType > Flavor > main > Dependecies.
8.参考链接
http://stackoverflow.com/questions/26555975/using-alternate-resources-with-build-flavors-in-gradle
http://stackoverflow.com/questions/16737006/using-build-flavors-structuring-source-folders-and-build-gradle-correctly
http://sodino.com/2016/09/01/android-gradle-change-appName/
- How to change appname or app icon for different flavor version?
- How to select different app.config for several build configurations
- How to change the default stack size on different platforms
- How to change Rails App name
- How to Get App Name and Version
- How to Check or Verify PC Motherboard BIOS SLIC Version is SLP OA 2.0 or 2.1 for OEM Activation
- How to Check or Verify PC Motherboard BIOS SLIC Version is SLP OA 2.0 or 2.1 for OEM Activation
- How to hide the New! icon or control how long the icon is displayed.
- iOS - Could not launch"appName" process launch failed: timed out waiting for app to launch:
- iOS - Could not launch"appName" process launch failed: timed out waiting for app to launch
- How To Move The Database To Different Diskgroup (Change Diskgroup Redundancy)
- how to book-keeping Gain/Loss for different Securities
- icon+appname+key
- How To Find Your Ubuntu or Kernel Version
- How to change options for Format Fortran Indent Plugin ?
- How to change credentials for SVN repository in Eclipse?
- How to Reset or Change Microsoft Office 2007 Product License Key or Volume License Key (VLK)
- How to distribute iOS app to device or app store or testflight
- Rest概念
- appium环境变量配置
- UVALive Problem 7079 How Many Maos Does the Guanxi Worth(暴力枚举+最短路)——2014ACM/ICPC亚洲区广州站
- Object介绍
- np.linalg.inv():
- How to change appname or app icon for different flavor version?
- RxJava interval 轮询
- 幸运数字
- Android系统开机启动流程及init进程浅析
- iOS 开发中关于Frame和约束的简单认识
- 使新建windows记事本的字符集编码默认为UTF-8
- 浅谈C/C++ 开发Excel插件之自定制ribbon菜单
- 服务端极光推送2-分组推送及服务端集成
- TCP/IP协议三次握手与四次握手流程解析