sentry-dart icon indicating copy to clipboard operation
sentry-dart copied to clipboard

Build flutter as macos-framework and import into swift:Failed to build module 'sentry_flutter'

Open Messiahfy opened this issue 6 months ago • 6 comments

Platform

Dart, Flutter Desktop macOS

Obfuscation

Disabled

Debug Info

Disabled

Doctor

[✓] Flutter (Channel stable, 3.29.2, on macOS 15.5 24F74 darwin-arm64, locale zh-Hans-CN) [1,271ms] • Flutter version 3.29.2 on channel stable at /Users/huangfeiyang/flutterSDK/flutter • Upstream repository https://github.com/flutter/flutter.git • Framework revision c236373904 (3 个月前), 2025-03-13 16:17:06 -0400 • Engine revision 18b71d647a • Dart version 3.7.2 • DevTools version 2.42.3

[✓] Android toolchain - develop for Android devices (Android SDK version 35.0.0) [2.4s] • Android SDK at /Users/huangfeiyang/Library/Android/sdk • Platform android-35, build-tools 35.0.0 • Java binary at: /Applications/Android Studio.app/Contents/jbr/Contents/Home/bin/java This is the JDK bundled with the latest Android Studio installation on this machine. To manually set the JDK path, use: flutter config --jdk-dir="path/to/jdk". • Java version OpenJDK Runtime Environment (build 21.0.6+-13368085-b895.109) • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 16.3) [2.1s] • Xcode at /Applications/Xcode.app/Contents/Developer • Build 16E140 • CocoaPods version 1.16.2

[✓] Chrome - develop for the web [33ms] • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio (version 2024.3) [33ms] • Android Studio at /Applications/Android Studio.app/Contents • Flutter plugin can be installed from: 🔨 https://plugins.jetbrains.com/plugin/9212-flutter • Dart plugin can be installed from: 🔨 https://plugins.jetbrains.com/plugin/6351-dart • Java version OpenJDK Runtime Environment (build 21.0.6+-13368085-b895.109)

[✓] IntelliJ IDEA Community Edition (version 2023.3.6) [31ms] • IntelliJ at /Applications/IntelliJ IDEA CE.app • Flutter plugin can be installed from: 🔨 https://plugins.jetbrains.com/plugin/9212-flutter • Dart plugin can be installed from: 🔨 https://plugins.jetbrains.com/plugin/6351-dart

[✓] VS Code (version 1.100.2) [9ms] • VS Code at /Applications/Visual Studio Code.app/Contents • Flutter extension version 3.110.0

[!] Proxy Configuration [8ms] • HTTP_PROXY is set ! NO_PROXY is not set

[✓] Connected device (3 available) [6.2s] • macOS (desktop) • macos • darwin-arm64 • macOS 15.5 24F74 darwin-arm64 • Mac Designed for iPad (desktop) • mac-designed-for-ipad • darwin • macOS 15.5 24F74 darwin-arm64 • Chrome (web) • chrome • web-javascript • Google Chrome 136.0.7103.114

[✓] Network resources [974ms] • All expected network resources are available.

! Doctor found issues in 1 category.

Version

8.14.2

Steps to Reproduce

  1. add sentry_flutter in flutter project:
// pubspec.yaml
dependencies:
    sentry_flutter: ^8.14.2
  1. run command:"flutter build macos-framework",it will generate some *.xcframework at {flutterProjectDir}/build/macos/framework/Debug/

Due to our business reasons, we did not build the Mac app directly through the Flutter project, but built the framework

Image
  1. create a new macos app xcode project, and add these *.xcframework into xcode project
Image
  1. build error
Image Image

I found that "SentrySdkInfo.h" does not exist Image

Expected Result

build success

Actual Result

build error

(But if I run the flutter project as macos app directly, it's ok. If you use framework, you will get an error)

Are you willing to submit a PR?

None

Messiahfy avatar May 29 '25 07:05 Messiahfy

That seems odd, @philprime do you maybe know what's wrong?

I can't tell whether this is a Flutter tooling issue or not

buenaflor avatar May 30 '25 09:05 buenaflor

Yes, this is odd. Which version of Sentry Cocoa is used here? Where does the framework come from?

philprime avatar Jun 02 '25 10:06 philprime

  1. Which version of Sentry Cocoa is used here? Instead of using sentry cocoa directly, I use the sentry flutter plugin.

  2. Where does the framework come from? Generate the framework through flutter build macos-framework command

Messiahfy avatar Jun 03 '25 03:06 Messiahfy

Since he mentioned using 8.14.2 it would be sentry-cocoa 8.46.0

@Messiahfy could you check if older versions of the Sentry Flutter SDK work?

buenaflor avatar Jun 05 '25 11:06 buenaflor

I'm in the exact same situation as @Messiahfy.

I tried version 8.11.0. According to the changelog (https://pub.dev/packages/sentry_flutter/changelog), the Cocoa SDK version for this release is 8.41.0. However, the issue still persists.

I suspect the main problem is that when using the flutter build macos-framework command, the built framework is missing necessary header files. But I'm not quite clear on how this build process works. My reasoning is based on the following observations:

  1. When I manually replace the precompiled Sentry.xcframework, the error can be avoided. (I downloaded it from here: https://github.com/getsentry/sentry-cocoa/releases?page=2)
  2. Alternatively, when I add the two missing header files to the framework produced by Flutter, the error can also be avoided. (Specifically, these are: SentryInternalSerializable.h and SentrySdkInfo.h)
  3. When I compared the header files in the precompiled framework with those in the framework built using flutter build macos-framework, I found that there are significantly fewer headers in the latter. Both of the above-mentioned header files are located in the PrivateHeaders directory.

Therefore, I suspect that during the flutter build macos-framework process, the necessary header files are not being exposed.

ClassWizard avatar Jun 09 '25 07:06 ClassWizard

Thanks for the details, we will have a look

buenaflor avatar Jun 11 '25 07:06 buenaflor

hey sorry we don't have an update yet here.

I assume this is still an issue?

buenaflor avatar Jul 02 '25 13:07 buenaflor

Yes, this issue still exists

Messiahfy avatar Jul 03 '25 01:07 Messiahfy

Gotcha, I'll investigate this whether it's a Flutter tooling issue or a Sentry issue

buenaflor avatar Jul 04 '25 07:07 buenaflor

Closing this as we do not support this use case currently - I'd suggest to use the current workaround mentioned in this comment.

Let us know if you have any more questions

buenaflor avatar Oct 09 '25 11:10 buenaflor