-
-
Notifications
You must be signed in to change notification settings - Fork 19
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
Test Apple targets don't find Sentry framework when using SPM #176
Comments
Hi, I'm not 100% how to tackle this since SPM support on KMP is generally not well documented / supported currently but it is on the roadmap: https://youtrack.jetbrains.com/issue/KT-64571 I'll take a look regardless |
Hi @buenaflor, thanks for taking a look. My title is a little bit misleading. We besically generate a regular xcframework and use it on iOS/watchOS in combination with the Sentry SPM library. |
Hey @buenaflor ! Were you able to already take a look at this issue? It would be great if it was documented https://docs.sentry.io/platforms/kotlin-multiplatform/#swift-package-manager-spm that if you're using that option it's no longer possible to run tests. |
@thomasflad were you able to find a workaround or solution for the issue, I am getting a similar issue on my project |
@msasikanth No, not yet. Since we already have a working solution by using the native libraries on each platform separately we've investigated not further and blocking the integration of the KMP version until there is a fix from Sentry |
The main thing we're trying to solve here is to get proper stack traces in sentry for iOS crashes. Am I correct in the assumption that this is not possible without sentry kmp? Or is there a way to set the stack trace addresses by implementing a callback from swift and keep using the native sdks? |
Sorry no update here yet.
If you only care about iOS crashes then you can also use https://github.com/rickclephas/NSExceptionKt which also works well. But then you'll still have the same problems where you can't use SPM in combination with tests
Unfortunately not yet. getsentry/sentry-cocoa#1999 |
In addition this is not a Sentry specific problem but I assume a problem with SPM dependency usage in KMP in general (at least specific to libraries that have ingested other cocoa dependencies) |
Just a hunch but I imagine it is connected with this issue: #108 (linker stuff) |
And would it be possible to do this manually until we have official sentry support?
If yes, could you give a hint how? @rickclephas is deprecating the sentry integration and point to using this SDK. We would really benefit from proper stacktraces at this point 🙏 |
I would like to mention that tricking the linker like that results in issues when you distribute your app with app thinning enabled. Besides that, last I heard, the CrashKiOS approach hasn't been working for tests in recent Kotlin versions either.
Yeah, like @buenaflor already mentioned, NSExceptionKt currently suffers from the same issue. I have been working on a new API that will decouple the implementations from the Kotlin code. |
Hm and what about making the sentry iOS stuff public so that we don't need reflection? |
Yeah correct. That is more or less how the new API for NSExceptionKt works. I created getsentry/sentry-cocoa#1999 a while ago to request some public APIs. |
That linked proposal makes very much sense to me. |
Turns out someone raised this in the past too 😂 |
The cocoa team prio'ed this as p4 and their backlog is pretty full so tbh not sure if I can give more hope here that it will be implemented anytime soon. @thomasflad @PaulWoitaschek here's a workaround for working tests although a bit annoying
Here the short code snippet for listOf(
iosX64(),
iosArm64(),
iosSimulatorArm64(),
).forEach {
it.binaries.framework {
baseName = "shared"
isStatic = true
}
it.compilations.all {
if (compilationName == "test" && target.platformType == KotlinPlatformType.native) {
compilerOptions.configure {
freeCompilerArgs.add("-linker-options")
freeCompilerArgs.add("-F/Users/giancarlobuenaflor/Downloads/Carthage/Build/Sentry.xcframework/ios-arm64_x86_64-simulator/")
}
}
}
} Now it should run You can prolly make the config a bit more cleaner, optimized but that's the gist of it lmk if that works |
Hi @buenaflor, Thanks for the workaround. Unfortunately, this is not a satisfactory solution, as we no longer notice when the library is updated. I think it would be a good idea to mention this issue in the README because you can't use the library like that in an enterprise context. |
Got it, yea, will definitely add it to our docs. If that doesn't work in your use case we'd prolly have to wait until the kotlin folks deliver a proper swiftpm solution similar to their cocoapods plugin. The other option would be to create a gradle plugin and add this workaround automatically |
I added the docs, I'll close this issue for now but feel free to reopen for any more questions |
A colleague shared this, a template for publishing libraries to SPM and CocoaPods: https://touchlab.co/kmmbridge-quick-start
|
@ataulm unfortunately this doesn't solve our problem, they're actually quite unrelated We have few solutions to this problem and are currently discussing them |
Just wanted to give a quick update that we are working on a gradle plugin that helps solve this issue |
Hello 👋 Do you have an update on the gradle plugin? I've just run into this issue while upgrading. Has anything changed in more recent versions? We were integrating via SPM fine on |
@abrown252 we're on it, it's working in a local build but still need to smoothen things out. Meanwhile you can try this out https://docs.sentry.io/platforms/kotlin-multiplatform/troubleshooting/#tests-not-working
The reason it changed is because we upgraded our kotlin version to Now that it's dynamic it needs linker configuration which our gradle plugin should help automate. |
@abrown252 we've released a pre-release of the plugin: https://github.com/getsentry/sentry-kotlin-multiplatform/releases/tag/0.8.0-beta.1 you can try it out like so: plugins {
// version is synced with library version
id("io.sentry.kotlin.multiplatform.gradle") version "0.8.0-beta.1"
}
sentryKmp {
// configure it if needed
} it's still a preview so we also don't have extensive documentation yet. Feel free to ask questions if something doesn't work! |
Platform
Apple, Android
Installed
Swift Package Manager
Version
0.4.0
Steps to Reproduce
commonMain
commenTest
linkDebugTestIosSimulatorArm64
Gradle task or run test on iOS simulator targetSee fork from my co-worker: PaulWoitaschek@4e856fc
Expected Result
Test also runs on Apple targets as expected
Actual Result
Gradle task
linkDebugTestIosSimulatorArm64
fails with error message:ld: framework 'Sentry' not found
The text was updated successfully, but these errors were encountered: