before everything, I have already read this post Use different GoogleService-Info.plist for different build schemes
But still somehow it's not working for me.
I have two Prod and dev build schemes and I have two different GoogleService-Info.plist
for them.
In my first attempt, I rename both google files to GoogleService-Info-prod
and GoogleService-Info-dev
. and tried to read the files directly:
#if Production
if let filePath = Bundle.main.path(forResource: "GoogleService-Info-prod", ofType: "plist"),
let options = FirebaseOptions(contentsOfFile: filePath) {
FirebaseApp.configure(options: options)
} else {
fatalError("GoogleService-Info-Dev.plist is missing!")
}
#elseif Development
if let filePath = Bundle.main.path(forResource: "GoogleService-Info-dev", ofType: "plist"),
let options = FirebaseOptions(contentsOfFile: filePath) {
FirebaseApp.configure(options: options)
} else {
fatalError("GoogleService-Info.plist is missing!")
}
#endif
FirebaseConfiguration.shared.setLoggerLevel(.min)
UNUserNotificationCenter.current().delegate = self
let authOptions: UNAuthorizationOptions = [.alert, .badge, .sound]
UNUserNotificationCenter.current().requestAuthorization(options: authOptions) { _, _ in }
application.registerForRemoteNotifications()
Messaging.messaging().delegate = self
App can run ok after that. But in logs I have this warning
[FirebaseCore][I-COR000012] Could not locate configuration file: 'GoogleService-Info.plist'.
So It can mean that filename must be GoogleService-Info.plist
and it doesn't work with GoogleService-Info-prod
and GoogleService-Info-dev
In my second attempt, I made all the two files to GoogleService-Info.plist
, so it leads to have an error:
"Multiple commands produce GoogleService-Info.plist"
To avoid this error, I removed these two files from Build Phases > Copy Bundle Resources
and make the firebase setup function like that:
FirebaseApp.configure()
FirebaseConfiguration.shared.setLoggerLevel(.min)
UNUserNotificationCenter.current().delegate = self
let authOptions: UNAuthorizationOptions = [.alert, .badge, .sound]
UNUserNotificationCenter.current().requestAuthorization(options: authOptions) { _, _ in }
application.registerForRemoteNotifications()
Messaging.messaging().delegate = self
And then add this script
GOOGLESERVICE_INFO_DEV=${PROJECT_DIR}/${TARGET_NAME}/Application/Firebase/Dev/${GOOGLESERVICE_INFO_PLIST}
GOOGLESERVICE_INFO_PROD=${PROJECT_DIR}/${TARGET_NAME}/Application/Firebase/Prod/${GOOGLESERVICE_INFO_PLIST}
# Make sure the dev version of GoogleService-Info.plist exists
echo "Looking for ${GOOGLESERVICE_INFO_PLIST} in ${GOOGLESERVICE_INFO_DEV}"
if [ ! -f $GOOGLESERVICE_INFO_DEV ]
then
echo "No Development GoogleService-Info.plist found. Please ensure it's in the proper directory."
exit 1
fi
# Make sure the prod version of GoogleService-Info.plist exists
echo "Looking for ${GOOGLESERVICE_INFO_PLIST} in ${GOOGLESERVICE_INFO_PROD}"
if [ ! -f $GOOGLESERVICE_INFO_PROD ]
then
echo "No Production 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
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
if [ "${CONFIGURATION}" == "Release" ]
then
echo "Using ${GOOGLESERVICE_INFO_PROD}"
cp "${GOOGLESERVICE_INFO_PROD}" "${PLIST_DESTINATION}"
else
echo "Using ${GOOGLESERVICE_INFO_DEV}"
cp "${GOOGLESERVICE_INFO_DEV}" "${PLIST_DESTINATION}"
fi
BTW: I have to check the For install builds only
, otherwise I will get error:
Command PhaseScriptExecution failed with a nonzero exit code
Then after run, app will crash, and it says firebase cannot find GoogleService-Info.plist
- it's because I remove then from Build Phases > Copy Bundle Resources to avoid multiple file name issue.
Can anyone help how to fix this issue and add google files successfully.
BTW: I don't care about any Firebase analytics
Thank you so much