Integrating Crashlytics to library project

前端 未结 3 773
滥情空心
滥情空心 2021-02-18 18:24

I have a library project (a custom view library project) which doesn\'t have any Activities/services. I want to integrate Crashlytics SDK to my library. When I try to add it via

3条回答
  •  南方客
    南方客 (楼主)
    2021-02-18 18:53

    It can be done, with the help of the parent app that consumes the module.

    • Set up Firebase on the parent using the normal steps.
    • Add this to the build.gradle of the library module.
      implementation 'com.google.firebase:firebase-core:16.0.1'
      implementation 'com.crashlytics.sdk.android:crashlytics:2.9.9'
    
    • Create a class in the library module with this static variable. public static Crashlytics crash;
    • In the parents Application class, assign Crashlytics.getInstance(); to that variable.
    • The library module can call crash.core.logException(e); anywhere in the library and sent off to the Firebase console - but include a null check in case eg. library test methods are being called without a parent app.
    • Other unhandled exceptions eg throw new RuntimeException("test"); in the library should also show up in the console.

提交回复
热议问题