Using Google Sign-in with two targets Using Google Sign-in with two targets ios ios

Using Google Sign-in with two targets


I had the same problem and I found a pretty simple solution.

Just copy the GoogleServices-Info.plist and put it in a different folder. The folder must be a physically different folder, since the filesystem won't accept same file names in the same folder. So create a real folder in finder and add it to XCode, don't use XCode groups.

Then change the target membership according to each plist file. Thats it!



I had the same problem. I have four different targets which needed to use the same GoogleService-Info.plist file but with different bundleIDs.I stumbled upon this excellent article from Restless Thinker which provided a solution to this exact problem.

PlistBuddy is a free tool provided by Apple and built-in in OSX.!

PlistBuddy can create and modify plist files. Here's a great tutorial by Fotis. He makes it seem like a piece of cake.

First thing is you check if the GoogleService-Info.plist file is listed under the Build Phases>Copy Bundle resources for each target. This should already be in place, but a recheck won't hurt. Add the file if it's not present.

The next thing you'd need to do is to create a new build Phase for each target. Go to your Project>Targets>Select your target>Build PhasesCheck the top-left area of the Build Phases screen for a + button.

Add a new custom phase. (You may already have the Run Script phase, in which case, just keep adding the commands after your existing commands)

Select New Run Script Phase and in the new box that opens up, enter your PlistBuddy command

/usr/libexec/PlistBuddy -c "Set :BUNDLE_ID ${PRODUCT_BUNDLE_IDENTIFIER}" $BUILT_PRODUCTS_DIR/$TARGET_NAME.app/GoogleService-Info.plist

Make sure your .app (under Product) filename is the same as your target name or this won't work. You can $TARGET_NAME.app to make it the same as your project.app name.

You can change more values in this way, just add another new line to the script.You'd need to add two more lines at least to change the CLIENT_ID and REVERSE_CLIENT_ID.

/usr/libexec/PlistBuddy -c "Set :CLIENT_ID 123456789012-abcdefghijklmnopqrstuvwxyzabcdefghijklm.apps.googleusercontent.com" $BUILT_PRODUCTS_DIR/$TARGET_NAME.app/GoogleService-Info.plist/usr/libexec/PlistBuddy -c "Set :REVERSED_CLIENT_ID com.googleusercontent.apps.123456789012-abcdefghijklmnopqrstuvwxyzabcdefghijklm" $BUILT_PRODUCTS_DIR/$TARGET_NAME.app/GoogleService-Info.plist

You might have to clean for it to work. Build and run on device.You might need to check the little box under the Run Script which says 'Run script only when installing' when installing on a device. When i left this box unchecked, XCode kept referring to my old Derived data.

Using PlistBuddy, you can change any plist value based on the target. Hope this helped.


make a seperate plist file for each target and dynamically switch between them.to do that you can check the answers here