![](/img/trans.png)
[英]Use different signature for Gradle product flavour and build type in Android
[英]Android App Name Per Build Type AND Flavour
我的應用程序具有多種構建類型和風格gradle。
buildTypes {
release {}
test {}
debug {}
}
productFlavors {
europe {}
asia {}
}
如何根據構建類型和風格的組合命名應用程序?
例子:
Flavor europe的應用名稱為AppEurope
BuildType測試會在 App 名稱后面加上“ Test ”后綴, AppEuropeTest
我在表盤中遇到了同樣的問題,並試圖將依賴於風味的應用程序名稱與依賴於構建類型的應用程序標簽值結合在一起。 我最終這樣做如下:
在build.gradle文件中:
buildTypes {
release {
manifestPlaceholders = [ applicationLabel: "@string/app_name"]
}
debug {
manifestPlaceholders = [ applicationLabel: "@string/app_name_dev" ]
}
}
在AndroidManifest.xml中:
<application
[..]
android:label="${applicationLabel}">
在strings.xml文件中:
<resources>
<string name="app_name">Classic & Essential</string>
<string name="app_name_dev">Classic & Essential (DEV)</string>
</resources>
我也在我的一篇博客文章中對此進行了描述: https : //www.journal.deviantdev.com/android-build-type-app-name-label/
您的問題已在這里回答-
為所有版本的每種構建類型創建單獨的string.xml版本。
這里有一個示例項目。
https://github.com/commonsguy/cw-omnibus/tree/master/Gradle/HelloBuildType
編輯1
android.sourceSets.europe {
res.srcDirs = ['flavor_resources/europe/res']
}
android.sourceSets.europe.debug {
res.srcDirs = ['flavor_resources/europe/debug/res']
}
相關鏈接顯示了如何為 flavor 執行此操作,並且在擴展以包含構建類型時概念是相同的 - 我們可以將 flavors 和構建類型視為組合以創建“變體”,並且我們可以像配置 flavors 一樣輕松地配置變體使他們。
你有這些構建類型:
你有這些口味:
您在正常位置聲明了默認的app_name
字符串資源
src/main/res/values/strings.xml
<string name="app_name">App</string>
在這個簡單的例子中不需要清單占位符。 如果您的情況需要,您可以根據其他答案配置它們。
只需直接在清單中使用app_name
即可。 相信您對變體所做的更改會正確反映。
例如
<application
android:label="@string/app_name"
etc...
作為標准,gradle 允許在變體源文件夾(如 flavor 或構建類型源文件夾)中聲明資源文件,這些將自動覆蓋默認值。
在這種簡單的情況下不需要源集。
只需為每個變體添加一個新的strings.xml
文件,重新定義app_name
以匹配該變體。
例如,對於 Europe Test 版本,將您的文件添加到名為europeTest
的變體文件夾中,並覆蓋名稱:
src/europeTest/res/values/strings.xml
<string name="app_name">AppEuropeTest</string>
不同的變體還將根據需要獲得自己的覆蓋字符串文件。
使用應用程序 ID,可以配置每種風格以向應用程序 ID 添加一點。
這對於普通構建系統目前是不可能的,因此您目前無法將test
構建配置為 append 名稱“Test”為主名稱,然后將europe
風味配置為 append“Europe”。
那真的很好,但本機不支持。
This answer suggests a library that you can use for an alternative way to combining the app names, and could probably be used to make a more logical naming system, especially with more flavor dimensions(類似於應用程序 ID 的做法)。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.