touchlab / Kermit

Kermit by Touchlab is a Kotlin Multiplatform centralized logging utility.
https://kermit.touchlab.co
Apache License 2.0
731 stars 41 forks source link

Kermit Crashlytics or Bugsnag #179

Closed puelocesar closed 3 years ago

puelocesar commented 3 years ago

I'm trying to follow the instructions on https://github.com/touchlab/Kermit/pull/177 for integrating Kermit Crashlytics, but my builds now always fail with this error message:


Showing Recent Messages
> Task :shared:linkDebugFrameworkIos

e: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ld invocation reported errors

The /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ld command returned non-zero exit code: 1.

output:

Undefined symbols for architecture arm64:

  "_OBJC_CLASS_$_FIRStackFrame", referenced from:

      objc-class-ref in result.o

  "_OBJC_CLASS_$_FIRExceptionModel", referenced from:

      objc-class-ref in result.o

  "_OBJC_CLASS_$_FIRCrashlytics", referenced from:

      objc-class-ref in result.o

ld: symbol(s) not found for architecture arm64

> Task :shared:linkDebugFrameworkIos FAILED

Is there anything else I'm missing? I'm using Kermit version "1.0.0-rc4"

mrf7 commented 3 years ago

Are you building your shared module as a dynamic framework? Something along the lines of

targets.withType<KotlinNativeTarget> {
        binaries.withType<Framework> {
            isStatic = false
           ...
        }
    }
kpgalligan commented 3 years ago

To follow up on that, the issue is that including Firebase in a dynamic library framework is problematic. This is less of a Kotlin thing than an Xcode framework thing.

https://github.com/firebase/firebase-ios-sdk/blob/master/docs/firebase_in_libraries.md

For static frameworks, we're providing a stub binary you can link against so the linker is happy for testing builds. For dynamic frameworks, the only real solution would be to pull in firebase itself, which we'd rather avoid.

I'm still thinking through this, but for now, using Kermit's Crashlytics support requires using static frameworks. To use dynamic, you'd need to implement a Crashlytics logger from Objc/Swift and pass it in. Not ideal, of course, but it's not too difficult. Hopefully we'll have something more user friendly soon.

puelocesar commented 3 years ago

Ok, it makes sense, but I'm still getting the same errors after changing my Firebase installation to be static. And there's something I still don't get, in Xcode, KMM step runs before linking with Pods, so how can Kotlin know where are the Pod libraries?

Here's how the iOS app is configured in my Gradle:

val iosTarget: (String, KotlinNativeTarget.() -> Unit) -> KotlinNativeTarget = when {
        System.getenv("SDK_NAME")?.startsWith("iphoneos") == true -> ::iosArm64
        System.getenv("NATIVE_ARCH")?.startsWith("arm") == true -> ::iosSimulatorArm64
        else -> ::iosX64
    }

    iosTarget("ios") {
        binaries {
            framework {
                baseName = "shared"
            }
        }
    }
kpgalligan commented 3 years ago

The Kotlin framework needs to be static.

iosTarget("ios") {
        binaries {
            framework {
                baseName = "shared"
                isStatic = true
            }
        }
    }
puelocesar commented 3 years ago

That did the trick, thanks for all the help