sentry-kotlin-multiplatform
sentry-kotlin-multiplatform copied to clipboard
Lift the requirement on cocoapods
Problem Statement
The SDK relies on cocoapods that is coming to EOL. It would be nice if this SDK provided the batteries-included setup with no requirements on cocoapods nor SPM.
Solution Brainstorm
Get whatever you have in cocoapods and make a static library out of it then create cInterops and link the static library to the .klib artifact using staticLibraries property in .def file π
hey yeah that's something we might do in the future π
I assume dynamic libraries wont work with this approach
Yes, it has to be statically linked
I'm wondering though how often it's the case that someone uses neither spm nor cocoapods
+ defining header files is definitely a major increase in maintenance overhead for us and I'm not sure how well it plays together with new cocoa sdk features since they're using more and more swift
I'm fine with SPM dependency, just not cocoapods, please.
I'm fine with SPM dependency, just not cocoapods, please.
Cocoapods is not required to use the SDK. You can use either SPM or Cocoapods
I'm fine with SPM dependency, just not cocoapods, please.
Cocoapods is not required to use the SDK. You can use either SPM or Cocoapods
How exactly? The manual setup says this
Apple Installation Methods Swift Package Manager (SPM) Swift Package Manager (SPM) is a powerful tool for managing dependencies in Swift that allows developers to enjoy a more native integration experience with Xcode. If you already use SPM or prefer it over other package managers on Apple platforms, this guide will show you how to install the Kotlin Multiplatform SDK while using Swift Package Manager.
Install In order to install the Sentry Kotlin Multiplatform SDK, you need to use Cocoapods and Swift Package Manager simultaneously, which might seem unconventional at first, especially if you're accustomed to using SPM for all your dependencies. However, you can achieve a smooth integration by using the Kotlin Cocoapods plugin specifically for compiling and building the shared framework. You can then continue to manage all other dependencies with SPM as usual.
Follow the steps for our primary installation method Cocoapods to install the Sentry Kotlin Multiplatform SDK.
After you've consumed the shared framework in your application via Cocoapods, you can continue with SPM for other dependencies without disrupting your existing workflow.
I tried different combinations anyway, if I add the dependency with SPM it complains about duplicate symbols, if I don't it complains that it's missing, the plugin also didn't work (which I don't want to use anyway as it adds ~20 seconds build time to Android..)
@ivnsch the reason why we mention it here is because it's the easiest way to integrate SPM if you decide to do it manually
If you only add the Sentry Cocoa SDK via SPM to your project the Kotlin/Native compiler doesn't know anything about how to resolve the symbols we are using in the KMP SDK so you'd have to configure the linker.
However setting up the linker and linking to the correct framework manually is a hassle. See this comment
Since the Kotlin Cocoapods plugin downloads the framework and sets up the linker for you it is a much easier process.
And that's why we have the Sentry KMP plugin which main purpose is to set up the linker without cocoapods.
the plugin also didn't work
Could you describe the errors?
which I don't want to use anyway as it adds ~20 seconds build time to Android
That's something we can optimize (and should)
However given the confusion around this topic I might consider adding a section describing setting up the linker manually without cocoapods
@buenaflor please do! I'd be happy to test it.
@ivnsch sounds good, I'll whip something up
@buenaflor any updates? I've some time to integrate and test this π
I'm using my plug-in spmforKmp instead of Cocoapods for setting up Sentry KMP and it's working great
remotePackageVersion(
url = uri("https://github.com/getsentry/sentry-cocoa"),
version = libs.versions.sentryiOS.get(),
products = {
add("Sentry")
},
)
@frankois944 nice, thanks! I'm having trouble getting it to work however
listOf(
iosArm64(),
iosSimulatorArm64()
).forEach { iosTarget ->
iosTarget.binaries.framework {
baseName = "ComposeApp"
isStatic = true
export(project(":agents:composeApp"))
}
iosTarget.compilations {
val main by getting {
cinterops.create("nativeIosShared")
}
}
}
// toml: // sentry-ios = "8.56.0"
swiftPackageConfig {
create("nativeIosShared") {
dependency {
remotePackageVersion(
url = uri("https://github.com/getsentry/sentry-cocoa"),
version = libs.versions.sentry.ios.get(),
products = {
// add("Sentry", exportToKotlin = true) // doesn't work either
add("Sentry")
},
)
}
}
}
added SentryBridge.swift to the appearing composeApp/src/swift/nativeIosShared/ folder
Still can't import anything with Sentry in my code
Not sure what else I've to do or what's wrong?
Hello, Please create an issue on the project, itβs the best location :)
In case it helps anyone, I confirm that spmforKmp solved this problem for me!