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

A problem occurred configuring project ':kmp'. > Sentry Cocoa Framework not found at /user/path/.../ #318

Open
franmontiel opened this issue Jan 30, 2025 · 26 comments
Assignees
Labels
Platform: KMP Type: Bug Something isn't working

Comments

@franmontiel
Copy link

Platform

Apple

Installed

None

Version

0.1.0

Steps to Reproduce

  1. Create a new KMP app project and use "Regular Framework" for distribution to Xcode.
  2. Add the Sentry KMP plugin.
  3. Sync gradle and the error will appear. The same one mentioned in this issue -> [Gradle Plugin] improve error message #303

Expected Result

Sentry is added to my KMP project and let me build it.

Actual Result

Cannot sync gradle, the following error appears:
A problem occurred configuring project ':shared'.

Sentry Cocoa Framework not found at /path/to/iosApp/build/SourcePackages/artifacts/sentry-cocoa/Sentry-Dynamic/Sentry-Dynamic.xcframework/ios-arm64 or /path/to/iosApp/build/SourcePackages/artifacts/sentry-cocoa/Sentry/Sentry.xcframework/ios-arm64

@franmontiel franmontiel added Platform: KMP Type: Bug Something isn't working labels Jan 30, 2025
@github-project-automation github-project-automation bot moved this to Needs Discussion in Mobile SDKs Jan 30, 2025
@buenaflor
Copy link
Contributor

hey, this is definitely a docs issue and an error message issue, you have to add the Sentry-Cocoa dependency via SPM first if you use a regular framework. we should mention it in the error message as well

@franmontiel
Copy link
Author

I added Sentry SPM dependency to the iosApp and the problem persists. I also tried with Sentry-Dynamic and the result is the same.

@franmontiel
Copy link
Author

Seems to only start working if I add the cocoapods plugin but according to this comment it shouldn't be needed

@buenaflor
Copy link
Contributor

buenaflor commented Jan 30, 2025

@franmontiel if you add the cocoapods plugin it will work because our gradle plugin detects this and installs the sentry-cocoa dependency via the cocoapods plugin.

can you show your kmp gradle config? in case you changed something

/path/to/iosApp/ doesnt seem right unless you purposefully changed the log

@franmontiel
Copy link
Author

franmontiel commented Jan 30, 2025

The /path/to/iosApp/ was just me modifying the path as it was irrelevant.

Here the gradle file as it is failing right now

import org.jetbrains.kotlin.gradle.dsl.JvmTarget

plugins {
    alias(libs.plugins.kotlinMultiplatform)
    alias(libs.plugins.androidLibrary)
    id("io.sentry.kotlin.multiplatform.gradle") version "0.10.0"
}

kotlin {
    androidTarget {
        compilations.all {
            compileTaskProvider.configure {
                compilerOptions {
                    jvmTarget.set(JvmTarget.JVM_1_8)
                }
            }
        }
    }
    
    listOf(
        iosX64(),
        iosArm64(),
        iosSimulatorArm64()
    ).forEach {
        it.binaries.framework {
            baseName = "shared"
            isStatic = false
        }
    }

    sourceSets {
        commonMain.dependencies {
            //put your multiplatform dependencies here
        }
        commonTest.dependencies {
            implementation(libs.kotlin.test)
        }
    }
}

android {
    namespace = "io.bridify.sentrytest"
    compileSdk = 35
    defaultConfig {
        minSdk = 24
    }
    compileOptions {
        sourceCompatibility = JavaVersion.VERSION_1_8
        targetCompatibility = JavaVersion.VERSION_1_8
    }
}

@buenaflor
Copy link
Contributor

buenaflor commented Jan 30, 2025

Thanks! I was able to reproduce it.

The issue is that in newer versions the sentry-cocoa artifacts changed the folder names

  • ios-arm64
  • ios-arm64_x86_64-maccatalyst
  • ios-arm64_x86_64-simulator

turned into

  • ios-arm64_arm64e
  • ios-arm64_arm64e_x86_64-maccatalyst
  • ios-arm64_x86_64-simulator

I will add a fix for this

@buenaflor
Copy link
Contributor

buenaflor commented Jan 30, 2025

If you want to try it out for now you can for example use the sentry-cocoa version8.37.0 which will still be compatible

@buenaflor buenaflor moved this from Needs Discussion to Todo in Mobile SDKs Jan 30, 2025
@buenaflor buenaflor self-assigned this Jan 30, 2025
@franmontiel
Copy link
Author

