不同构建风格的不同应用程序名称? [英] Different app names for different build flavors?

查看:33
本文介绍了不同构建风格的不同应用程序名称?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有 2 种构建风格,比如 flavor1flavor2.

I have 2 build flavors, say, flavor1 and flavor2.

我希望我的应用程序命名为AppFlavor1",当我为flavor1 构建时,AppFlavor2",当我为flavor 2 构建时.

I would like my application to be named, say, "AppFlavor1" when I build for flavor1 and "AppFlavor2" when I build for flavor 2.

这不是我要更改的活动标题.我想更改显示在手机菜单和其他地方的应用名称.

It is not the title of activities I want to change. I want to change the app name as it's displayed on the phone menu and elsewhere.

build.gradle 我可以为我的风格设置各种参数,但似乎不是应用程序标签.而且我也无法根据某些变量以编程方式更改应用标签.

From build.gradle I can set various parameters for my flavors but, it seems, not the app label. And I can not change the app label programmatically based on some variable, too.

那么,人们如何处理这个问题?

So, how do people handle this?

推荐答案

与其使用脚本更改主要的 strings.xml 并冒着扰乱源代码管理的风险,为什么不依靠 Android Gradle 构建的标准合并行为呢?

Instead of changing your main strings.xml with a script and risk messing up your source control, why not rely on the standard merging behavior of the Android Gradle build?

我的build.gradle包含

sourceSets {
    main {
        manifest.srcFile 'AndroidManifest.xml'
        java.srcDirs = ['src']
        resources.srcDirs = ['src']
        aidl.srcDirs = ['src']
        renderscript.srcDirs = ['src']
        res.srcDirs = ['res']
        assets.srcDirs = ['assets']
    }

    release {
        res.srcDir 'variants/release/res'
    }

    debug {
        res.srcDir 'variants/debug/res'
    }
}

所以现在我可以在 variants/[release|debug]/res/strings.xml 中定义我的 app_name 字符串.还有我想改变的任何其他东西!

So now I can define my app_name string in the variants/[release|debug]/res/strings.xml. And anything else I want to change, too!

这篇关于不同构建风格的不同应用程序名称?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