4

I am develop Flutter mobile app with Firebase.

I need separate Firebase environment for development and production.

I am follow this guide for setup.

Issue is when I implement google authentication for iOS because in Runner must copy REVERSED_CLIENT_ID from GoogleServices-Info.plist into Info.plist file.

I cannot just hardcode this REVERSED_CLIENT_ID into Info.plist because it is different for my development and production environments.

Is there way to specify variable in Info.plist to get correct REVERSED_CLIENT_ID for different environments?

I am use this script to copy correct GoogleServices-Info.plist:

if [ "${CONFIGURATION}" == "Debug-prod" ] || [ "${CONFIGURATION}" == "Release-prod" ] || [ "${CONFIGURATION}" == "Release" ]; then
cp -r "${PROJECT_DIR}/Runner/Firebase/Prod/GoogleService-Info.plist" "${PROJECT_DIR}/Runner/GoogleService-Info.plist"

echo "Production plist copied"

elif [ "${CONFIGURATION}" == "Debug-dev" ] || [ "${CONFIGURATION}" == "Release-dev" ] || [ "${CONFIGURATION}" == "Debug" ]; then

cp -r "${PROJECT_DIR}/Runner/Firebase/Dev/GoogleService-Info.plist" "${PROJECT_DIR}/Runner/GoogleService-Info.plist"

echo "Development plist copied"
fi

I look for answer everywhere but cannot find! I am completely block because of this.

Thanks!

FlutterFirebase
  • 2,163
  • 6
  • 28
  • 60

4 Answers4

4

I was able to solve this be creating a User-Defined variable that is environment specific and pull that variable into Info.plist

I setup my application to connect to two firebase projects (dev and prod) using instructions in this article: https://medium.com/@animeshjain/build-flavors-in-flutter-android-and-ios-with-different-firebase-projects-per-flavor-27c5c5dac10b

The thousand-foot summary is that you end up with a GoogleServices-Info.plist file for each dev and prod that is copied into the correct location at build time.

To set two REVERSE_CLIENT_IDS:

  1. Create a User-defined variable by adding it to ios/Flutter/Debug.xcconfig and ios/Flutter/Release.xcconfig. I called mine: GOOGLE_SERVICE_REVERSE_CLIENT_ID = {REVERSE_CLIENT_ID found in GoogleService-Info.plist file}
  2. Replace the hard-coded REVERSE_CLIENT_ID set in Info.plist with $(GOOGLE_SERVICE_REVERSE_CLIENT_ID)
  3. Open your project in XCode and go to the User-defined section and set the actual environment specific REVERSE_CLIENT_ID for each build type. Targets > Runner > Build Settings > Search "user" > User-Defined > GOOGLE_SERVICES_REVERSE_CLIENT_ID >

    Debug-dev = com.googleusercontent.apps.{dev client-id}
    Debug-prod = com.googleusercontent.apps.{prod client-id}
    Profile-dev = com.googleusercontent.apps.{dev client-id}
    Profile-prod = com.googleusercontent.apps.{prod client-id}
    Release-dev = com.googleusercontent.apps.{dev client-id}
    Release-prod = com.googleusercontent.apps.{prod client-id}

1

My thought is, the way you have different GoogleService-Info.plist files for dev and prod environments, keep different Info.plist files with correct reverse client ids for dev and prod environments too. In your script include a line to copy the Info.plist file into iOS/Runner/ directory.

flutter_bee
  • 11
  • 1
  • 1
  • This isn't really an answer but commentary on another post. Please move this to the comments section. – RyanNerd Feb 03 '20 at 07:18
0

I cannot make a comment but the nearest answer I could find is this: https://stackoverflow.com/a/48789232 (Below is an example modified for flutter, check your paths before following this!)

  1. Create folder with all your Google.plist files (with different names) in project
  2. Add a run script
PATH_TO_GOOGLE_PLISTS="${PROJECT_DIR}/Runner/Firebase"
    case "${CONFIGURATION}" in

   "Debug_Staging" | "AdHoc_Staging" )
        cp -r "$PATH_TO_GOOGLE_PLISTS/GoogleService-Info-dev.plist" "${BUILT_PRODUCTS_DIR}/${PRODUCT_NAME}.app/GoogleService-Info.plist" ;;

   "Debug_Poduction" | "AdHoc_Poduction" | "Distribution" | "Test_Poduction" )
        cp -r "$PATH_TO_GOOGLE_PLISTS/GoogleService-Info-prod.plist" "${BUILT_PRODUCTS_DIR}/${PRODUCT_NAME}.app/GoogleService-Info.plist" ;;

    *)
        ;;
esac
  1. Build scheme names (in accordance to the different cases of ${CONFIGURATION} from above code)
  1. Additionally you might have to add a default GoogleService-Info.plist in the Runner folder despite it being replaced by a copy from the script from the said link, should an notice pops up from the console where it asks about Could not locate configuration file: 'GoogleService-Info.plist'.
Sha-agi
  • 184
  • 2
  • 5
0

For Swift development, you can add both your dev and prod REVERSED_CLIENT_IDs to your url schemes, and your app will use the one that you initialize in your AppDelegate.

Ken Mueller
  • 3,659
  • 3
  • 21
  • 33