build.gradle app name 多國語言設定,以及 BuildConfig 字串設定

Build Variants 多國語言設定

1. 開啟 build.gradle (Module)

2. 設定 productFlavors 當前有兩個版本

3. 加入 resValue 字串

直接設定,沒有透過 string.xml

4. APP 會分別顯示不同名稱

多國語言設定

1. 開啟 string.xml 定義字串

2. 可以分別在各個資料夾下定義 string.xml

[範例 1] 分別在 dev 跟 stable 資料夾下分別存一個 string.xml 檔

[範例 2] 在 main 資料夾 string.xml 下,定義字串

3. 寫入 build.gradle

4. 結果

Build Config 設定

基本使用的方法

1. 可以透過 BuildConfig 直接讀取字串

2. 如果沒有發現新增的參數,執行 make project

3. 設定完成,可以正常讀到參數

4. 可以直接查看 BuildConfig

會顯是由哪個 flavor 產生

私密訊息如何處理

如檔案打包或上傳 GitHub 等動作,要將帳號密碼做處理,放置在 local.properties 的檔案,可以留在電腦端不受影響

1. 開啟 local.properties

2. 定義兩組 key

3. 讀取 local.properties

複製程式碼

Properties properties = new Properties()
properties.load(project.rootProject.file('local.properties').newDataInputStream()) // load local.properties
def web_auth_key = properties.getProperty('web_auth_key') // read property from local.properties
def web_auth_key1 = properties.getProperty('web_auth_key1') // read property from local.properties

4. 定義 resValue 兩組 key

5. 設定完成,執行 make project

後記

如果這篇文章對於你有幫助,可以幫忙分享給更多的人.文章內容如果有誤,可以在下方留言告知.本網站主要提供程式, 玩具相關資訊,可以訂閱獲得最即時的資訊.

留言

熱門文章

TourCard 開通全紀錄 台胞證 支付寶

[ 教學 ] 如何使用 Sourcetree 對 Github 進行版本控制 #Mac OS 版本控制