某天測試反映,每次測試不一樣環境的時候都要卸載舊的包。太麻煩了,咋解決?javascript
研究發現發現兩個方案html
好比我有一個app 包他可能有這樣幾種類型前端
雖然我是個前端仔,but 查資料仍是會的。通過不懈的努力,終於發現java
安卓系統中區分不一樣應用使用的是 applicationId 屬性
複製代碼
so 下一步問題變成如何去改 appId 了 查詢資料發現能夠利用 gradle 去設置 productFlavors 能夠很方便的實現這個需求.android
修改 android/app/build.gradle
productFlavors {
beta {//測試環境
applicationId "com.x.beta"
// applicationIdSuffix ".beta"
manifestPlaceholders = [
app_name: "@string/app_name_beta",
]
// resValue("string", "envTag", "beta環境")
}
product {//生產環境
applicationId "com.x.product"
// applicationIdSuffix ".product"
manifestPlaceholders = [
app_name: "@string/app_name",
]
// resValue("string", "envTag", "生產環境")
}
}
複製代碼
咱們能夠經過 manifestPlaceholders也就是佔位符來設置app
// 擴展上面
beta {
...
manifestPlaceholders = [
app_name: "@string/app_name_beta",
app_icon: '@xxxx'
JPUSH_APPKEY: '123' // 極光推送,
GoogleMapKey: '456' //谷歌地圖
]
}
product {}
複製代碼
build.gradle 修改完了,接下來還要設置 /android/app/src/main/AndroidManifest.xml裏面的內容ide
<application
android:icon="${app_icon}"
android:label="${app_name}"
xxxxx>
<!-- Google Map Key -->
<meta-data
android:name="com.google.android.geo.API_KEY"
android:value="${GoogleMapKey}" />
<!-- 極光推送-->
<!-- User defined. 用戶自定義的廣播接收器-->
<receiver
android:name="com.ablegenius.member.receiver.JpushReceiver"
android:enabled="true">
<!--android:process=":remote"廣播運行在遠端單獨進程中 ,調試斷點沒法執行須要關閉 或者 debug時候選擇 remote ! -->
<intent-filter>
xxxxx
<!--推送包名必須一導致用Gradle中的常量纔是最終的 -->
<category android:name="${applicationId}" />
</intent-filter>
</receiver>
</application>
複製代碼
最後配置包名 android/app/src/main/res/values/strings.xml測試
<resources>
<string name="app_name">x正式</string>
<string name="app_name_beta">x測試版</string>
</resources>
複製代碼
結果生成以下gradle
而後出現以下問題 ui
說是某個三方庫裏面的 provider下的 authorities的問題
終於發現一個庫的做者是寫死的不是動態的 而後改爲
最後成功的解決了個人問題