Use Different Googleservice-Info.Plist for Different Build Schemes

Use different GoogleService-Info.plist for single project in xcode using swift4

I got the solution. I renamed GoogleService-Info.plists files by its respective environments. And Added those files in Build Phases -> Copy Bundle Resources. Then added the following code as per the environment selected

 guard let plistPath = Bundle.main.path(forResource: "nameOfTheGoogleService-Info.plistFileAsPerTheEnvironment", ofType: "plist"),
let options = FirebaseOptions(contentsOfFile: plistPath)
else { return }
if FirebaseApp.app() == nil{
FirebaseApp.configure(options: options)
}

Minor change is that, when user changes the app's environment, then he should remove app from background and open it again. Then the AppDeleagte takes the path of respective GoogleService-Info.plist as per its environment selected

How to use two different GoogleService-info.plist file in ios swift project for dev n prod?

For this case you need use different Targets with diff bundle id in project for Dev and Prod.

After that you will can link GoogleService-info.plist for this targets. And also I recommend create different folders in project directory
Look at pictures. The first you create targets Prod and Dev

enter image description here

After create diff folders in project dict let's call them GoogleProd and GoogleDev and copy your .plist file to diff folders and drag to project. First file you need link with TestProd target

enter image description here

And the second file link with TestDev target

enter image description here

The final project directory will look like

enter image description here

Different GoogleService-Info.plist files for dev and prod for ios and android in react-native

If you have configured your project with https://console.developers.google.com
There is no need to configure anything in your code.

For ANDROID by default, you can set up 3 environments

  1. DEV
  2. RELEASE
  3. Google Play(Production)

ANDROID provides separate SHA-1 Keys for the above-mentioned environemnts.
With these SHA-1 keys, you can create 3 Oauth projects. Now you have 3 Oauth google projects that you can configure with 3 separate branches(dev, release, prod) of your project.

FOR IOS

You can create as many Oauth google projects as you like.
Just keep the GoogleService-Info.plist of your Oauth google project depending upon the environment in the ios folder at the time of making the build.

Have two GoogleService-Info.plist in one target in XCode

I use the following solution:

Create a GoogleService-CONFIGURATION-Info.plist file for every XCode configuration. Don't link the files to a target.

Add a Run Script Build Phase:

cp ${SRCROOT}/Resources/Firebase/GoogleService-${CONFIGURATION}-Info.plist ${CONFIGURATION_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/GoogleService-Info.plist

Could not find a valid GoogleService-Info.plist after handle different configuration in Build phrase

I believe there are multiple issues in your approach

Issue 1:

I believe simply copying the file to the folder will not help, you need to add the file to project and change its target membership to the specific target you are running. You need to add the file to Copy Bundle Resources in build phase of specific target you are running with.

Issue 2:

Also though you have changed the filename of GoogleService-info.plist name Firebase is still looking for GoogleService-info.plist and not your renamed file hence the crash.

As mentioned here github.com/firebase/quickstart-ios/issues/5 you can not change the filename, file has to be named as GoogleService-info.plist. So copying entire file would not work.

Probable Solution:

Rather than copying the file what you can do is have a empty plist file named GoogleService-info.plist make sure you have its target membership correctly ticked and also added to Copy Bundle Resource of your target. Copy other GoogleService-Info-Configuration.plist file as well to your project.

Then, in your run script, read the content from specific GoogleService-Info-{Configuration}.plist and simply copy the content of file to your GoogleService-info.plist

Using something like

cat "${SRCROOT}/Test/Resourses/Firebase/GoogleService-Info-$CONFIGURATION.plist"  > "${SRCROOT}/Test/Resourses/Firebase/GoogleService-Info.plist"

Or as OP mentioned in his comment use

cp "${SRCROOT}/Turf/Resourses/Firebase/GoogleService-Info-$CONFIGURATION.plist" "${SRCROOT}/Turf/Resourses/Firebase/GoogleService-Info.plist"

I have not tested above pasted shell Script, though it should give you fairly simple idea how to approach the problem.



Related Topics



Leave a reply



Submit