getsentry / sentry-kotlin-multiplatform

Sentry SDK for Kotlin Multiplatform
MIT License
137 stars 19 forks source link

[Gradle Plugin] Add support for creating a dynamic library when using SPM and Cocoapods (not kotlin cocoapods) #108

Closed buenaflor closed 3 months ago

buenaflor commented 1 year ago

Description

Currently if someone wants to use SPM or (native, not kotlin) Cocoapods with our SDK it is only possible when making the shared libary static (dynamic is the default), e.g:

kotlin {
  listOf(
    iosX64(),
    iosArm64(),
    iosSimulatorArm64()
  ).forEach {
    it.binaries.framework {
        baseName = "shared"
        isStatic = true // Using SPM is only available when creating a static framework
    }
  }

Why the current solution is not ideal

Advantages of having it work as a dynamic library

Why it doesn't work

On iOS only the definitions for Sentry are added when compiling the Kotlin code and building the framework. The binary (the actual Sentry Cocoa library) isn't added until later when you build the iOS app. When building a dynamic framework, the Kotlin compile expects to be able to resolve everything and it ends up with this error: ld: symbol(s) not found for architecture x86_64 which basically tells us it cannot find the binary.

Solution

~Crashkios has solved this by basically telling the linker to treat the listed symbols as undefined. That means the linker will not try to find these symbols during the linking process and assumes these symbols will be provided by other means.~

The solution might not be viable since it can lead to problems if the app has app thinning enabled. See https://youtrack.jetbrains.com/issue/KT-58461

An alternative solution would be to properly link it to the framework

Essentially this means creating a KMP gradle plugin.

### Blocked by
- [ ] https://github.com/getsentry/sentry-kotlin-multiplatform/issues/191
kahest commented 1 year ago

blocked by https://github.com/getsentry/team-sdks/issues/29

ShmuelCammebys commented 1 month ago

So how do you actually do this?