Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[iOS] Update to support Firebase SDK v6 #9

Closed
dpa99c opened this issue Jun 21, 2019 · 47 comments
Closed

[iOS] Update to support Firebase SDK v6 #9

dpa99c opened this issue Jun 21, 2019 · 47 comments
Labels
feature request New feature request

Comments

@dpa99c
Copy link
Owner

dpa99c commented Jun 21, 2019

The plugin currently defaults to Version 5.20.2 which is the final v5.x released on 10 April 2019.

However as of now, the most recent release is Version 6.3.0 released on 19 June 2019.

v6.x contains breaking changes so the plugin code needs updating before v6.x of the SDK can be used.

@svzi
Copy link

svzi commented Jun 25, 2019

@dpa99c I'm trying to upgrade from cordova-plugin-firebase to cordova-plugin-firebasex in another project of mine. Sadly I can't build the iOS project. Looks like the pod installation fails:

 ~> pod install
Analyzing dependencies
[!] CocoaPods could not find compatible versions for pod "GoogleUtilities/MethodSwizzler":
  In snapshot (Podfile.lock):
    GoogleUtilities/MethodSwizzler (= 6.2.0, ~> 6.0)

  In Podfile:
    Firebase/Performance (= 5.20.2) was resolved to 5.20.2, which depends on
      FirebasePerformance (= 2.2.4) was resolved to 2.2.4, which depends on
        GoogleUtilities/MethodSwizzler (~> 5.2)

Specs satisfying the `GoogleUtilities/MethodSwizzler (= 6.2.0, ~> 6.0), GoogleUtilities/MethodSwizzler (~> 5.2)` dependency were found, but they required a higher minimum deployment target.

I'm using version 3.0.1 of this plugin (and Android works like a charm).

This is the corresponding entry in my config.xml:

    <plugin name="cordova-plugin-firebasex" spec="^3.0.1">
        <variable name="ANDROID_PLAY_SERVICES_TAGMANAGER_VERSION" value="17.0.0" />
        <variable name="ANDROID_FIREBASE_CORE_VERSION" value="17.0.0" />
        <variable name="ANDROID_FIREBASE_MESSAGING_VERSION" value="19.0.0" />
        <variable name="ANDROID_FIREBASE_CONFIG_VERSION" value="18.0.0" />
        <variable name="ANDROID_FIREBASE_PERF_VERSION" value="18.0.0" />
        <variable name="ANDROID_FIREBASE_AUTH_VERSION" value="18.0.0" />
        <variable name="ANDROID_CRASHLYTICS_VERSION" value="2.9.8" />
        <variable name="ANDROID_SHORTCUTBADGER_VERSION" value="1.1.22" />
        <variable name="IOS_FIREBASE_CORE_VERSION" value="5.20.2" />
        <variable name="IOS_FIREBASE_AUTH_VERSION" value="5.20.2" />
        <variable name="IOS_FIREBASE_MESSAGING_VERSION" value="5.20.2" />
        <variable name="IOS_FIREBASE_PERFORMANCE_VERSION" value="5.20.2" />
        <variable name="IOS_FIREBASE_REMOTECONFIG_VERSION" value="5.20.2" />
        <variable name="IOS_FABRIC_VERSION" value="1.9.0" />
        <variable name="IOS_CRASHLYTICS_VERSION" value="3.12.0" />
    </plugin>

@dpa99c
Copy link
Owner Author

dpa99c commented Jun 25, 2019

GoogleUtilities/MethodSwizzler (~> 5.2)` dependency were found, but they required a higher minimum deployment target.

Looks like the target (min) SDK for iOS is set lower than what GoogleUtilities requires.
Mine is set to iOS 10.0 in my test project - check what yours is set to.

@svzi
Copy link

svzi commented Jun 25, 2019

Where do I need to check? 🤔

@dpa99c
Copy link
Owner Author

dpa99c commented Jun 25, 2019

Open the project in Xcode and look under "General" for Target under Deployment Info - here's a screenshot of my test project in Xcode 11 beta:
Screenshot 2019-06-25 at 11 17 25

@svzi
Copy link

svzi commented Jun 25, 2019

Mine is already set to 11.0! 🤔

Bildschirmfoto 2019-06-25 um 12 23 18

@dpa99c
Copy link
Owner Author

dpa99c commented Jun 25, 2019

Give me a few minutes - just need fix a bug in a production build - and I'll push my test project to github so you can try building that.

@svzi
Copy link

svzi commented Jun 25, 2019

I believe that your's is building. I'm just wondering why mine isn't. Could that be because of another plugin? What else information could I paste?

Hah! I just had a look at my Podfile:

platform :ios, '9.0'
use_frameworks!
target 'DummyProject' do
	pod 'Google-Mobile-Ads-SDK', '~> 7.36'
	pod 'Firebase/Core', '5.20.2'
	pod 'Firebase/Auth', '5.20.2'
	pod 'Firebase/Messaging', '5.20.2'
	pod 'Firebase/Performance', '5.20.2'
	pod 'Firebase/RemoteConfig', '5.20.2'
	pod 'Fabric', '1.9.0'
	pod 'Crashlytics', '3.12.0'
end

Interesting. iOS 9, uh? Just changed it, trying it again...

@dpa99c
Copy link
Owner Author

dpa99c commented Jun 25, 2019

@dpa99c
Copy link
Owner Author

dpa99c commented Jun 25, 2019

We should probably either get rid of that or make it configurable in this fork of the firebase plugin

@svzi
Copy link

svzi commented Jun 25, 2019

I removed it manually, but it didn't change anything. Now I'm just removing ios platform and re-add it afterwards...

@svzi
Copy link

svzi commented Jun 25, 2019

I'm not getting it to work. :-(

@dpa99c
Copy link
Owner Author

dpa99c commented Jun 25, 2019

Try cloning and building this example project.

I've got it building and running on both Android & iOS though currently not getting a device token on iOS - investigating why that is - might have been my updating of the Firebase SDK for iOS that did it...

@svzi
Copy link

svzi commented Jun 25, 2019

I can build that project (at least after changing the package-id), but it won't run because of the missing GoogleService-Info.plist.

So it should not have anything to do with the platform :ios, '9.0' definition in the Podfile, because it's the same definition for your test project and my real project.

@dpa99c dpa99c added feature request New feature request TODO Something needs doing labels Jun 25, 2019
@svzi
Copy link

svzi commented Jun 25, 2019

I did try to change this line manually in my plugins (and node_modules/cordova-plugin-firebase/) folder:
https://github.com/dpa99c/cordova-plugin-firebase/blob/master/plugin.xml#L105

After that I removed the ios platform and re-added it, but nothing changed:

 ~> pod install
Analyzing dependencies
[!] CocoaPods could not find compatible versions for pod "GoogleUtilities/MethodSwizzler":
  In snapshot (Podfile.lock):
    GoogleUtilities/MethodSwizzler (= 6.2.0, ~> 6.0)

  In Podfile:
    Firebase/Performance (= 5.20.2) was resolved to 5.20.2, which depends on
      FirebasePerformance (= 2.2.4) was resolved to 2.2.4, which depends on
        GoogleUtilities/MethodSwizzler (~> 5.2)

Specs satisfying the `GoogleUtilities/MethodSwizzler (= 6.2.0, ~> 6.0), GoogleUtilities/MethodSwizzler (~> 5.2)` dependency were found, but they required a higher minimum deployment target.

This is my current Podfile:

platform :ios, '11.0'
use_frameworks!
target 'DummyProject' do
	pod 'Google-Mobile-Ads-SDK', '~> 7.44'
	pod 'Firebase/Core', '5.20.2'
	pod 'Firebase/Auth', '5.20.2'
	pod 'Firebase/Messaging', '5.20.2'
	pod 'Firebase/Performance', '5.20.2'
	pod 'Firebase/RemoteConfig', '5.20.2'
	pod 'Fabric', '1.9.0'
	pod 'Crashlytics', '3.12.0'
end

Looks like what I did wasn't enough.

@dpa99c
Copy link
Owner Author

dpa99c commented Jun 25, 2019

Couple of related issues:

From the comments there it's worth trying pod repo update && rm -Rf platforms/ios/ && cordova platform add ios

@svzi
Copy link

svzi commented Jun 25, 2019

That fixes it temporary, but a new pod issue occurs now:

 ~> pod update
Update all pods
Updating local specs repositories
Analyzing dependencies
[!] CocoaPods could not find compatible versions for pod "GoogleAppMeasurement":
  In Podfile:
    Firebase/Performance (= 5.20.2) was resolved to 5.20.2, which depends on
      Firebase/Core (= 5.20.2) was resolved to 5.20.2, which depends on
        FirebaseAnalytics (= 5.8.1) was resolved to 5.8.1, which depends on
          GoogleAppMeasurement (= 5.8.1)

    Google-Mobile-Ads-SDK (~> 7.44) was resolved to 7.46.0, which depends on
      GoogleAppMeasurement (~> 6.0)

And the old issue re-appears as soon as I drop the platform and re-add it. I need to run pod update to produce the new issue...

@dpa99c
Copy link
Owner Author

dpa99c commented Jun 25, 2019

Looks like one of the other plugins in your project is pulling in Google-Mobile-Ads-SDK which is requiring a newer version of GoogleAppMeasurement than is supported by Firebase SDK v5.20.2

I think that should get fixed when the the original title of this issue is resolved, i.e. update to Firebase SDK v6 - the newer version will probably request a newer version of GoogleAppMeasurement

@svzi
Copy link

svzi commented Jun 25, 2019

Do you have any timetable for the upgrade to Firebase SDK v6? I wouldn't mind donating some bucks for your effort.

@dpa99c
Copy link
Owner Author

dpa99c commented Jun 25, 2019

I haven't looked at what the breaking changes exactly are with v6.
I think I'll just include the latest v6 into an iOS build, see what breaks and try to fix it 😄
I'll have a go at that over the next few days.

In the meantime, maybe it's possible to track down where Google-Mobile-Ads-SDK is being pulled into your build and see if you can pin it to an older version that also depends on GoogleAppMeasurement@5.8.1 (i.e. same as Firebase SDK v5.20.2)

@svzi
Copy link

svzi commented Jun 25, 2019

I've already tracked that down. The source is the admob-plus plugin (see https://github.com/admob-plus/admob-plus). And to be honest, I'm not sure how to pin it to an older version. And I'm not sure, if that wouldn't probably break some functionality. I don't like that idea. For me the better way is, to wait for the SDK 6 integration. That sounds more safe and future proof. 😎

@dpa99c
Copy link
Owner Author

dpa99c commented Jun 26, 2019

I had a go at migrating to Firebase SDK v6 on iOS last night.

I've managed to resolve all the build-time issues so far except one ([[FIRMessaging messaging] connectWithCompletion]] no longer exists so I need to find what the v6 alternative is).

Once that's done, it should build and run but I expect there'll be some runtime issues I need to diagnose and fix.

@svzi
Copy link

svzi commented Jun 26, 2019

Thank you very much for keeping us noted! Appreciate the time and effort you put into this. Hopefully you will have less runtimes issues than expected.

@dpa99c
Copy link
Owner Author

dpa99c commented Jun 26, 2019

I've resolved that last issue and pushed a preliminary version to the dev branch - you can try it by installing as follows:

cordova plugin add https://github.com/dpa99c/cordova-plugin-firebase#dev

So far the runtime activity looks to be working OK.
I've updated my test project to test APNS on iOS and seems to work OK.

@svzi
Copy link

svzi commented Jun 26, 2019

Can't install:

 ~> cordova plugin add https://github.com/dpa99c/cordova-plugin-firebase#dev
Installing "cordova-plugin-firebasex" for ios
Installing "cordova-plugin-cocoapod-supportx" for ios
Installing "cordova-plugin-androidx" for ios
Failed to install 'cordova-plugin-firebasex': Error: Cannot find module 'cordova-lib'
    at Function.Module._resolveFilename (module.js:547:15)
    at Function.Module._load (module.js:474:25)
    at Module.require (module.js:596:17)
    at require (internal/module.js:11:18)
    at Object.getAppName (/Users/svzi/development/_own/DummyProject/app/plugins/cordova-plugin-firebasex/scripts/lib/utilities.js:27:24)
    at Object.getXcodeProjectPath (/Users/svzi/development/_own/DummyProject/app/plugins/cordova-plugin-firebasex/scripts/ios/helper.js:22:29)
    at module.exports (/Users/svzi/development/_own/DummyProject/app/plugins/cordova-plugin-firebasex/scripts/ios/after_plugin_install.js:7:35)
    at runScriptViaModuleLoader (/usr/local/lib/node_modules/cordova/node_modules/cordova-lib/src/hooks/HooksRunner.js:196:18)
    at runScript (/usr/local/lib/node_modules/cordova/node_modules/cordova-lib/src/hooks/HooksRunner.js:172:16)
    at /usr/local/lib/node_modules/cordova/node_modules/cordova-lib/src/hooks/HooksRunner.js:140:20
Cannot find module 'cordova-lib'

@svzi
Copy link

svzi commented Jun 26, 2019

Your test project is using version 3.0.5:

"cordova-plugin-firebasex": "^3.0.5"

Not the dev branch?!

@dpa99c
Copy link
Owner Author

dpa99c commented Jun 26, 2019

git clone https://github.com/dpa99c/cordova-plugin-firebase-test && cd cordova-plugin-firebase-test
git checkout dev
cordova platform add ios

@dpa99c
Copy link
Owner Author

dpa99c commented Jun 26, 2019

You'll need to change the package ID in the test project to one which you have control over (i.e. in your Apple Team ID and Firebase project) but if you've got it all setup correctly, you should be able to send a push notification via the Firebase Console and see something like this in the iOS test app:

@svzi
Copy link

svzi commented Jun 26, 2019

Thanks, I've tried again and got it to work. The app is building and running right now. That's a very good starting point. But the device log shows that it's not working the way I expect it to work:

WARN: Ionic Native: tried calling Firebase.setScreenName, but the Firebase plugin is not installed.
WARN: Install the Firebase plugin: 'ionic cordova plugin add cordova-plugin-firebase' 
...
WARN: Ionic Native: tried calling Firebase.logEvent, but the Firebase plugin is not installed.
WARN: Install the Firebase plugin: 'ionic cordova plugin add cordova-plugin-firebase'
...

I'm using a wrapper in my Ionic app: @ionic-native/firebase.

It looks like this wrapper is somehow referencing the original plugin:
https://github.com/ionic-team/ionic-native/blob/master/src/%40ionic-native/plugins/firebase/index.ts#L32

Looks like I should get rid of the wrapper. That would probably be the easiest way. At least easier than patching the Ionic-Native Plugin, or what do you think about? I'm using this wrapper only for Notifications and Analytics (two services in total). So I think I will rewrite them, and remove the wrapper.

@svzi
Copy link

svzi commented Jun 26, 2019

Nevermind, I just checked my two services in more detail and I discovered only 3 lines of code in total, that use the wrapper. So please don't worry about my questions in the last post. 😂

@svzi
Copy link

svzi commented Jun 26, 2019

Any plans to merge the dev-branch into master and make a new NPM release?

@dpa99c
Copy link
Owner Author

dpa99c commented Jun 26, 2019

I was just keeping it on the dev branch until you can give it a sanity check - if you're happy with it, I'll merge it to master and do an npm release.

@svzi
Copy link

svzi commented Jun 26, 2019

I will do some more testing tomorrow morning and let you know about my results! No way to rush things.

@dpa99c
Copy link
Owner Author

dpa99c commented Jun 26, 2019

👍

@svzi
Copy link

svzi commented Jun 27, 2019

To be honest: yesterday my project didn't install the cordova-plugin-firebasex. I just missed the error messages, but after digging into the Ionic-Native wrapper and some tries to get my few lines of codes running without it, I've noticed that the package simple wasn't installed in my node_modules folder. For that reason it didn't work, because the plugin wasn't installed.

But as of today I'm still unable to install this branch into my main project. Just to be clear, cloning and running your sample projects works fine. But I need to get this running in my real project. Not sure why it doesn't work.

I've removed all references of cordova-plugin-firebasex from my package.json and config.xml files. After that I run the following commands:

rm -rf platforms/ plugins/ node_modules/  
rm package-lock.json  
npm install

All fine. Then I add the plugin:

 ~> cordova plugin add https://github.com/dpa99c/cordova-plugin-firebase#dev
Adding cordova-plugin-firebasex to package.json
Saved plugin info for "cordova-plugin-firebasex" to config.xml

Works as well. But when I add the iOS platform:

 ~> cordova platform add ios@5.0.1
Using cordova-fetch for cordova-ios@5.0.1
Adding ios project...
Creating Cordova project for the iOS platform:
	Path: platforms/ios
	Package: com.svzi.dummyproject
	Name: DummyProject
iOS project created with cordova-ios@5.0.1
Installing "cordova-plugin-firebasex" for ios
Installing "cordova-plugin-cocoapod-supportx" for ios
Installing "cordova-plugin-androidx" for ios
Failed to install 'cordova-plugin-firebasex': Error: Cannot find module 'cordova-lib'
    at Function.Module._resolveFilename (module.js:547:15)
    at Function.Module._load (module.js:474:25)
    at Module.require (module.js:596:17)
    at require (internal/module.js:11:18)
    at Object.getAppName (/Users/svzi/development/_own/DummyProject/app/plugins/cordova-plugin-firebasex/scripts/lib/utilities.js:27:24)
    at Object.getXcodeProjectPath (/Users/svzi/development/_own/DummyProject/app/plugins/cordova-plugin-firebasex/scripts/ios/helper.js:22:29)
    at module.exports (/Users/svzi/development/_own/DummyProject/app/plugins/cordova-plugin-firebasex/scripts/ios/after_plugin_install.js:7:35)
    at runScriptViaModuleLoader (/usr/local/lib/node_modules/cordova/node_modules/cordova-lib/src/hooks/HooksRunner.js:196:18)
    at runScript (/usr/local/lib/node_modules/cordova/node_modules/cordova-lib/src/hooks/HooksRunner.js:172:16)
    at /usr/local/lib/node_modules/cordova/node_modules/cordova-lib/src/hooks/HooksRunner.js:140:20
Cannot find module 'cordova-lib'

Do you have any clue what's going on? Why is your sample project installing this dev branch without any issue, but my main project doesn't work?

@dpa99c
Copy link
Owner Author

dpa99c commented Jun 27, 2019

I added an explicit dependency on cordova-lib in the package.json so I don't understand: npm install should be installing it to node_modules/cordova-lib so when the plugin hook script requires it, it should not cause the above error.

Can you check if the cordova-lib directory is being created in node_modules and if so what the version is in its package.json?

I made the dependency on cordova-lib@^9.0.0 - a quite recent version - so maybe there's a version conflict?
You could try running npm list | grep cordova-lib too see if more than 1 version is referenced.

@svzi
Copy link

svzi commented Jun 27, 2019

There is no node_modules/cordova-lib folder in my project. And btw:

 ~> cordova --version
8.1.2 (cordova-lib@8.1.1)

And your request:

 ~> npm list | grep cordova-lib
npm ERR! missing: cordova-plugin-firebasex@git+https://github.com/dpa99c/cordova-plugin-firebase.git#dev, required by dummyproject@2.0.12

@dpa99c
Copy link
Owner Author

dpa99c commented Jun 27, 2019

aha! 💡
I wonder if Cordova/NPM is getting confused because the npm package name is cordova-plugin-firebasex but the Git repo is called cordova-plugin-firebase?
Either way, it seems not to be happy when installing the plugin from my git repo but happy when installing it from npm.

So, another idea - clone the plugin repo and install the plugin from it locally:

cd /some/tmp/dir/ && git clone https://github.com/dpa99c/cordova-plugin-firebase
cd cordova-plugin-firebase && git checkout dev
cd /your/app/dir && npm install /some/tmp/dir/cordova-plugin-firebase

@svzi
Copy link

svzi commented Jun 27, 2019

I've replaced npm install /some/tmp/dir/cordova-plugin-firebase with cordova plugin add /some/tmp/dir/cordova-plugin-firebase and it works like a charm!

Btw, the cordova-lib gets installed into node_modules/cordova-plugin-firebasex/node_modules and not into node_modules/cordova-lib as I initially understood.

While running on iOS I've noticed one message in the system log, that I probaby didn't notice before:

PID: 1914, TID: 2763213, Thread name: (none), Queue name: com.apple.root.default-qos, QoS: 0
Backtrace:
4   DummyProject                         0x00000001006a8d64 __33-[FirebasePlugin setBadgeNumber:]_block_invoke + 104
5   libdispatch.dylib                   0x00000001014f36f0 _dispatch_call_block_and_release + 24
6   libdispatch.dylib                   0x00000001014f4c74 _dispatch_client_callout + 16
7   libdispatch.dylib                   0x00000001014f7ad4 _dispatch_queue_override_invoke + 876
8   libdispatch.dylib                   0x0000000101505dc8 _dispatch_root_queue_drain + 372
9   libdispatch.dylib                   0x00000001015067ac _dispatch_worker_thread2 + 156
10  libsystem_pthread.dylib             0x00000001a7dfd1b4 _pthread_wqthread + 464
11  libsystem_pthread.dylib             0x00000001a7dffcd4 start_wqthread + 4

Should that worry me?

@dpa99c
Copy link
Owner Author

dpa99c commented Jun 27, 2019

looks like a warning rather than an error - was it preceded by a message something like this?

Main Thread Checker: UI API called on a background thread

Might be a pre-existing issue if the plugin is performing UI operations on a bg thread, but not a major blocker

@svzi
Copy link

svzi commented Jun 27, 2019

Yes, the message is preceded by that text. Thanks for the info!

So from my point of view everything seems to work. The only functionality I did not test with my app, is the notification handling. My sends one push notification each day, but in the morning. So I will check tomorrow if that did work. But requesting permissions for notifications worked. So I assume the rest will work as well.

@dpa99c
Copy link
Owner Author

dpa99c commented Jun 27, 2019

I've tested APNS push notifications via the Firebase Console and they worked fine, so on that basis I think this version is good to release. I'll merge to master and release to npm shortly.

@dpa99c
Copy link
Owner Author

dpa99c commented Jun 27, 2019

Published to npm as v3.0.6

@dpa99c dpa99c closed this as completed Jun 27, 2019
@svzi
Copy link

svzi commented Jun 27, 2019

I'm observing some interesting behavior. I can build and run my code via XCode, but I usually build via cli, to enable some optimizations (minify & aot). For whatever reason, the build via cli hangs at some point (no matter if I try a release build or not):

CompileSwiftSources normal armv7 com.apple.xcode.tools.swift.compiler (in target: DummyProject)
    cd /Users/svzi/development/_own/DummyProject/app/platforms/ios
    export DEVELOPER_DIR=/Applications/Xcode.app/Contents/Developer
    export SDKROOT=/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS12.2.sdk
    /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swiftc -incremental -module-nameDummyProject -Onone -enable-batch-mode -enforce-exclusivity=checked -sdk /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS12.2.sdk............

Do you have any idea why?

@dpa99c
Copy link
Owner Author

dpa99c commented Jun 27, 2019

No idea why it would hang: I just tried cordova build ios in my test project and it succeeded - does that work for you?

@svzi
Copy link

svzi commented Jun 27, 2019

I just figured out that the build only hangs with the ionic cli, which in some cases should serve as a wrapper around cordova. When I build right away with cordova cli, the build went through. So it seems like it has nothing to do with your changes, but I can't say for sure. 🤷‍♂️

@dpa99c
Copy link
Owner Author

dpa99c commented Jun 27, 2019

maybe best thing is to try to create an isolated test project where you can repro the problem then raise as issue against ionic which references that project as evidence

@svzi
Copy link

svzi commented Jun 27, 2019

Good idea, will try to! Thanks a lot, again. :-)

@dpa99c dpa99c removed the TODO Something needs doing label Jun 26, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request New feature request
Projects
None yet
Development

No branches or pull requests

2 participants