touchlab / CrashKiOS

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

Kotlin 1.8.0 compile error #48

Open brendanw opened 1 year ago

brendanw commented 1 year ago

After updating a project to kotlin 1.8.0, I started seeing the below error

Showing Recent Messages
Undefined symbols for architecture arm64:

  "_OBJC_CLASS_$_Bugsnag", referenced from:
      objc-class-ref in libco.touchlab.crashkios:bugsnag-cache.a(result.o)
      objc-class-ref in libco.touchlab:kermit-bugsnag-cache.a(result.o)
  "_OBJC_CLASS_$_BugsnagError", referenced from:
      objc-class-ref in libco.touchlab.crashkios:bugsnag-cache.a(result.o)
  "_OBJC_CLASS_$_BugsnagFeatureFlag", referenced from:
      objc-class-ref in libco.touchlab.crashkios:bugsnag-cache.a(result.o)
  "_OBJC_CLASS_$_BugsnagStackframe", referenced from:
      objc-class-ref in libco.touchlab.crashkios:bugsnag-cache.a(result.o)

The project does not directly depend on crashkios, just has a dependency on kermit:

            implementation("co.touchlab:kermit:1.2.2")
            implementation("co.touchlab:kermit-bugsnag:1.2.2")
russhwolf commented 1 year ago

Are you using cocoapods? Kotlin 1.8 changes the cocoapods plugin to link dynamically instead of statically by default, and this looks like a linking error. If that's the issue, the fix is to do

cocoapods {
  framework {
    isStatic = true
  }
}

If that's not the issue, it would help to know more about your project.

kpgalligan commented 1 year ago

Kermit bugsnag depends on crashkios for cinterop. We still need more doc updates, but here's the linker error you're getting:

https://github.com/touchlab/Kermit/blob/main/kermit-bugsnag/README.md#testing

You'll need to either make the framework static as Russell suggests, or tell the linker to ignore those missing symbols. If you're testing, you'll need to disable the build cache:

kotlin.native.cacheKind.iosX64=none
kotlin.native.cacheKind.iosSimulatorArm64=none
brendanw commented 1 year ago

Thanks Russ and Kevin!

Yes, I am using cocoapods.

Switching back to static linking resolves the issue.

I tried following the instructions for using co.touchlab.crashkios.bugsnaglink but was unable to successfully build. Spent some time experimenting toggling various gradle/kotlin flags in gradle.properties to no avail.

ponvig commented 1 year ago

Have similar issues trying to add the library for crashlytics to my KMM project. The gradle plugin suggested in https://github.com/touchlab/CrashKiOS#linking did not resolve the problem. (Not using cocoapods) Any chance you could validate and update the documentation using a fresh KMM 1.8.0 project?

amirplaza commented 1 year ago

@ponvig It seems the plugin adding compiler parameters doesn't work properly on Kotlin 1.8.10. As a workaround I added the following line to "iosArm64().binaries.framework {" piece of code.

freeCompilerArgs += listOf("-linker-options", "-U _FIRCLSExceptionRecordNSException -U _OBJC_CLASS_\$_FIRStackFrame -U _OBJC_CLASS_\$_FIRExceptionModel -U _OBJC_CLASS_\$_FIRCrashlytics")

Note: instead of using iosArm64(), you will probably iterate over all of the supported native targets.

I suppose something similar happens with the Bugsnag plugin.

kirillzh commented 10 months ago

Was hoping to enable K/N caching as well but am running into similar problem... Using Kotlin 1.9.0, Compose 1.5.0 (supports K/N caching finally), static library linking, not using cocoapods:

16:44:51 Please try to disable compiler caches and rerun the build. To disable compiler caches, add the following line to the gradle.properties file in the project's root directory:
16:44:51     
16:44:51     kotlin.native.cacheKind.iosX64=none
16:44:51     
16:44:51 Also, consider filing an issue with full Gradle log here: https://kotl.in/issue
16:44:51 The /Applications/Xcode/14.2.0/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ld command returned non-zero exit code: 1.
16:44:51 output:
16:44:51 Undefined symbols for architecture x86_64:
16:44:51   "_OBJC_CLASS_$_Bugsnag", referenced from:
16:44:51       objc-class-ref in libco.touchlab.crashkios:bugsnag-cache.a(result.o)
16:44:51   "_OBJC_CLASS_$_BugsnagError", referenced from:
16:44:51       objc-class-ref in libco.touchlab.crashkios:bugsnag-cache.a(result.o)
16:44:51   "_OBJC_CLASS_$_BugsnagFeatureFlag", referenced from:
16:44:51       objc-class-ref in libco.touchlab.crashkios:bugsnag-cache.a(result.o)
16:44:51   "_OBJC_CLASS_$_BugsnagStackframe", referenced from:
16:44:51       objc-class-ref in libco.touchlab.crashkios:bugsnag-cache.a(result.o)
16:44:51 ld: symbol(s) not found for architecture x86_64