touchlab / CrashKiOS

Crash reporting for Kotlin/Native iOS applications
https://crashkios.touchlab.co/
Apache License 2.0
282 stars 16 forks source link

Linker plugin not working with the new Kotlin/Native artifacts DSL #46

Open joharei opened 1 year ago

joharei commented 1 year ago

The linker plugin is not applying the compiler args when using the new DSL for Kotlin/Native artifacts: https://kotlinlang.org/docs/multiplatform-native-artifacts.html.

I can work around it by specifying the compiler args manually:

kotlinArtifacts {
    Native.XCFramework("sdk") {
        targets(iosX64, iosArm64, iosSimulatorArm64)
        setModules(
            project(":shared"),
            project(":lib")
        )

        // Add this:
        kotlinOptions {
            freeCompilerArgs = listOf(
                "-linker-options",
                "-U _FIRCLSExceptionRecordNSException " +
                        "-U _OBJC_CLASS_\$_FIRStackFrame " +
                        "-U _OBJC_CLASS_\$_FIRExceptionModel " +
                        "-U _OBJC_CLASS_\$_FIRCrashlytics"
            )
        }
    }
}
sigurdurrafn commented 1 year ago

I have the same issue.

I'm using the plugin id("co.touchlab.crashkios.crashlyticslink") version "0.8.1".

This was enough to fix the linker issue to build the app.

But the test linker task :linkDebugTestIosArm64 fails (also the x86 one). the error is the same as building the app without the plugin:

Undefined symbols for architecture arm64:
  "_OBJC_CLASS_$_FIRCrashlytics", referenced from:
      objc-class-ref in libco.touchlab.crashkios:crashlytics-cache.a(result.o)
  "_OBJC_CLASS_$_FIRExceptionModel", referenced from:
      objc-class-ref in libco.touchlab.crashkios:crashlytics-cache.a(result.o)
  "_OBJC_CLASS_$_FIRStackFrame", referenced from:
      objc-class-ref in libco.touchlab.crashkios:crashlytics-cache.a(result.o)
ld: symbol(s) not found for architecture arm64
npresseault commented 1 year ago

I've had the same issue. We're also using cocoapod gradle plugin.

I was able to workaround it by adding the linker options on the freeCompilerArgs of my Framework configuration

kotlin {
    cocoapods {
       framework {
            configureFramework()
        }
    }
}

fun org.jetbrains.kotlin.gradle.plugin.mpp.Framework.configureFramework() {
    isStatic = false
    freeCompilerArgs = listOf(
        "-linker-options",
        "-U _FIRCLSExceptionRecordNSException " +
            "-U _OBJC_CLASS_\$_FIRStackFrame " +
            "-U _OBJC_CLASS_\$_FIRExceptionModel " +
            "-U _OBJC_CLASS_\$_FIRCrashlytics"
    )