Can't run flutter app with firebase on IOS
I guess you forgot to add GoogleService-Info.plist
file to your ios project
Follow this codelab (point 6 and 7 specifically) for detailed instruction.
Remember that it's not enough to copy it in your ios/Runner
folder from the finder/explorer
or command line
.
You need to open the ios/Runner.xcworkspace
with Xcode
and add the file to the project tree. Xcode needs to be aware of this file, so that it can be copied in the application bundle.
For cases with two google-services plist files you can add a new build phase to copy the file to the correct location on compilation.
- Create a config folder on the root of the iOS folder and inside it have the names of the two apps/builds you're targeting. Add the files accordingly to the folders. Next, head to Target Runner and on the Build Phases section.
- Add a new run script phase by clicking the + button at the top of that section.
- Rename it to a descriptive title, I call mine Copy GoogleServices-Info.plist to correct location Then move it right below the Link Binary With Libraries phase.
- Copy the following script into the build phase body
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}"
Try running the app and it should be good