Reputation: 1138
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)
Upvotes: 9
Views: 30437
Reputation: 1581
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
Upvotes: 21
Reputation: 537
Select the GoogleService-Info.plist in the left pane, then uncheck/recheck the Target Membership checkbox for your project.
Upvotes: 0
Reputation: 832
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
Upvotes: 3
Reputation: 69
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...'.
Upvotes: 0
Reputation: 1138
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.
Upvotes: 5