How to avoid hardcoding REVERSED_CLIENT_ID into iOS Info.plist for dev/prod Google sign in?

2,412

Solution 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.

Solution 2

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}

Share:
2,412
FlutterFirebase
Author by

FlutterFirebase

Updated on December 09, 2022

Comments

  • FlutterFirebase
    FlutterFirebase over 1 year

    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!