Could not locate configuration file GoogleService-Info.plist when using FirebaseApp.configure(options:)
Asked Answered
D

5

8

In my project I have different targets for the same app with different configurations (Production / Staging / QA). As suggested by the Firebase docs I added a plist file for each trarget and initializing FirebaseApp by passing the correct configuration file in this way:

let configPath = Bundle.main.path(forResource: NAME_OF_PLIST_FOR_CURRENT_TARGET ofType: ".plist")!
let options = FirebaseOptions(contentsOfFile: configPath)!
FirebaseApp.configure(options: options)

I also removed from my project the GoogleService-Info.plist file as suggested in docs here to ensure reliable Analytics reports.

When I run the app in the console I see these messages.

[Firebase/Core][I-COR000012] Could not locate configuration file: 'GoogleService-Info.plist'.
[Firebase/Analytics][I-ACS020006] Google App ID from GoogleService-Info.plist is empty. Please, define GOOGLE_APP_ID in GoogleService-Info.plist for Analytics to work reliably. See
[Firebase/Analytics][I-ACS025020] Analytics requires Google App ID from GoogleService-Info.plist. Your data may be lost. Google App ID has been changed. Original, new ID: (nil), MYAPPID 

Am I doing something wrong? Could this configuration lead to lost Analytics? (as console message suggest)

Dickinson answered 25/9, 2019 at 12:45 Comment(5)
Try to follow step 4 under "Add Firebase to your app": firebase.google.com/docs/ios/setup#prerequisitesAdrienneadrift
Do you mean "Add Firebase SDKs to your app"? I already added 'Firebase/Core' to the project. Also, when using a single GoogleService-Info.plist everything works (my app is in production already and Analytics is working).Dickinson
Have you checked each configuration? Are they all behaving exactly the same? Based on that error message, it looks like the FirebaseOptions are not getting set properly (especially since you're not using the default file name any more).Wappes
I downloaded configuration files from Firebase Console. Also in the debugger if I check the value of options.googleAppID before passing options to FirebaseApp.configure I get the correct value.Dickinson
I had a similar issue, so I left the original file name, I moved files into folders and set Target Memberships according to the Target. Did you try that?Psaltery
P
16

When you use flutter:

I ran the flutter cli to add Firebase to my project, using the flutterfire configure command. This added the GoogleService_Info.plist to my project, but didn't register the file in the .xcworkspace file.

So I had to right-click on the Runner-folder in Xcode, choose Add Files to "Runner"..., and select the file GoogleService_Info.plist

Psittacosis answered 12/2, 2023 at 12:40 Comment(0)
D
5

After several attempts it seemed that, despite the error messages in the console, Firebase was configured correctly.

Nonetheless I decided to adopt the solution proposed by @Micgal, thus having multiple files named GoogleService-Info.plist in separate filesystem directories and adding each one to the corresponding target. I can then initialize Firebase with FirebaseApp.configure() which works as expected without generating error messages.

Dickinson answered 27/9, 2019 at 15:12 Comment(0)
C
2

Alternative workaround to having separate folders for GoogleService-Info.plist is adding additional step in Build Phases, to copy appropriate file. Just go to Targets / Build Phases and add new script by clicking on "New Run Script Phase". Script could be something like:

cp "${SRCROOT}/${PROJECT}/${FIREBASE_CONFIG_FILE}.plist" "${TARGET_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/GoogleService-Info.plist"

where FIREBASE_CONFIG_FILE is defined in Build Settings as User-Defined settings which has different values for various configurations. And then just calling FirebaseApp.configure().

There is also a dedicated ticket on Firebase github

Build Phases

Castrato answered 3/5, 2020 at 14:43 Comment(0)
F
0

maybe you have to add this needed file (GoogleService-Info.plist) to you project ressources. Open yourproject.xcworkspace in Xcode and in the Project navigator click right on Ressources folder and select 'Add files to...'.

Fleming answered 15/1, 2020 at 22:48 Comment(0)
P
0

Select the GoogleService-Info.plist in the left pane, then uncheck/recheck the Target Membership checkbox for your project.

Right panel target membership

Pimiento answered 20/10, 2022 at 18:5 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.