Reputation: 85
I am trying to build a flutter app on Codemagic. The app uses multiple firebase project so I have configured it accordingly. I am able to run all flavors both for android and iOS locally. The android build is success on Codemagic as well but the iOS build fails.
In the below screenshot you can see after reaching the Firebase setup run script file the iOS build fails
Code for my Firebase Setup file is
environment="default"
# Regex to extract the scheme name from the Build Configuration
# We have named our Build Configurations as Debug-dev, Debug-prod etc.
# Here, dev and prod are the scheme names. This kind of naming is required by Flutter for flavors to work.
# We are using the $CONFIGURATION variable available in the XCode build environment to extract
# the environment (or flavor)
# For eg.
# If CONFIGURATION="Debug-prod", then environment will get set to "prod".
if [[ $CONFIGURATION =~ -([^-]*)$ ]]; then
environment=${BASH_REMATCH[1]}
fi
echo $environment
# Name and path of the resource we're copying
GOOGLESERVICE_INFO_PLIST=GoogleService-Info.plist
GOOGLESERVICE_INFO_FILE=${PROJECT_DIR}/config/${environment}/${GOOGLESERVICE_INFO_PLIST}
# Make sure GoogleService-Info.plist exists
echo "Looking for ${GOOGLESERVICE_INFO_PLIST} in ${GOOGLESERVICE_INFO_FILE}"
if [ ! -f $GOOGLESERVICE_INFO_FILE ]
then
echo "No GoogleService-Info.plist found. Please ensure it's in the proper directory."
exit 1
fi
# Get a reference to the destination location for the GoogleService-Info.plist
# This is the default location where Firebase init code expects to find GoogleServices-Info.plist file
PLIST_DESTINATION=${BUILT_PRODUCTS_DIR}/${PRODUCT_NAME}.app
echo "Will copy ${GOOGLESERVICE_INFO_PLIST} to final destination: ${PLIST_DESTINATION}"
# Copy over the prod GoogleService-Info.plist for Release builds
cp "${GOOGLESERVICE_INFO_FILE}" "${PLIST_DESTINATION}"
I am following https://medium.com/@animeshjain/build-flavors-in-flutter-android-and-ios-with-different-firebase-projects-per-flavor-27c5c5dac10b article for setup.
Here is another approach which I took as recommended by the Codemagic team
Instead of creating flavors,i uploaded my firebase
files to codemagic as environment variables. Everything works fine for android but the iOS build fails saying Could not get GOOGLE_APP_ID. I know many people have asked question regarding this on stack but none of them works for me as they are not related to code magic and instead dragging the file to Xcode manually.
I also did an SSH to check if the firebase file gets added to iOS folder and it does get added with the help of prebuild scripts but iOS build still fails.
Upvotes: 4
Views: 1984
Reputation: 96
I used the same Medium article for setting up flavors (prod and dev) on my local machine.
I followed the Codemagic tutorial for setting up environment variables for the Google Service files, and I kept running into the same Could not get GOOGLE_APP_ID
error.
The key insight for me was to replicate my local environment in Codemagic as closely as possible and leverage the Firebase setup script in Xcode during Codemagic builds.
In my case, it meant recreating the exact same folder and file structure for the Runner/Firebase/prod/GoogleService-Info.plist
so that the Firebase Setup script in Build Phases could run without any issues.
First, I changed the pre-build script in Codemagic to ensure that the GoogleService-Info.plist
could be found by the Firebase Setup script:
#!/bin/bash
set -e # exit on first failed commandset
rm -rf $FCI_BUILD_DIR/iOS/Runner/GoogleService-Info.plist
mkdir -p “${FCI_BUILD_DIR}/iOS/Runner/Firebase/${FCI_FLUTTER_SCHEME}”
echo $IOS_FIREBASE_SECRET | base64 —decode > $FCI_BUILD_DIR/iOS/Runner/Firebase/prod/GoogleService-Info.plist
Second, Xcode must be aware of these files. A file present in directory does not mean it is on Xcode. Add the Firebase/
directory into Xcode by File -> Add files to “Runner..” and make sure to uncheck ‘Copy if required’.
If you are already building locally without any issues, you might be able to skip this step.
Here is how my folders appear in Xcode
Then run a build on Codemagic with FCI_FLUTTER_SCHEME=prod
.
Lastly, reading through xcodebuild.log
in the Codemagic build Artifacts might give you more details.
Upvotes: 7