shanshan_ttzi
shanshan_ttzi

Reputation: 35

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

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.

Upvotes: 2

Views: 8541

Answers (2)

Vario
Vario

Reputation: 530

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.

Upvotes: 0

Sandeep Bhandari
Sandeep Bhandari

Reputation: 20379

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.

Upvotes: 4

Related Questions