EddyVerbruggen / nativescript-plugin-firebase

:fire: NativeScript plugin for Firebase
https://firebase.google.com
MIT License
1.01k stars 444 forks source link

[iOS] Hook is called after successful sync application on device #1541

Open faelperetta opened 4 years ago

faelperetta commented 4 years ago

[iOS] "nativescript-plugin-firebase": "10.3.3"

When I run the application with "tns run ios" the application is deploy successfully on device. But, right after finishing syncronization the nativescript-plugin-firebase hook is called again and starts a new build/sync and the install works but the application crash because the GoogleService-Info.plist is not found anymore.

This problem only occurs when I'm using the separation of environments approach. In my project I have these files: GoogleService-Info.plist.dev and GoogleService-Info.plist.prod. If I remove these files and just use one GoogleService-Info.plist the build only occurs one time and the application works as expected.

This is what happens:

Successfully synced application com.wiboo.wibx.devapplication on device XXXX.
nativescript-plugin-firebase: building for same environment, not forcing prepare.
pnilesh10 commented 4 years ago

I encountered same problem and saw there are some issues open as well. I still haven't understood whole flow but would like to tell how I fixed it. After adding plist.dev & plist.prod; it was working for prod but started crashing for dev. when I debugged; it was firebase plugin not able to configure because it didn't find plist file.

JS Stack: 1 configure@[native code] 2 @file:///app/vendor.js:103661:37 3 ZoneAwarePromise@file:///app/vendor.js:100193:37 4 init@file:///app/vendor.js:103634:23 5 initFirebase@file:///app/bundle.js:425:22 6 ngOnInit@file:///app/bundle.js:421:26

I started looking into code and found out it deletes plist file to avoid git issues. File: hooks/after-prepare/firebase-copy-google-services.js(line no 77)

I did put logger statement and verified.

Command: tns debug ios --device "iPhone 11 Pro"

nativescript-plugin-firebase: <your project>/platforms/ios/.pluginfirebaseinfo not found, forcing prepare!
nativescript-plugin-firebase: running release build or change in environment detected, forcing prepare!
nativescript-plugin-firebase: copy <your project>/app/App_Resources/iOS/GoogleService-Info.plist.dev to <your project>/app/App_Resources/iOS/GoogleService-Info.plist.
Preparing project...
Installing pods...
*****************
Configure firebase
------> nativescript-plugin-firebase: Deleting <your project>/app/App_Resources/iOS/GoogleService-Info.plist (My logger statement)
Building project...
Xcode build...
Project successfully built.

as you can see above..it is deleting the file before Xcode starts building..so I am not entirely sure what is happening, but Xcode doesn't get plist file and then obviously firebase initialization fails.

Solution: I knew; to put NativeScript app on devices we need to prepare project in --release mode.(command: tns prepare ios --release)

also, picking up .dev or .prod plist is based on prepare command options(--release for plist.prod and default plist.dev). So what I did was; cleaned platform(tns platform clean ios) and ran tns prepare ios (without --release option). which correctly configured my Xcode project and now when I run tns run ios, it works and no longer crashes the app. I think you have to run this every time you clean platform since it resets Xcode project.

Hope this helps.

PS: I didn't get much from the JS stack so I opened .xcworkspace project and ran app; it pinpointed me to the exact cause.