Skip to content

Commit 8e814c5

Browse files
committed
Update docs and v0.8.1
1 parent 1986b74 commit 8e814c5

File tree

6 files changed

+62
-27
lines changed

6 files changed

+62
-27
lines changed

README.md

Lines changed: 47 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,12 @@ Thin library that provides symbolicated crash reports for Kotlin code on iOS. Su
44

55
To use crash reporting with general logging support, check out [Kermit](https://github.com/touchlab/Kermit/).
66

7+
If you're wondering *why* you need this library, please see [the problem](THE_PROBLEM.md).
8+
79
> ## Subscribe!
810
>
911
> 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.
15-
16-
<img src="kotlinabort.png" alt="Abort report" style="zoom:50%;" />
17-
18-
We want to get the caught exception and record that instead:
19-
20-
<img src="kotlinlines.png" alt="Abort report" style="zoom: 67%;" />
21-
22-
That's what this library is for.
12+
> [Sign up here](https://go.touchlab.co/newsletter-gh)!
2313
2414
## Crashlytics Usage
2515

@@ -33,19 +23,23 @@ val commonMain by sourceSets.getting {
3323
}
3424
```
3525

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:
3729

3830
```kotlin
3931
enableCrashlytics()
4032
```
4133

34+
You sould generally do this as part of app initialization, after you make the calls to start Crashlytics itself.
35+
4236
On iOS, you should also set the unhandled exception hook:
4337

4438
```kotlin
4539
setCrashlyticsUnhandledExceptionHook()
4640
```
4741

48-
Once initialized, you call methods on `CrashlyticsKotlin`
42+
Once initialized, you call methods on `CrashlyticsKotlin`, from common code or platform-specific code.
4943

5044
```kotlin
5145
CrashlyticsKotlin.logMessage("Some message")
@@ -75,14 +69,18 @@ Undefined symbols for architecture x86_64:
7569
ld: symbol(s) not found for architecture x86_64
7670
```
7771

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.
7973

8074
```kotlin
8175
plugins {
8276
id("co.touchlab.crashkios.crashlyticslink") version "x.y.z"
8377
}
8478
```
8579

80+
### Crashlytics Sample
81+
82+
See [samples/sample-crashlytics](samples/sample-crashlytics).
83+
8684
## Bugsnag Usage
8785

8886
Add the dependency.
@@ -95,7 +93,19 @@ val commonMain by sourceSets.getting {
9593
}
9694
```
9795

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.
99109

100110
The detailed calls you need to make are the following:
101111

@@ -105,6 +115,8 @@ In the iOS init, before starting Bugsnag, you need to call `configureBugsnag` wi
105115
let config = BugsnagConfiguration.loadConfig()
106116
```
107117

118+
#### Option 1: Manual Calls
119+
108120
Call `configureBugsnag` with that config. This *must* be called before starting Bugsnag.
109121

110122
```swift
@@ -123,20 +135,26 @@ Then set the default exception handler hook
123135
BugsnagConfigKt.setBugsnagUnhandledExceptionHook()
124136
```
125137

126-
Alternatively, call the helper function
138+
If you haven't done so, call:
127139

128140
```swift
129-
BugsnagConfigKt.startBugsnag(config: config)
141+
BugsnagConfigKt.enableBugsnag()
130142
```
131143

132-
That function calls `configureBugsnag`, `Bugsnag.start`, and `setBugsnagUnhandledExceptionHook`.
133144

134-
For both Android and iOS, you must call the following:
135145

136-
```kotlin
137-
enableBugsnag()
146+
#### Option 2: Helper Calls
147+
148+
You can call a single function that performs the 4 steps above.
149+
150+
```swift
151+
BugsnagConfigKt.startBugsnag(config: config)
138152
```
139153

154+
That function calls `configureBugsnag`, `Bugsnag.start`, `setBugsnagUnhandledExceptionHook`, and `enableBugsnag()`.
155+
156+
### Using the Library
157+
140158
Once initialized, you call methods on `BugsnagKotlin`
141159

142160
```kotlin
@@ -148,7 +166,7 @@ BugsnagKotlin.setCustomValue("someKey", "someValue")
148166

149167
### Testing
150168

151-
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.
152170

153171
### Linking
154172

@@ -168,14 +186,18 @@ Undefined symbols for architecture x86_64:
168186
ld: symbol(s) not found for architecture x86_64
169187
```
170188

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.
172190

173191
```kotlin
174192
plugins {
175193
id("co.touchlab.crashkios.bugsnaglink") version "x.y.z"
176194
}
177195
```
178196

197+
### Bugsnag Sample
198+
199+
See [samples/sample-bugsnag](samples/sample-bugsnag).
200+
179201
## NSExceptionKt
180202

181203
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.

THE_PROBLEM.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
## The Problem
2+
3+
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.
4+
5+
<img src="kotlinabort.png" alt="Abort report" style="zoom:50%;" />
6+
7+
We want to get the caught exception and record that instead:
8+
9+
<img src="kotlinlines.png" alt="Abort report" style="zoom: 67%;" />
10+
11+
That's what this library is for.

bugsnag/src/darwinMain/kotlin/co/touchlab/crashkios/bugsnag/BugsnagConfig.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ public fun startBugsnag(config: BugsnagConfiguration){
99
configureBugsnag(config)
1010
Bugsnag.startWithConfiguration(config)
1111
setBugsnagUnhandledExceptionHook()
12+
enableBugsnag()
1213
}
1314

1415
/**

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ kotlin.code.style=official
66
SONATYPE_HOST=DEFAULT
77
RELEASE_SIGNING_ENABLED=true
88
GROUP=co.touchlab.crashkios
9-
VERSION_NAME=0.8.0
9+
VERSION_NAME=0.8.1
1010
NSEXCEPTION_KT_VERSION=0.1.1
1111
KOTLIN_VERSION=1.7.20
1212
BUGSNAG_ANDROID_VERSION=5.28.1

samples/sample-bugsnag/app/src/main/java/co/touchlab/crashkiossamplecrashlog/MainActivity.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import com.bugsnag.android.Bugsnag
2020
class MainActivity : AppCompatActivity() {
2121
override fun onCreate(savedInstanceState: Bundle?) {
2222
super.onCreate(savedInstanceState)
23-
Bugsnag.start(this)
23+
2424
val binding = ActivityMainBinding.inflate(layoutInflater)
2525
setContentView(binding.root)
2626

samples/sample-bugsnag/app/src/main/java/co/touchlab/crashkiossamplecrashlog/SampleApp.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ class SampleApp : Application() {
1818
override fun onCreate() {
1919
super.onCreate()
2020

21+
Bugsnag.start(this)
2122
enableBugsnag()
2223
}
2324
}

0 commit comments

Comments
 (0)