問(wèn)題描述
我正在嘗試找出一種方法,能夠在 gradle 中更改每個(gè)構(gòu)建類(lèi)型的應(yīng)用程序的應(yīng)用程序名稱(chēng).
I am trying to figure out a way to be able to change my application's app name per build type in gradle.
例如,我希望調(diào)試版本具有 <APP_NAME>-debug
,而 qa 版本具有 <APP-NAME>-QA
.
For instance, I would like the debug version to have <APP_NAME>-debug
and the qa version to have <APP-NAME>-QA
.
我熟悉:
debug {
applicationIdSuffix '.debug'
versionNameSuffix '-DEBUG'
}
但是,在啟動(dòng)器中,我似乎找不到 gradle 命令來(lái)應(yīng)用應(yīng)用程序的更改.
However, I can't seem to find a gradle command to apply the change of the app when in the launcher.
推薦答案
如果應(yīng)用名稱(chēng)"是指 上的
android:label
,則最簡(jiǎn)單的解決方案是將該點(diǎn)指向一個(gè)字符串資源(例如,android:label="@string/app_name"
),然后在 src/debug 中使用該字符串資源的不??同版本/
源集.
If by "app name", you mean android:label
on <application>
, the simplest solution is to have that point at a string resource (e.g., android:label="@string/app_name"
), then have a different version of that string resource in a src/debug/
sourceset.
您可以在 這個(gè)示例項(xiàng)目中看到這一點(diǎn),我在 src/debug/res/values/strings.xml
中替換了 app_name
,它將應(yīng)用于 debug
構(gòu)建.release
構(gòu)建將使用 src/main/
中的 app_name
版本.
You can see that in this sample project, where I have a replacement for app_name
in src/debug/res/values/strings.xml
, which will be applied for debug
builds. release
builds will use the version of app_name
in src/main/
.
這篇關(guān)于如何更改每個(gè) Gradle 構(gòu)建類(lèi)型的應(yīng)用程序名稱(chēng)的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!