franmontiel commented Jan 30, 2025

With version 8.37.0 the same thing is happening.

For what I am understanding we required the Sentry library to be build in a specific folder location (that I believe it does not coincide with the XCode default build folder). Could that be the cause?

I tried moving my DerivedData folder to a different place and using frameworkPath option to direct to the exact folder were the .xcframework was, is this the expected setup?

@buenaflor
Copy link
Contributor

buenaflor commented Jan 30, 2025

I tested it locally on a new project with 8.37.0 which works and 8.38.0 which doesnt work.

by default the gradle plugin will use the xcodeproj to determine where the build folder is located via xcodebuild -project yourproject.xcodeproj -showBuildSettings which spits out a bunch of info including BUILD_DIR which points to the derived data path of your build and thats where we are looking for the framework that you installed with SPM

if for some reason that deviates you'll need to update the frameworkPath configuration to point to that - that's the main purpose of this option so in your case it is expected although I am not sure in your case why the framework is not in the build folder that we receive from the xcodebuild command

can you paste here the location where the framework is by default? (before you moved it)

@franmontiel
Copy link
Author

franmontiel commented Jan 30, 2025

This is were the error message says it is looking for the frameworks

/Users/fj/AndroidStudioProjects/SentryTest/iosApp/build/SourcePackages/artifacts/sentry-cocoa/Sentry-Dynamic/Sentry-Dynamic.xcframework/ios-arm64
/Users/fj/AndroidStudioProjects/SentryTest/iosApp/build/SourcePackages/artifacts/sentry-cocoa/Sentry/Sentry.xcframework/ios-arm64

No matter where I configure Derived data and build folders location that it will always show me those locations in the error. It could mean that the code that find the frameworks is faulty or for some reason the error message is using a different path.

This is for me the default derived data folder were I can find the frameworks:

/Users/fj/Library/Developer/Xcode/DerivedData/Bridify-ddpfikekigqzzgcnpfnacsmlfpln/SourcePackages/artifacts/sentry-cocoa

@franmontiel
Copy link
Author

I am also thinking, it is DerivedData folder reliable to depend on? Could it happen that the folder is deleted and we might end-up in a catch-22 situation where KMP project needs the framework files but those are not build because KMP part is failing?

@buenaflor
Copy link
Contributor

yeah that doesn't look right

can you execute xcodebuild -project yourproject.xcodeproj -showBuildSettings and post the BUILD_DIR

@buenaflor
Copy link
Contributor

buenaflor commented Jan 30, 2025

we might end-up in a catch-22 situation where KMP project needs the framework files

if you update or reload the SPM package dependencies that should restore the framework files without you needing to actually compile the project

in any case this is a best effort solution since there is no official support for a Kotlin SPM plugin right now. if you manually set up the SDK you would also have to do these steps -> find the framework location and set up linking manually

@franmontiel
Copy link
Author

can you execute xcodebuild -project yourproject.xcodeproj -showBuildSettings and post the BUILD_DIR

BUILD_DIR = /Users/fj/AndroidStudioProjects/SentryTest/iosApp/build

That's really weird, as if I check it from XCode it is inside DerivedData folder.

By the way, in my case, the SourcePackages is not in the build folder but in the DerivedData folder

@buenaflor
Copy link
Contributor

BUILD_DIR = /Users/fj/AndroidStudioProjects/SentryTest/iosApp/build

hmm looks like this is the issue, on my end BUILD_DIR points to the derived data path location. tbh I'm unsure why it points to the build folder of your kmp app

in the output are there any other fields that point to the derived data? we might be able to use those as a fallback

@franmontiel
Copy link
Author

franmontiel commented Jan 30, 2025

For what I see there is no value that points to the DerivedData folder.

For the moment to make it work without needing to change my project configuration to use Cocoapods I've done the following:

  • Manually added Sentry.xcframework (version 8.37.0 until the plugin is fixed) to the iOS project.
  • Added sentry dependencies and plugin in my KMP project (Version 0.9.0 or you will face this issue)
  • Configured Sentry in my KMP project build.gradle.kts file to point to the .xcframework file:
 sentryKmp {
    autoInstall {
        linker {
            frameworkPath.set(rootProject.file("iosApp/Frameworks/").absolutePath)
        }
    }
 }
  • Be sure that your KMP project is not a dynamic library, isStatic = true must be set

@buenaflor could you please let me know when the plugin is fixed so I can be able to use the latest version of the library? Thanks so much for your help

