项目作者: icerockdev

项目描述 :
Fatal and Non-Fatal reporting to Crashlytics for Kotlin Multiplatform Mobile
高级语言: Kotlin
项目地址: git://github.com/icerockdev/moko-crash-reporting.git
创建时间: 2020-10-01T08:07:37Z
项目社区:https://github.com/icerockdev/moko-crash-reporting

开源协议:Apache License 2.0

下载


moko-crash-reporting
GitHub license Download kotlin-version

Mobile Kotlin crash report

This is a Kotlin MultiPlatform library that provides reporting fatal and non-fatal exceptions from common code.

Table of Contents

Features

  • CrashlyticsLogger implementation of ExceptionLogger, for logging messages and non-fatals to FirebaseCrashlytics.
  • CrashReportingAntilog can be used for Napier logger to log messages and errors by ExceptionLogger

Requirements

  • Gradle version 6.8+
  • Android API 19+
  • iOS version 11.0+

Installation

root build.gradle

  1. allprojects {
  2. repositories {
  3. mavenCentral()
  4. }
  5. }

project build.gradle

  1. dependencies {
  2. commonMainImplementation("dev.icerock.moko:crash-reporting-crashlytics:0.4.0") // for CrashlyticsLogger
  3. commonMainImplementation("dev.icerock.moko:crash-reporting-napier:0.4.0") // for CrashReportingAntilog
  4. }

For CrashlyticsLogger need to add FirebaseCrashlytics cocoapod
With mobile-multiplatform-gradle-plugin cocoapods configuration simplest:
build.gradle.kts:

  1. cocoaPods {
  2. podsProject = file("ios-app/Pods/Pods.xcodeproj")
  3. pod("MCRCDynamicProxy", onlyLink = true)
  4. }

project Podfile

  1. pod 'MCRCDynamicProxy', :git => 'https://github.com/icerockdev/moko-crash-reporting.git', :tag => 'release/0.4.0'
  2. pod 'MCRCStaticReporter', :git => 'https://github.com/icerockdev/moko-crash-reporting.git', :tag => 'release/0.4.0'

On iOS side add to AppDelegate:

  1. import FirebaseCore
  2. import MCRCStaticReporter
  3. ...
  4. func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]? = nil) -> Bool {
  5. FirebaseApp.configure()
  6. MokoFirebaseCrashlytics.setup()
  7. ...
  8. }

Usage

CrashlyticsLogger

If you haven’t already, add Firebase to your project, you can see how to do it here

  1. val logger = CrashlyticsLogger()
  2. // setting user id in crashlytics
  3. logger.setUserId("User_1")
  4. // setting custom key-value in crashlytics
  5. logger.setCustomValue("customValue", "customKey")
  6. // log message in crashlytics
  7. logger.log("Hello World")
  8. // send non-fatal exception to crashlytics
  9. try {
  10. "test".toInt()
  11. } catch (e: NumberFormatException) {
  12. logger.recordException(e)
  13. }

CrashReportingAntilog

  1. val logger = CrashlyticsLogger() // CrashlyticsLogger for example, you can use any ExceptionLogger implementation
  2. // initialize napier
  3. Napier.base(antilog = CrashReportingAntilog(exceptionLogger = logger))
  4. // All messages will be logged by exceptionLogger
  5. Napier.d(message = "Hello World")
  6. Napier.i(message = "This is random message", tag = "FYI")
  7. Napier.w(message = "Something goes wrong", tag = "Alarm")
  8. Napier.v(message = "just verbose", tag = "VERBOSE")
  9. // throwable will be recorded by exceptionLogger
  10. try {
  11. "test".toInt()
  12. } catch (e: NumberFormatException) {
  13. Napier.e(message = "test is not a number", tag = "Non fatal", throwable = e)
  14. }

Samples

Please see more examples in the sample directory.

Set Up Locally

Contributing

All development (both new features and bug fixes) is performed in the develop branch. This way master always contains the sources of the most recently released version. Please send PRs with bug fixes to the develop branch. Documentation fixes in the markdown files are an exception to this rule. They are updated directly in master.

The develop branch is pushed to master on release.

For more details on contributing please see the contributing guide.

License

  1. Copyright 2020 IceRock MAG Inc.
  2. Licensed under the Apache License, Version 2.0 (the "License");
  3. you may not use this file except in compliance with the License.
  4. You may obtain a copy of the License at
  5. http://www.apache.org/licenses/LICENSE-2.0
  6. Unless required by applicable law or agreed to in writing, software
  7. distributed under the License is distributed on an "AS IS" BASIS,
  8. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  9. See the License for the specific language governing permissions and
  10. limitations under the License.