2

I am working on use firebase to tag in application iOS.

I have different configuration in app, dev, prod, preprod, appStore. So I have several GoogleService-Info.plist in project.

I renamed them as GoogleService-Info-Prod.plist, GoogleService-Info-Dev.plist, in a folder Resources.

I've add a run script in the build phrase of project,

cp "${SRCROOT}/Test/Resourses/Firebase/GoogleService-Info-$CONFIGURATION.plist" "${SRCROOT}/Test/Resourses/Firebase/GoogleService-Info.plist" I intent to cp the content of GoogleService-Info-blabla.plist into GoogleService-Info.plist.

But apparently, I've got this error:

2018-07-02 19:05:27.295083+0200 Test [PROD][63021:19806839] *** Terminating app due to uncaught exception 'com.firebase.core', reason: '[FIRApp configure]; (FirebaseApp.configure() in Swift) could not find a valid GoogleService-Info.plist in your project. Please download one from https://console.firebase.google.com/.'

Any idea that where I made mistake? Thank you so much for you attention.

shanshan_ttzi
  • 35
  • 1
  • 7

2 Answers2

4

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.

Sandeep Bhandari
  • 19,999
  • 5
  • 45
  • 78
  • 1
    I added a empty GoogleService.plist and use this script : cp "${SRCROOT}/Turf/Resourses/Firebase/GoogleService-Info-$CONFIGURATION.plist" "${SRCROOT}/Turf/Resourses/Firebase/GoogleService-Info.plist" works nice, Thanks for your help :) – shanshan_ttzi Jul 03 '18 at 09:16
  • @shanshan-ttzi : Sorry buddy I was confused, yup the cp command will work fine :) Cheers :) Happy coding – Sandeep Bhandari Jul 03 '18 at 09:39
0

Although this is a rather old question, there is a better solution here. You can initialise firebase with an options parameter. There the desired GoogleService-Info.plist file can be defined

let options = FirebaseOptions(contentsOfFile: Bundle.main.path(forResource: Constants.Firebase.plistFileName, ofType: "plist")!)!
FirebaseApp.configure(options: options)

For example, i defined in a separate constants file the different files for stage/test and production. In this file i distinguish with environment variables the different values for the constants.

Vario
  • 490
  • 4
  • 13
  • cannot find 'Constants' in scope. i was got this error. what because of? – Michael Fernando Nov 03 '21 at 04:16
  • Hey @MichaelFernando as described below the code, Constants is a File, where different structs with static variables are defined which are used in the project. e.g struct Firebase { static let plistFileName = "GoogleService-Info" } Just enter the name of your Google-Info file :-) – Vario Nov 03 '21 at 10:29
  • oh, i forgot with this. thx u for explaining it – Michael Fernando Nov 03 '21 at 17:35
  • you are welcome. Let me know if the answer works for you. I use this global Constants File for all sorts of values which should be defined once to keep it in one place – Vario Nov 04 '21 at 06:33