@buenaflor
Copy link
Contributor

buenaflor commented Jan 30, 2025

thanks for the info

I will look into a way to get the derived data path reliably and fix the folder name missmatch

that way you can use a higher cocoa version as well

Unlikely though that a fix will be out this week, most likely next monday

@buenaflor
Copy link
Contributor

@franmontiel do you mind sending me the output of xcodebuild -project yourproject.xcodeproj -showBuildSettings to [email protected] so I can take a closer look

@franmontiel
Copy link
Author

@franmontiel do you mind sending me the output of xcodebuild -project yourproject.xcodeproj -showBuildSettings to [email protected] so I can take a closer look

email sent.

@buenaflor
Copy link
Contributor

update: I'm working on the fix as we speak, I'll see to it that it's out soon

@ade
Copy link

ade commented Feb 5, 2025

Just a quick note here, sentry-kmp 0.10.0 is NOT compatible with sentry-cocoa 8.37.0 due to (atleast one) renamed api

You have to use sentry-kmp 0.9.0 with sentry-cocoa 8.36.0 for now.

@buenaflor
Copy link
Contributor

You have to use sentry-kmp 0.9.0 with sentry-cocoa 8.36.0 for now.

Thanks for the info, yes right now until I release the gradle plugin fix I recommend this combination

@buenaflor
Copy link
Contributor

@franmontiel just published 0.11.0, could you try out if it fixes the problem

@remarkjt
Copy link

@franmontiel just published 0.11.0, could you try out if it fixes the problem

Hi @buenaflor! Thank you for your work on this library.

I've tested out 0.11.0 and it doesn't fix the issue for me on iOS 😔 The app crashes when launching right after building (debug mode) with the following error:

dyld[xxxxx]: Library not loaded: @rpath/Sentry.framework/Sentry
  Referenced from: /Users/<username>/Library/Developer/Xcode/DerivedData/<AppName>-xxxxx/Build/Products/Debug-iphonesimulator/<AppName>.framework/<AppName>
  Reason: tried: '/Users/<username>/Library/Developer/Xcode/DerivedData/<AppName>-xxxxx/Build/Products/Debug-iphonesimulator/Sentry.framework/Sentry' (no such file), 
  '/Library/Developer/CoreSimulator/Profiles/Runtimes/iOS 15.4.simruntime/Contents/Resources/RuntimeRoot/usr/lib/swift/Sentry.framework/Sentry' (no such file),
  '/usr/lib/swift/Sentry.framework/Sentry' (no such file),
  '/Users/<username>/Library/Developer/CoreSimulator/Devices/<device-id>/data/Containers/Bundle/Application/<bundle-id>/AppNameApp.app/Frameworks/Sentry.framework/Sentry' (no such file)
  [Additional paths omitted for brevity]

@buenaflor
Copy link
Contributor

@remarkjt can you share your gradle config

@remarkjt
Copy link

remarkjt commented Feb 21, 2025

@remarkjt can you share your gradle config

Here's my build.gradle.kts with sensitive info replaced with placeholders and irrelevant lines removed.

plugins {
    kotlin("multiplatform")
    kotlin("plugin.serialization") version "1.9.22"
    kotlin("native.cocoapods")
    id("com.android.library")
    id("io.sentry.kotlin.multiplatform.gradle") version "0.11.0"
}

kotlin {
    androidTarget {
        compilations.all {
            kotlinOptions {
                jvmTarget = "1.8"
            }
        }
    }
    iosX64()
    iosArm64()
    iosSimulatorArm64()

    cocoapods {
        summary = "My SDK"
        homepage = "..."
        version = "x.y.z"
        ios.deploymentTarget = "13.4"
        framework {
            baseName = "shared"
            isStatic = true
        }
    }

    sourceSets {
        val commonMain by getting {
            dependencies {
                implementation(kotlin("stdlib-common"))
                // other dependencies...
            }
        }
        // other sourcesets...
    }
}

android {
    namespace = "com.example.myapp"
    compileSdk = 35
    defaultConfig {
        minSdk = 26
    }
    buildToolsVersion = "33.0.2"
    ndkVersion = "24.0.8215888"
    compileOptions {
        sourceCompatibility = JavaVersion.VERSION_1_8
        targetCompatibility = JavaVersion.VERSION_1_8
    }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Platform: KMP Type: Bug Something isn't working
Projects
Status: Todo
Development

No branches or pull requests

4 participants