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

Regular framework support (use without CocoaPods) #118

Closed
StefanOltmann opened this issue Aug 25, 2023 · 10 comments
Closed

Regular framework support (use without CocoaPods) #118

StefanOltmann opened this issue Aug 25, 2023 · 10 comments

Comments

@StefanOltmann
Copy link

Problem Statement

I don't like CocoaPods. They're complicated and not a great solution at all.

Solution Brainstorm

Could a Gradle script be utilized to facilitate the copying or updating of the XCFramework to its designated location?

Alternatively, a more streamlined approach could involve developing a completely Kotlin-based version of the SDK, thereby replacing the existing iteration with an XCFramework generated through Kotlin/Native.

@buenaflor
Copy link
Contributor

buenaflor commented Aug 25, 2023

Alternatively if that is an option for you, you can also use SPM to include the sentry-cocoa dependency:

https://docs.sentry.io/platforms/kotlin-multiplatform/install/swift-package-manager/?original_referrer=https%3A%2F%2Fwww.google.com%2F

The only caveat here currently is that you need to export the shared framework as static. Some context as to why and how to fix this in the future: #108

@StefanOltmann
Copy link
Author

I presently utilize the Sentry XCFramework, which is provided as a ZIP file on the releases page, and this setup serves me well. I have contemplated transitioning to the Multiplatform option to streamline my codebase, although I am reluctant to do so if it involves incorporating CocoaPods.

@buenaflor
Copy link
Contributor

buenaflor commented Aug 25, 2023

You don't necessarily need cocoapods. The only thing you need for the SDK to work (on apple platforms) is providing the sentry-cocoa SDK binary and cocoapods is one way to do that. I haven't checked on how a pre-built XCFramework needs to be linked in this case.

It might be as easy as linkerOpts("-framework", "MyFramework", "-F/path/to/framework/")

But I'll check that out and get back to you on how to configure it.

@buenaflor
Copy link
Contributor

buenaflor commented Aug 28, 2023

@StefanOltmann

You can configure it as follows:

Add the XCFramework to your project and add this to your KMP config:

    listOf(
        iosX64(),
        iosArm64(),
        iosSimulatorArm64()
    ).forEach {
        it.binaries.framework {
            baseName = "shared"
            when (it.name) {
                "iosSimulatorArm64" -> {
                    linkerOpts("-framework", "Sentry", "-F/path/to/framework/")
                }
                "iosArm64" -> {
                    linkerOpts("-framework", "Sentry", "-F/path/to/framework/")
                }
                "iosX64" -> {
                    linkerOpts("-framework", "Sentry", "-F/path/to/framework/")
                }
            }
        }
    }

Just make sure to reference the correct framework based on your target platform.
But please note that currently we officially support sentry-cocoa version 8.4.0. It might or might not work with other versions.

However, so far this configuration still leads to a problem where you cannot launch the iOS app through the KMP plugin in Android Studio but need to launch it directly from XCode. This still needs some investigation why.

@StefanOltmann
Copy link
Author

Thank you, I will try that.
I wonder why only the simulator needs that and not the other targets.

@buenaflor
Copy link
Contributor

buenaflor commented Aug 28, 2023

Sry, should've added the rest of the code. You will need to specify each target and the respective framework of course.

Nonetheless thank you for the issue, this should also be documented in our docs.

@msasikanth
Copy link

Hi, I have noticed an issue when migrating from cocoapods to regular framework. So flagging it here.

After removing cocoapods plugin from KMP, I have added Sentry cocoa dependency using SPM and the ran app from Xcode and everything worked correctly. But when I tried to run the iOS tests in the common module. I keep getting this error, not entirely sure how I can resolve this. Didn't had this issue when using pod dependency.

Undefined symbols for architecture arm64:
  "_OBJC_CLASS_$_PrivateSentrySDKOnly", referenced from:
      objc-class-ref in result.o
  "_OBJC_CLASS_$_SentryAttachment", referenced from:
      objc-class-ref in result.o
  "_OBJC_CLASS_$_SentryBreadcrumb", referenced from:
      objc-class-ref in result.o
  "_OBJC_CLASS_$_SentryDependencyContainer", referenced from:
      objc-class-ref in result.o
  "_OBJC_CLASS_$_SentryEnvelope", referenced from:
      objc-class-ref in result.o
  "_OBJC_CLASS_$_SentryEnvelopeHeader", referenced from:
      objc-class-ref in result.o
  "_OBJC_CLASS_$_SentryEnvelopeItem", referenced from:
      objc-class-ref in result.o
  "_OBJC_CLASS_$_SentryEvent", referenced from:
      objc-class-ref in result.o
  "_OBJC_CLASS_$_SentryException", referenced from:
      objc-class-ref in result.o
  "_OBJC_CLASS_$_SentryHttpStatusCodeRange", referenced from:
      objc-class-ref in result.o
  "_OBJC_CLASS_$_SentryId", referenced from:
      objc-class-ref in result.o
  "_OBJC_CLASS_$_SentryMechanism", referenced from:
      objc-class-ref in result.o
  "_OBJC_CLASS_$_SentryMessage", referenced from:
      objc-class-ref in result.o
  "_OBJC_CLASS_$_SentrySDK", referenced from:
      objc-class-ref in result.o
  "_OBJC_CLASS_$_SentryScope", referenced from:
      objc-class-ref in result.o
  "_OBJC_CLASS_$_SentryUser", referenced from:
      objc-class-ref in result.o
  "_OBJC_CLASS_$_SentryUserFeedback", referenced from:
      objc-class-ref in result.o
ld: symbol(s) not found for architecture arm64

@buenaflor
Copy link
Contributor

buenaflor commented Sep 1, 2023

@msasikanth

hi, please refer to our sentry doc on how to set it up.

Essentially you need to export your shared framework as static (for now) if you'd like to use SPM.

As for your error, read #108 if you like to understand why this is happening and our future plan on how to support this better

@msasikanth
Copy link

Got it. The framework is already static, I think I would have to mark those symbols as undefined like you mentioned in the issue. Thanks 👍🏾

@romtsn
Copy link
Member

romtsn commented Sep 27, 2023

Let's track this in #108 where we'll look for adding a gradle plugin that configures this automatically without a need for cocoapods (we could even just download the sentry-cocoa binaries from the gradle plugin or ship them together to avoid a need for any package manager like cocoapods/carthage)

@romtsn romtsn closed this as not planned Won't fix, can't repro, duplicate, stale Sep 27, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Archived in project
Development

No branches or pull requests

4 participants