dev.icerock.moko:crash-reporting-crashlytics-iosarm64

Fatal and Non-Fatal reporting to Crashlytics for Kotlin Multiplatform Mobile


Keywords
android, crash-reporting, ios, kotlin, kotlin-multiplatform, kotlin-native, moko
License
Apache-2.0

Documentation

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

allprojects {
    repositories {
        mavenCentral()
    }
}

project build.gradle

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

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

cocoaPods {
    podsProject = file("ios-app/Pods/Pods.xcodeproj")

    pod("MCRCDynamicProxy", onlyLink = true)
}

project Podfile

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

On iOS side add to AppDelegate:

import FirebaseCore
import MCRCStaticReporter

...

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]? = nil) -> Bool {
    FirebaseApp.configure()
    MokoFirebaseCrashlytics.setup()
    ...
}

Usage

CrashlyticsLogger

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

val logger = CrashlyticsLogger()

// setting user id in crashlytics 
logger.setUserId("User_1")

// setting custom key-value in crashlytics 
logger.setCustomValue("customValue", "customKey")

// log message in crashlytics
logger.log("Hello World")

// send non-fatal exception to crashlytics
try {
    "test".toInt()
} catch (e: NumberFormatException) {
    logger.recordException(e)
}

CrashReportingAntilog

val logger = CrashlyticsLogger() // CrashlyticsLogger for example, you can use any ExceptionLogger implementation

// initialize napier
Napier.base(antilog = CrashReportingAntilog(exceptionLogger = logger))

// All messages will be logged by exceptionLogger
Napier.d(message = "Hello World")
Napier.i(message = "This is random message", tag = "FYI")
Napier.w(message = "Something goes wrong", tag = "Alarm")
Napier.v(message = "just verbose", tag = "VERBOSE")

// throwable will be recorded by exceptionLogger
try {
    "test".toInt()
} catch (e: NumberFormatException) {
    Napier.e(message = "test is not a number", tag = "Non fatal", throwable = e)
}

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

Copyright 2020 IceRock MAG Inc.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.