For Android:
- create a folder "staging" at
/android/app/src
and put yourgoogle-services.json
for dev - create a folder "production" at
/android/app/src
and put yourgoogle-services.json
for production - in your
/android/app/build.graddle
:
add
task switchToStaging(type: Copy) {
description = 'Switches to Staging google-services.json'
from "src/staging"
include "google-services.json"
into "."
}
task switchToProduction(type: Copy) {
description = 'Switches to Production google-services.json'
from "src/production"
include "google-services.json"
into "."
}
afterEvaluate {
processStagingDebugGoogleServices.dependsOn switchToStaging
processStagingReleaseGoogleServices.dependsOn switchToStaging
processProductionDebugGoogleServices.dependsOn switchToProduction
processProductionReleaseGoogleServices.dependsOn switchToProduction
}
You can replace "staging" and "production" by your flavors name. When you will build it will copy google-services.json
from the created folder to /android/app
For iOS:
- the same way as Android, create a folder
Firebase/staging
andFirebase/production
atRunner/Runner/
and put your respective GoogleService-Info.plist
then, (assuming you have created your scheme that match to your flavors name), in Build Phases
section in xcode:
replace if statement with your needs
if [ "${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"
elif [ "${CONFIGURATION}" == "Debug-profile" ] || [ "${CONFIGURATION}" == "Release-profile" ] || [ "${CONFIGURATION}" == "Profile" ]; then
cp -r "${PROJECT_DIR}/Runner/Firebase/staging/GoogleService-Info.plist" "${PROJECT_DIR}/Runner/GoogleService-Info.plist"
elif [ "${CONFIGURATION}" == "Debug-staging" ] || [ "${CONFIGURATION}" == "Release-staging" ] || [ "${CONFIGURATION}" == "Debug" ]; then
cp -r "${PROJECT_DIR}/Runner/Firebase/staging/GoogleService-Info.plist" "${PROJECT_DIR}/Runner/GoogleService-Info.plist"
fi
Fonte:
https://stackoverflow.com/questions/77884297/setup-two-environments-for-flutter-firebase-existing-project
Nenhum comentário:
Postar um comentário