sentry-kotlin-multiplatform icon indicating copy to clipboard operation
sentry-kotlin-multiplatform copied to clipboard

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

Open franmontiel opened this issue 1 year ago • 27 comments

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 -> https://github.com/getsentry/sentry-kotlin-multiplatform/issues/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 avatar Jan 30 '25 11:01 franmontiel

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

buenaflor avatar Jan 30 '25 11:01 buenaflor

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 avatar Jan 30 '25 11:01 franmontiel

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

franmontiel avatar Jan 30 '25 11:01 franmontiel

@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

buenaflor avatar Jan 30 '25 11:01 buenaflor

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
    }
}

franmontiel avatar Jan 30 '25 11:01 franmontiel

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 avatar Jan 30 '25 12:01 buenaflor

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 avatar Jan 30 '25 12:01 buenaflor

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?

franmontiel avatar Jan 30 '25 12:01 franmontiel

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)

buenaflor avatar Jan 30 '25 13:01 buenaflor

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 avatar Jan 30 '25 13:01 franmontiel

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?

franmontiel avatar Jan 30 '25 13:01 franmontiel

yeah that doesn't look right

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

buenaflor avatar Jan 30 '25 13:01 buenaflor

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

buenaflor avatar Jan 30 '25 13:01 buenaflor

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

franmontiel avatar Jan 30 '25 13:01 franmontiel

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

buenaflor avatar Jan 30 '25 13:01 buenaflor

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

franmontiel avatar Jan 30 '25 16:01 franmontiel

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 avatar Jan 30 '25 16:01 buenaflor

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

buenaflor avatar Jan 30 '25 17:01 buenaflor

@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.

franmontiel avatar Jan 30 '25 19:01 franmontiel

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

buenaflor avatar Feb 04 '25 13:02 buenaflor

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.

ade avatar Feb 05 '25 15:02 ade

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 avatar Feb 05 '25 15:02 buenaflor

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

buenaflor avatar Feb 11 '25 12:02 buenaflor

@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]

remarkjt avatar Feb 20 '25 03:02 remarkjt

@remarkjt can you share your gradle config

buenaflor avatar Feb 20 '25 17:02 buenaflor

@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
    }
}

remarkjt avatar Feb 21 '25 03:02 remarkjt

Hi @buenaflor, for me the new plugin fixes the local build but now I am unable to build the iOS library using Github Actions. The build fails with the following error:

Plugin 'io.sentry.kotlin.multiplatform.gradle': failed to compute value with custom source 'io.sentry.kotlin.multiplatform.gradle.DerivedDataPathValueSource' with org.gradle.process.internal.ExecException: Process 'command 'xcodebuild'' finished with non-zero exit value 74

I've just created a new issue for this problem.

franmontiel avatar Mar 19 '25 14:03 franmontiel

Closing this for now, let us know if you still have issues

buenaflor avatar Nov 04 '25 10:11 buenaflor