- 分開後端服務或第三方服務資料
- debug, release 版不能滿足需求,測試環境也需要用 release 版 APP 測試
.vscode/launch.json
{
"configurations": [
// ... 其他設定
{
"name": "TideWallet3",
"request": "launch",
"type": "dart"
},
// 新增 Development
{
"name": "Development",
"request": "launch",
"type": "dart",
"program": "lib/main.dart",
"args": ["--flavor", "development"]
},
// 新增 Production
{
"name": "Production",
"request": "launch",
"type": "dart",
"program": "lib/main.dart",
"args": ["--flavor", "production"]
}
]
}
-
新增 xcconfig
-
修改 xcconfig 內容 e.g
#include "Pods/Target Support Files/Pods-Runner/Pods-Runner.debug.xcconfig" #include "Generated.xcconfig" FLUTTER_TARGET=lib/main.dart // main 進入點,根據需求可改 bundle_suffix=.dev // 用於分辨是不同 app app_display_name=TideWallet 3 DEV // App 名稱
-
新增 configurations
- 更新 scheme
-
android/app/build.gradle
android { // ... buildTypes { // ... } flavorDimensions "flavor-type" productFlavors { development { dimension "flavor-type" applicationIdSuffix ".dev" resValue "string", "app_name", "TideWallet 3 DEV" } production { dimension "flavor-type" resValue "string", "app_name", "TideWallet" } } }
-
android/app/src/main/AndroidManifest.xml
// ... <application android:name=".Application" android:label="@string/app_name" // ...
FCM
-
修改名稱和 Script
# Type a script or drag a script file from your workspace to insert its path. exec > ${PROJECT_DIR}/prebuild.log 2>&1 echo "${CONFIGURATION}" if [ "${CONFIGURATION}" == "Debug-Development" ] || [ "${CONFIGURATION}" == "Release-Development" ] || [ "${CONFIGURATION}" == "Debug" ]; then cp -r "${PROJECT_DIR}/Runner/Firebase/Development/GoogleService-Info.plist" "${PROJECT_DIR}/Runner/GoogleService-Info.plist" echo "Development plist copied" elif [ "${CONFIGURATION}" == "Debug-Production" ] || [ "${CONFIGURATION}" == "Release-Production" ] || [ "${CONFIGURATION}" == "Release" ]; then cp -r "${PROJECT_DIR}/Runner/Firebase/Production/GoogleService-Info.plist" "${PROJECT_DIR}/Runner/GoogleService-Info.plist" echo "Production plist copied" fi
Unable to find included file "Generated.xcconfig"
- 方法一:
- 關掉 Xcode
- flutter clean && flutter pub get && cd ios/ && pod install
- 方法二:砍掉有問題的 xcconfig,重新建就好了
- 方法一:
https://ashok-b.medium.com/flutter-flavors-multiple-environment-setup-with-firebase-eb45f10e4014