本文介绍了为每个构建类型解析应用程序标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 我想为每个构建类型和风味解析manifestPlaceholders依赖关系。例如,我有I want to resolve manifestPlaceholders dependency for each build types and flavors. For example, I have productFlavors { dev { manifestPlaceholders = ['applicationLabel': 'DevFlavor'] } prod { manifestPlaceholders = ['applicationLabel': 'ProdFlavor'] }..... buildTypes { debug { def old_name = manifestPlaceholders.get('applicationLabel'); // every time is null// def old_name = productFlavors.dev.manifestPlaceholders.get('applicationLabel'); // ITS OK, but not dynamic manifestPlaceholders = [applicationLabel: old_name + ' Dev'] } $ b 感谢您提供任何帮助Thanks for any help在你的 defaultConfig 中声明一个 resValue ,这将成为应用程序的名字。 (注意:)如果您选择将其命名为 app_name ,请务必删除原始的 app_name 属性从你的 strings.xml 文件,否则会发生冲突。)defaultConfig { // applicationId, versionCode, etc. (...) // define your base Applications name here resValue 'string', 'app_name', 'MyApp'}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 就像您已经做过的那样。如果您可以将您的应用程序的名称与风格的名称连接起来,或者提供一个明确的 resValue ,它将覆盖从 defaultConfig 。productFlavors { dev { // resValue 'string', 'app_name', 'MyAppDevFlavor' } prod { // resValue 'string', 'app_name', 'MyAppProdFlavor' }}configure the resValue's name at gradle configuration time 配置 resValue 在gradle配置时间的名称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 name appName = "${appName}" variant.productFlavors.each { flavor -> appName += " ${flavor.name}" } // optionally add buildType name appName += " ${variant.buildType.name}" // your requirement: if buildType == debug, add DEV to App name if(variant.buildType.name == "debug") { appName += " DEV" } // set new resVale variant.resValue 'string', 'app_name', appName}In your AndroidManifest, set the app_name field:<application ... android:label="@string/app_name" ... >正如我前面提到的,一定要删除来自 strings.xml的 app_name 属性的默认值As I mentioned above, be sure to delete the default app_name property from strings.xml 这篇关于为每个构建类型解析应用程序标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
09-11 04:37