You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+47-25Lines changed: 47 additions & 25 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,22 +4,12 @@ Thin library that provides symbolicated crash reports for Kotlin code on iOS. Su
4
4
5
5
To use crash reporting with general logging support, check out [Kermit](https://github.com/touchlab/Kermit/).
6
6
7
+
If you're wondering *why* you need this library, please see [the problem](THE_PROBLEM.md).
8
+
7
9
> ## Subscribe!
8
10
>
9
11
> We build solutions that get teams started smoothly with Kotlin Multiplatform Mobile and ensure their success in production. Join our community to learn how your peers are adopting KMM.
10
-
[Sign up here](https://go.touchlab.co/newsletter-gh)!
11
-
12
-
## The Problem
13
-
14
-
Crash reporter clients on iOS take the stack of active threads at the moment of crash. Kotlin on iOS, like Kotlin on the JVM, bubbles exceptions up until they are caught or reach the top of the call stack, at which point an unhandled exception hook is called. Because this differs from how iOS works, the crash report shows the point at which we call into Kotlin from Swift/Objc.
> [Sign up here](https://go.touchlab.co/newsletter-gh)!
23
13
24
14
## Crashlytics Usage
25
15
@@ -33,19 +23,23 @@ val commonMain by sourceSets.getting {
33
23
}
34
24
```
35
25
36
-
For both Android and iOS, you must call the following:
26
+
The library by default has noop implementations of the crash logging calls. This is because in test situations you generally don't want to interact with the crash logging. On iOS specifically, this will allow you to run tests without needing to link against the Crashlytics runtime library.
27
+
28
+
As a result, in the live app you need to initialize CrashKiOS. For both Android and iOS, you must call the following:
37
29
38
30
```kotlin
39
31
enableCrashlytics()
40
32
```
41
33
34
+
You sould generally do this as part of app initialization, after you make the calls to start Crashlytics itself.
35
+
42
36
On iOS, you should also set the unhandled exception hook:
43
37
44
38
```kotlin
45
39
setCrashlyticsUnhandledExceptionHook()
46
40
```
47
41
48
-
Once initialized, you call methods on `CrashlyticsKotlin`
42
+
Once initialized, you call methods on `CrashlyticsKotlin`, from common code or platform-specific code.
49
43
50
44
```kotlin
51
45
CrashlyticsKotlin.logMessage("Some message")
@@ -75,14 +69,18 @@ Undefined symbols for architecture x86_64:
75
69
ld: symbol(s) not found for architecture x86_64
76
70
```
77
71
78
-
To resolve this, you should tell the linker that Crashlytics will be added later. To do that, add a Gradle plugin that will configure your linker settings.
72
+
To resolve this, you should tell the linker that Crashlytics will be added later. You can do that directly, or you can use our Gradle plugin. It will find all Xcode Frameworks being built by Kotlin and add the necessary linker arguments.
79
73
80
74
```kotlin
81
75
plugins {
82
76
id("co.touchlab.crashkios.crashlyticslink") version "x.y.z"
83
77
}
84
78
```
85
79
80
+
### Crashlytics Sample
81
+
82
+
See [samples/sample-crashlytics](samples/sample-crashlytics).
83
+
86
84
## Bugsnag Usage
87
85
88
86
Add the dependency.
@@ -95,7 +93,19 @@ val commonMain by sourceSets.getting {
95
93
}
96
94
```
97
95
98
-
Bugsnag is somewhat more complex than Crashlytics. On startup, on iOS only, the library needs to suppress an extra error report from being sent. That requires some extra calls on iOS, or you can use a helper function that will handle the calls.
96
+
The library by default has noop implementations of the crash logging calls. This is because in test situations you generally don't want to interact with the crash logging. On iOS specifically, this will allow you to run tests without needing to link against the Bugsnag runtime library.
97
+
98
+
As a result, in the live app you need to initialize CrashKiOS. For both Android and iOS, you must call the following:
99
+
100
+
```kotlin
101
+
enableBugsnag()
102
+
```
103
+
104
+
You sould generally do this as part of app initialization, after you make the calls to start Bugsnag itself.
105
+
106
+
### iOS Only
107
+
108
+
Bugsnag is somewhat more complex than Crashlytics on iOS. On startup, the library needs to suppress an extra error report from being sent. That requires some extra calls, or you can use a helper function that will handle everything.
99
109
100
110
The detailed calls you need to make are the following:
101
111
@@ -105,6 +115,8 @@ In the iOS init, before starting Bugsnag, you need to call `configureBugsnag` wi
105
115
let config = BugsnagConfiguration.loadConfig()
106
116
```
107
117
118
+
#### Option 1: Manual Calls
119
+
108
120
Call `configureBugsnag` with that config. This *must* be called before starting Bugsnag.
109
121
110
122
```swift
@@ -123,20 +135,26 @@ Then set the default exception handler hook
You test code should not call `enableBugsnag()`. Before calling `enableBugsnag()`, calls to `BugsnagKotlin` are all no-ops. Also, on iOS, avoiding `enableBugsnag()` means you don't need to worry about Bugsnag linker issues.
169
+
Your test code should not call `enableBugsnag()`. Before calling `enableBugsnag()`, calls to `BugsnagKotlin` are all no-ops. Also, on iOS, avoiding `enableBugsnag()` means you don't need to worry about Bugsnag linker issues.
152
170
153
171
### Linking
154
172
@@ -168,14 +186,18 @@ Undefined symbols for architecture x86_64:
168
186
ld: symbol(s) not found for architecture x86_64
169
187
```
170
188
171
-
To resolve this, you should tell the linker that Bugsnag will be added later. To do that, add a Gradle plugin that will configure your linker settings.
189
+
To resolve this, you should tell the linker that Bugsnag will be added later. You can do that directly, or you can use our Gradle plugin. It will find all Xcode Frameworks being built by Kotlin and add the necessary linker arguments.
172
190
173
191
```kotlin
174
192
plugins {
175
193
id("co.touchlab.crashkios.bugsnaglink") version "x.y.z"
176
194
}
177
195
```
178
196
197
+
### Bugsnag Sample
198
+
199
+
See [samples/sample-bugsnag](samples/sample-bugsnag).
200
+
179
201
## NSExceptionKt
180
202
181
203
CrashKiOS and Kermit previously created 2 reports on a crash because none of the crash reporting clients had an obvious way to do one. [Rick Clephas](https://github.com/rickclephas) has done some excellent work figuring that out with [NSExceptionKt](https://github.com/rickclephas/NSExceptionKt). CrashKiOS now uses part of that library as a base and we've merged the cinterop from Kermit and NSExeptionKt to handle crashes as well as breadcrumb values and log statements.
Crash reporter clients on iOS take the stack of active threads at the moment of crash. Kotlin on iOS, like Kotlin on the JVM, bubbles exceptions up until they are caught or reach the top of the call stack, at which point an unhandled exception hook is called. Because this differs from how iOS works, the crash report shows the point at which we call into Kotlin from Swift/Objc.
0 commit comments