Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
1 task done
Tracked by #195
buenaflor opened this issue Jul 20, 2023 · 1 comment · Fixed by #230
Closed
1 task done
Tracked by #195

Comments

@buenaflor
Copy link
Contributor

buenaflor commented Jul 20, 2023

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

  • The sure way to get dynamic framework to work is by using the kotlin cocoapods plugin to pull in the sentry-cocoa dependency, however that is inefficient as it runs through c-interop which also creates extra compile time and overhead in the final binary (also probably a lot of dead code)

Advantages of having it work as a dynamic library

  • SwiftUI previews don't work with static libraries. There might be some workaround but that adds extra layers of complexity for the user.

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

  1. Platform: KMP
@kahest
Copy link
Member

kahest commented Oct 24, 2023

blocked by getsentry/team-sdks#29

@buenaflor buenaflor changed the title Add support for creating a dynamic library when using SPM [Gradle Plugin] Add support for creating a dynamic library when using SPM Mar 6, 2024
@buenaflor buenaflor changed the title [Gradle Plugin] Add support for creating a dynamic library when using SPM [Gradle Plugin] Add support for creating a dynamic library when using SPM and Cocoapods (not kotlin cocoapods) Mar 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

2 participants