Loading Firebase configuration
How to load Firebase configuration files into environment variables in a Flutter workflow editor pre-build script
Instead of committing the Firebase configuration files to your repository, you can upload them to Codemagic as environment variables and reference them in a custom script.
Save the contents of Firebase config files as environment variables, e.g. ANDROID_FIREBASE_SECRET
and IOS_FIREBASE_SECRET
in Codemagic UI (either in Application or Team variables) and select Secure.
Open your Codemagic app settings, and go to the Environment variables tab.
Enter the desired Variable name, e.g.
ANDROID_FIREBASE_SECRET
orIOS_FIREBASE_SECRET
.Copy and paste the config file content as Variable value.
Enter the variable group name, e.g. firebase_credentials. Click the button to create the group.
Make sure the Secure option is selected.
Click the Add button to add the variable.
Add the variable group to your
codemagic.yaml
fileenvironment: groups: - firebase_credentials
Add the following pre-build script echoing your variables to load the Firebase configuration in Codemagic.
scripts:
- name: Load Firebase configuration
script: |
#!/usr/bin/env sh
set -e # exit on first failed command
echo $ANDROID_FIREBASE_SECRET > $CM_BUILD_DIR/android/app/google-services.json
echo $IOS_FIREBASE_SECRET > $CM_BUILD_DIR/ios/Runner/GoogleService-Info.plist
In case your project is in a nested folder structure, adjust the script accordingly:
scripts:
- name: Load Firebase configuration
script: |
#!/usr/bin/env sh
set -e # exit on first failed command
PROJECT_ROOT=$CM_BUILD_DIR/myproject/path # ADD YOUR PROJECT FOLDER PATH HERE
echo $ANDROID_FIREBASE_SECRET > $PROJECT_ROOT/android/app/google-services.json
echo $IOS_FIREBASE_SECRET > $PROJECT_ROOT/ios/Runner/GoogleService-Info.plist