Nativescript-plugin-firebase: Running in debug works, running in release on iOS causes crash

Created on 17 Oct 2016  路  30Comments  路  Source: EddyVerbruggen/nativescript-plugin-firebase

Plugin works flawlessly on Android but on iOS causes crash. I am running iOS runtime 2.3.0, with device iOS versions ranging from 8-10. If I run a "hello-world" type, basic application and initialize the plugin, the app crashes prior to the splashscreen disappearing. When building for development the app runs and receives notifications with no issue, but only happens when I publish and sign the app. Not sure what i'm missing if it's something configuration related, but all plist files are in place.

Side note: If I run the app without the plugin being initialized, I have zero issues.

_Nativescript version: 2.3.0_

bug

Most helpful comment

Thanks guys for confirming. Will update npm very soon!

Update: done (3.7.2)

All 30 comments

I had this same issue and disabling the Firebase/Crash pod did the trick.

That's not good :(

Can you guys tell me the quickest way to run the app in release mode?

@austinlarue - could you explain what steps you took to disable the pod? I believe I did so correctly in my podfile (see below), just not having any luck with that as a solution. Maybe I am missing something.

` pod 'Firebase', '~> 3.7.0'
pod 'Firebase/Database'
pod 'Firebase/Auth'
#pod 'Firebase/Crash'

# Uncomment if you want to enable Remote Config
#pod 'Firebase/RemoteConfig'

# Uncomment if you want to enable FCM (Firebase Cloud Messaging)
pod 'Firebase/Messaging'

# Uncomment if you want to enable Firebase Storage
#pod 'Firebase/Storage'

# Uncomment if you want to enable Facebook Authentication
#pod 'FBSDKCoreKit'
#pod 'FBSDKLoginKit'

# Uncomment if you want to enable Google Authentication
#pod 'GoogleSignIn' 

# End Podfile `

@mschahczinski That looks about right, perhaps you'll need to re-add the iOS platform (and the lib/ios folder) as well to get rid of lingering bits.

@EddyVerbruggen - Tried that as well, but when you re-add the platform, the pod file is recreated. When building it adds the 'Firebase/Crash' dependency back to the pod file. Commenting it out again and rebuilding works, but still getting the crash on startup.

Here is a snippet of the crash log from the firebase console (prior to removing the crash pod):
Exception name: EXC_BAD_ACCESS / KERN_INVALID_ADDRESS 1 NativeScript 4304733816 + 132728 2 NativeScript 4304733804 + 132716 3 NativeScript 4304856088 + 255000 4 NativeScript 4309956832 + 5355744 5 NativeScript 4309959088 + 5358000 6 UIKit -[UIApplication sendAction:to:from:forEvent:] + 284588 7 UIKit -[UIControl sendAction:to:forEvent:] + 284460 8 UIKit -[UIControl _sendActionsForEvents:withEvent:] + 195552 9 UIKit -[UIControl touchesEnded:withEvent:] + 282648 10 UIKit -[UIWindow _sendTouchesForEvent:] + 281408 11 UIKit -[UIWindow sendEvent:] + 261512 12 UIKit -[UIApplication sendEvent:] + 67668 13 UIKit __dispatchPreprocessedEventFromEventQueue + 8379572 14 UIKit __handleEventQueue + 8353564 15 CoreFoundation __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 905844 16 CoreFoundation __CFRunLoopDoSources0 + 904124 17 CoreFoundation __CFRunLoopRun + 894908 18 CoreFoundation CFRunLoopRunSpecific + 36932 19 GraphicsServices GSEventRunModal + 49556 20 UIKit -[UIApplication _run] + 505380 21 UIKit UIApplicationMain + 484188 22 NativeScript 4309958720 + 5357632 23 NativeScript 4309955616 + 5354528 24 NativeScript 4309954360 + 5353272 25 NativeScript 4304619128 + 18040 26 NativeScript 4307718620 + 3117532 27 NativeScript 4307744596 + 3143508 28 NativeScript 4307744612 + 3143524 29 NativeScript 4307744612 + 3143524 30 NativeScript 4307720884 + 3119796 31 NativeScript 4307378852 + 2777764 32 NativeScript 4307272108 + 2671020 33 NativeScript 4308496040 + 3894952 34 NativeScript 4304688948 + 87860 35 NativeScript 4309458500 + 4857412 36 NativeScript 4307746896 + 3145808 37 NativeScript 4307744612 + 3143524 38 NativeScript 4307744612 + 3143524 39 NativeScript 4307744612 + 3143524 40 NativeScript 4307720884 + 3119796 41 NativeScript 4307378852 + 2777764 42 NativeScript 4307272108 + 2671020 43 NativeScript 4308925524 + 4324436 44 NativeScript 4304653500 + 52412 45 NativeScript 4304895144 + 294056 46 MobileNotificationsNG 4295563692 + 22956 47 libdyld.dylib start + 17844

