Skip to content

Conversation

russellwheatley
Copy link
Member

@russellwheatley russellwheatley commented Nov 18, 2022

Description

Allow the option of writing iOS, macOS & android Google service file to a specified directory. How it works:

Example:

flutterfire configure  --ios-out=/ios/GoogleService-Info.plist \
  --android-out=/android/google-services.json \ --macos-out=/macos/GoogleService-Info.plist

It uses the Flutter project as the root and adds the service file to the path and file name specified in the CLI options. The above example would add the service files to the root of each platform folder:

cool_flutter_project/ios/GoogleService-Info.plist
cool_flutter_project/android/google-services.json
cool_flutter_project/macos/GoogleService-Info.plist

Implementation

android

There isn't much to do for android except to write the file. according to the multi-environment documentation, you simply need to write the service file to the correct directory (e.g. android/app/src/development/google-services.json).

FFCLI also writes to the android/build.gradle & android/app/build.gradle which are used across all builds & flavors.


iOS & macOS

The approach I'm taking is to prompt the user to pick whether to write the service file for a scheme, target or to simply write to a path without any further configuration.

  1. Scheme
    Find schemes available and add a build phase script that adds the file to the app bundle. You can have multiple scheme configurations and it will still add to the app bundle. For instance, suppose you were using VGV CLI, and you chose to add a service file to the development scheme. It will include the service file the app bundle for the following configurations Release-development, Staging-development & Debug-development.

Example of script added to build phases:

#!/bin/bash

PLIST_DESTINATION=${BUILT_PRODUCTS_DIR}/${PRODUCT_NAME}.app
GOOGLESERVICE_INFO_PATH=/Users/russellwheatley/projects/devTests/service_testing/ios/some/GoogleService-Info.plist

# Copy GoogleService-Info.plist for appropriate scheme. Each scheme has multiple configurations (i.e. Debug-development, Debug-staging, etc).
# This is why we use *"scheme"*
if [[ "${CONFIGURATION}" == *"development"* ]];
then
    echo "Copying ${GOOGLESERVICE_INFO_PATH} to ${PLIST_DESTINATION}"
    cp "${GOOGLESERVICE_INFO_PATH}" "${PLIST_DESTINATION}"
fi     
  1. Target
    This is more straight forward, a command prompt allows you to select the desired target to include the service file. It will then add it to the "Copy bundle resources" phase for that target.

  2. Write with no further configuration
    This command prompt will simply add the file to the desired destination, creating necessary directories and is for user who want to do their own config setup.


  • what to do about firebase_app_id.json file write.

I've removed the need to have a firebase_app_id.json. The user now has the option to update their build phases with a script that will upload the debug symbols for Crashlytics for their setup (i.e. target or scheme). If the user selects a project setup that uses schemes for example, the CLI will write a bash script that will run for that specific scheme.

The example below is the script written if the user selects a "development" scheme script:

#!/bin/bash

# Run upload symbol script for appropriate scheme. Each scheme has multiple configurations (i.e. Debug-development, Debug-staging, etc).
# This is why we use *"scheme"*
if [[ "${CONFIGURATION}" == *"development"* ]];
then
    echo "Running firebase_crashlytics upload debug symbols script for 'development' scheme"
    $PODS_ROOT/FirebaseCrashlytics/upload-symbols --build-phase --validate -ai '1:361461320736:ios:6ecd45b6d0d3126f6f8045'
    $PODS_ROOT/FirebaseCrashlytics/upload-symbols --build-phase -ai '1:361461320736:ios:6ecd45b6d0d3126f6f8045'
fi     

The below example is a target script. In this example, the target they selected is "Runner":

#!/bin/bash

# Run upload symbol script for appropriate target.
if [ "${TARGET_NAME}" == "Runner" ];
then
    echo "Running [firebase_crashlytics] upload debug symbols script for 'Runner' target"
    $PODS_ROOT/FirebaseCrashlytics/upload-symbols --build-phase --validate -ai '1:361461320736:ios:6ecd45b6d0d3126f6f8045'
    $PODS_ROOT/FirebaseCrashlytics/upload-symbols --build-phase -ai '1:361461320736:ios:6ecd45b6d0d3126f6f8045'
fi 

Here's an example of the scripts written when using "schemes" setup. They will only be written once for each flutterfire configure call:
Screenshot 2022-11-25 at 13 56 31

Notes

  1. macOS "scheme" setup which bundles the 'GoogleService-Info.plist' won't work at the moment because there's a code signing issue. It does work for "target" setup.
  2. If you do test this feature, and you choose to add the "crashlytics upload debug symbol" script, you will need to delete the ios/firebase_app_id_file.json & macos/firebase_app_id_file.json because the script is now added in the build phases.

closes #14

Type of Change

  • feat -- New feature (non-breaking change which adds functionality)
  • 🛠️ fix -- Bug fix (non-breaking change which fixes an issue)
  • ! -- Breaking change (fix or feature that would cause existing functionality to change)
  • 🧹 refactor -- Code refactor
  • ci -- Build configuration change
  • 📝 docs -- Documentation
  • 🗑️ chore -- Chore

@russellwheatley russellwheatley changed the title typo feat: new command line args for service file output Nov 18, 2022
@russellwheatley russellwheatley marked this pull request as ready for review November 29, 2022 10:08
@russellwheatley russellwheatley changed the title feat: new command line args for service file output feat: new command line args for service file output & write debug symbol scripts to negate the use of "firebase_app_id_file.json" Nov 29, 2022
@russellwheatley russellwheatley changed the title feat: new command line args for service file output & write debug symbol scripts to negate the use of "firebase_app_id_file.json" feat: new command line args for Google service file output & write debug symbol scripts to negate the use of "firebase_app_id_file.json" Nov 29, 2022
@russellwheatley russellwheatley changed the title feat: new command line args for Google service file output & write debug symbol scripts to negate the use of "firebase_app_id_file.json" feat: new command line args & command prompts for Google service file output & write debug symbol scripts to negate the use of "firebase_app_id_file.json" Nov 29, 2022
@creativecreatorormaybenot
Copy link

creativecreatorormaybenot commented Dec 19, 2022

There isn't much to do for android except to write the file. according to the multi-environment documentation, you simply need to write the service file to the correct directory (e.g. android/app/development/google-services.json).

The example should be android/app/src/development/google-services.json, right @russellwheatley?

@russellwheatley
Copy link
Member Author

@creativecreatorormaybenot yes, I've updated the description 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support for multiple scheme dev, staging, prod
3 participants