Bradleycorn
11/03/2025, 3:32 PMinterface CommonErrorPlugin {
fun logMessage(message: String)
fun recordStateValue(key: String, value: Any)
fun setUserId(userId: String?)
}
expect interface ErrorPlugin: CommonErrorPlugin
In my iOS source set, I provide an actual implementation of the ErrorPlugin interface:
actual interface ErrorPlugin: CommonErrorPlugin {
fun logError(error: NSError)
}
This is crashing on iOS, and I'm not sure why?
More info in the thread ...Bradleycorn
11/03/2025, 3:32 PMErrorPlugin class FirebaseErrorPlugin: ErrorPlugin {
private let crashlytics = Crashlytics.crashlytics()
func logError(error: any Error) {
crashlytics.record(error: error, userInfo: [:])
}
func recordStateValue(key: String, value: Any) {
crashlytics.setCustomValue(value, forKey: key)
}
func logMessage(message: String) {
crashlytics.log(message)
}
func setUserId(userId: String?) {
crashlytics.setUserID(userId)
}
}
I pass an instance of this class to a Kotlin object, which calls it's methods.
For example, when a user logs in, it'll call the setUserId() method with the user's userid.
In iOS, when any of these methods are called, my app crashes. It doesn't ever even get to the swift code. The crash happens on the actual plugin definition line in the ios source set: actual interface ErrorPlugin: CommonErrorPlugin {
(see attached screen shot).
the other thing is, I have have exception handling in place, both try/catch blocks in the kotlin code, as well as a do/catch in the swift code, and neither of them get called.
I'm not sure what's going on here?Bradleycorn
11/03/2025, 6:20 PMCommonErrorPlugin interface, and just put it's methods in my (expected) ErrorPlugin interface:
expect interface ErrorPlugin {
fun logMessage(message: String)
fun recordStateValue(key: String, value: Any)
fun setUserId(userId: String?)
}
then, include the methods again when I build the actual implementations.
So, the ios implementation looks like:
actual interface ErrorPlugin {
actual fun logMessage(message: String)
actual fun recordStateValue(key: String, value: Any)
actual fun setUserId(userId: String?)
// ios specific interface method
fun logError(error: NSError)
}
android (and other platforms) get a similar actual definition.
It's a bit less DRY, as I have to repeat the "common" methods in the actual implementation on every platform ... but it works.russhwolf
11/03/2025, 6:37 PMrusshwolf
11/03/2025, 6:37 PMBradleycorn
11/03/2025, 6:43 PM