Thanks. Does it crash for debug and prod or only prod?

It works fine running in debug, it crashes in prod.

Note: I am exporting and signing the package with an enterprise distribution profile.

Good to know. I'll disable the crash pod in the next release as I don't think we can do much about this Firebase issue.

@EddyVerbruggen - were you able to verify the above solution provided by @austinlarue? I see there was a commit, but disabling 'Firebase/Crash' still causes a crash on my end.

@mschahczinski I'm not sure what you mean as @austinlarue says disabling the Pod fixes it, so that's what will be the case in the next release.

@EddyVerbruggen - The solution that @austinlarue proposed was applied in my project but did not fix the issue. I took the steps below to follow the solution provided.

  • removed ios platform
  • deleted node_modules, lib, and hooks directories
  • installed npm packages ( npm i )
  • in node_modules/nativescript-plugin-firebase/platforms/ios/Podfile -> commented out Firebase/crash (disabling this pod)
  • added ios platform
  • ran -> tns prepare ios
  • checked -> platforms/ios/Podfile & Podfile.lock - to make sure there were no references to Firebase/Crash ( There were none )
  • ran -> tns publish ios
  • opened exported archive in xcode
  • exported archive to .ipa file
  • installed on device

Following all of the above steps, application still crashes. If I follow the same steps above with the firebase plugin removed, the app launches and runs correctly. When I run with the plugin, I get the same errors in the crash log that I referenced earlier. Please advise if I am doing a step improperly, or if I am missing something along the way.

@mschahczinski @EddyVerbruggen I was wrong. It looks like it's the Firebase/Messaging pod that is causing the crash for me. Back when I thought it was the Crash pod, I didn't realize I had also removed the Messaging pod at the same time.

I just tried to re-publish my app yesterday after adding push notifications using this plugin and the app started crashing again while using TestFlight. I'm also receiving the same EXC_BAD_ACCESS / KERN_INVALID_ADDRESS error message in the crash log that @mschahczinski received.

@austinlarue - Thanks for the feedback, glad it's not just me.

@EddyVerbruggen - I am not sure this will help at all, but I was sifting through the physical device logs while trying to run the app and this is what's showing right before the application is terminating.
iPhone kernel(Sandbox)[0] <Notice>: SandboxViolation: logd(44) deny(1) file-read-data /private/var/containers/Bundle/Application/B44BD7B2-0A90-4FF7-B2FA-6128D3CC555E/MobileNotificationsNG.app/Frameworks/NativeScript.framework/NativeScript

Unfortunately I am not finding any more details here, just the same crash log error that @austinlarue is seeing as well. Possible to re-open this issue?

I can verify that disabling 'Firebase/Messaging' works. I can publish and run with no issues with the pod disabled, but messaging is needed in my app.

Oh bummer! Do you guys build for release by using the archiving feature of Xcode?

@EddyVerbruggen That's how I'm building it right now to try and track down the cause of this issue. This also happens when using tns publish ios

@EddyVerbruggen - Same thing here as @austinlarue ... I have tried it both ways. tns publish ios just uses the xCode command line build (as far as I know) which will essentially lead to the same end result.

@EddyVerbruggen @austinlarue - I created a basic project, installed the plugin, ran in debug and somehow received the below error when it would normally crash in a production version. This was on a physical device- It happened twice, but haven't had any luck replicating it since. Hoping this will help- maybe collectively we can figure this out.

