簡體   English   中英

Android 每個構建類型和風格的應用程序名稱

[英]Android App Name Per Build Type AND Flavour

我的應用程序具有多種構建類型風格gradle。

buildTypes {
    release {}
    test {}
    debug {}
}
productFlavors {
    europe {}
    asia {}
}

如何根據構建類型和風格的組合命名應用程序?

例子:
Flavor europe的應用名稱為AppEurope
BuildType測試會在 App 名稱后面加上“ Test ”后綴, AppEuropeTest

我在表盤中遇到了同樣的問題,並試圖將依賴於風味的應用程序名稱與依賴於構建類型的應用程序標簽值結合在一起。 我最終這樣做如下:

  1. 在build.gradle中使用manifestPlaceholder注入特定於buildType的字符串資源鏈接:

在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 &amp; Essential</string>
  <string name="app_name_dev">Classic &amp; Essential (DEV)</string>
</resources>
  1. 使用特定於字符串的風味版本的string.xml資源文件覆蓋該風味值。

我也在我的一篇博客文章中對此進行了描述: https : //www.journal.deviantdev.com/android-build-type-app-name-label/

您的問題已在這里回答-

如何更改每種Gradle構建類型的應用程序名稱

為所有版本的每種構建類型創建單獨的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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM