How to Integrate Crashlytics into an iOS Framework Target

Can I add Crashlytics to an iOS Library?

Looks like the answer is technically "YES", but it would be a bad idea to do so.

Mike Bonnell's comments in another post:

Comment 1:

Mike from Fabric here. If you're planning on distributing this
framework to third parties, do not include Fabric or Crashlytics in
it.

Comment 2:

Sure, our SDK only supports being initialized once. Being initialized in a framework and application would cause a conflict. You and the app developer would have different API keys and there is no way to ask the app developer to give permission to your SDK to share stack traces from their code with your framework. Including us in your framework will cause issues for your framework and anyone that uses it, so that's why I said don't include us! Totally understand that SDK developers would love to see this supported.

Crashlytics report from exception in framework

I'm going to go ahead and post this as an answer because it does appear to report crashes that happen in frameworks which was the primary point. It's only a partial answer because I was also talking about app extension. I have received reports from the keyboard extension but nothing from the iMessage extension so far.

Anyway, it does appear to work with frameworks. I took one of the frameworks we built and added these functions:

public static func doCrash() {
func1()
}

private static func func1() {
func2()
}

private static func func2() {
let _ = 10 / prepNum(5)
}

private static func prepNum(_ int:Int) -> Int {
return int - int
}

When the division by zero is hit the app crashed and, after I restarted it, I got the crash report with the following:

libswiftCore.dylib  
specialized _fatalErrorMessage(_:_:file:line:flags:) + 124
1 CommonKit _T012CommonKit9LocalFileC5func233_BC978A475DDB24483E4F12A335D91E70LLyyFZ + 136
2 CommonKit _T012CommonKit9LocalFileC5func133_BC978A475DDB24483E4F12A335D91E70LLyyFZ + 20
3 CommonKit _T012CommonKit9LocalFileC7doCrashyyFZ + 20
4 MyApp StickerViewController.swift line 369
StickerViewController.callFrameworkForCrash() -> ()

So it doesn't appear to be able to fully symbolicate the crash into the framework. But if we look at the results _T012CommonKit9LocalFileC7doCrashyyFZ we can pull out the name of the function that crashed CommonKit::LocalFile.doCrash().

I hope this helps out for someone in the future. I'll keep trying to get something from it in the iMessage extension.

Mike

Set up Firebase Crashlytics on IOS

To test this you can force a crash..

What you can do is...

  • Add a button on view and implement its touchupInside event.
  • in that method just write fatalError()
  • Run your app and click on that button.(You app will crash here so it will be close)
  • Now open app again(Do not run app. Just open it by taping on app icon)

So the crash report will be send to firebase and you can see the result on firebase dashboard with in 5 minutes(as per their doc.).

Also you need to set this flag in build setting of your project to generate dsym file for debug mode.

enter image description here

Also this has to be set in build phase

enter image description here



Related Topics



Leave a reply



Submit