JavaScript stack trace: 1 @file:///app/tns_modules/nativescript-plugin-firebase/firebase.js:12:44 JavaScript error: 2016-10-27 16:17:48.578235 fireTest[446:73296] file:///app/tns_modules/nativescript-plugin-firebase/firebase.js:12:44: JS ERROR TypeError: NSNotificationCenter.defaultCenter is not a function. (In 'NSNotificationCenter.defaultCenter()', 'NSNotificationCenter.defaultCenter' is an instance of NSNotificationCenter) file:///app/tns_modules/nativescript-plugin-firebase/firebase.js:12:44: JS ERROR TypeError: NSNotificationCenter.defaultCenter is not a function. (In 'NSNotificationCenter.defaultCenter()', 'NSNotificationCenter.defaultCenter' is an instance of NSNotificationCenter) (lldb)

Installed Nativescript version: 2.3.0

Package.json:

"nativescript": {
"id": "xxx.xxx.xxx",
"tns-ios": {
"version": "2.3.0"
}
},
"dependencies": {
"@angular/common": "2.1.0",
"@angular/compiler": "2.1.0",
"@angular/core": "2.1.0",
"@angular/forms": "2.1.0",
"@angular/http": "2.1.0",
"@angular/platform-browser": "2.1.0",
"@angular/platform-browser-dynamic": "2.1.0",
"@angular/router": "3.1.0",
"nativescript-angular": "1.1.0",
"nativescript-plugin-firebase": "^3.7.1",
"reflect-metadata": "~0.1.8",
"tns-core-modules": "^2.3.0"
},
"devDependencies": {
"nativescript-dev-typescript": "^0.3.2",
"typescript": "^2.0.6",
"zone.js": "~0.6.21"
}

Thanks for chipping in, @mschahczinski! The issue you've logged here was fixed in this version: https://github.com/EddyVerbruggen/nativescript-plugin-firebase/releases/tag/3.6.3, so that must have been an old file lingering around in your project.

@EddyVerbruggen - Well that would explain why I haven't been able to replicate the error... Thanks for the info.

@EddyVerbruggen I've narrowed it down to this line in firebase.ios.js in the function firebase._onTokenRefreshNotification:

var token = FIRInstanceID.instanceID().token();

Removing that line (and the subsequent code that relies on it) prevents the app from crashing but I won't receive the FCM token.

@austinlarue Strange.. that code is similar to this official sample.

Do you know what the error is?

@EddyVerbruggen @austinlarue - Have either of you seen this one? Looks to me like it's the reason we are getting the app crash on launch and definitely seems to be the culprit of @austinlarue's line of code.

file:///app/tns_modules/nativescript-plugin-firebase/firebase.js:176:65: JS ERROR ReferenceError: Metadata for "FirebaseInstanceID.kFIRInstanceIDTokenRefreshNotification" found but symbol not available at runtime.

@mschahczinski that one looks a LOT like this one. That constant may have been stripped for release build so it needs to be replaced by its actual value.

So can you try replacing kFIRInstanceIDTokenRefreshNotification by "com.firebase.iid.notif.refresh-token" and see if the crash is gone?

@EddyVerbruggen - Following your instructions worked like a charm! What will need to be changed to fix the plugin long-term as hard-coding is not a great solution?

For anyone having this issue ( @austinlarue ), you need to change the line of code in firebase.ios.js that matches
firebase._addObserver(kFIRInstanceIDTokenRefreshNotification, firebase._onTokenRefreshNotification); to
firebase._addObserver("com.firebase.iid.notif.refresh-token", firebase._onTokenRefreshNotification);

for reference, this line was #170 in my firebase.ios.js file. It might not be exact in yours but should be very close.

@EddyVerbruggen @mschahczinski I just tried this out and can confirm that it does fix the crashing issue.

I think it's also good to note for anyone that should stumble upon this issue... If the plugin is ever removed & re-added/updated for any reason, the change referenced above will need to be applied- at least until the npm package is updated with a long-term solution.

_UPDATE_ - This only applies to plugin versions <3.7.2 as it now contains the temporary fix.

Thanks guys for confirming. Will update npm very soon!

Update: done (3.7.2)

@EddyVerbruggen - I am also running in the same issue, app crashed if build in release mode with distribution profile ios, I m using 5.3.1 version of firebase plugin. Any pointers what could have wrong and a way to fix this.

@VimalKumarS I have no idea - you're not giving me much to work with. And please don't post on closed issues.

Was this page helpful?
0 / 5 - 0 ratings