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

[Flutter Desktop Windows] fresh flutter app does not build on Windows

Open jefflongo opened this issue 4 months ago • 20 comments

Platform

Flutter Desktop Windows

Obfuscation

Disabled

Debug Info

Disabled

Doctor

[√] Flutter (Channel stable, 3.32.7, on Microsoft Windows [Version 10.0.26100.4652], locale en-US) [419ms]
    • Flutter version 3.32.7 on channel stable at C:\Users\jeffa\AppData\Local\flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision d7b523b356 (8 days ago), 2025-07-15 17:03:46 -0700
    • Engine revision 39d6d6e699
    • Dart version 3.8.1
    • DevTools version 2.45.1

[√] Windows Version (11 Pro 64-bit, 24H2, 2009) [3.4s]

[√] Android toolchain - develop for Android devices (Android SDK version 35.0.0) [1,896ms]
    • Android SDK at C:\Users\jeffa\AppData\Local\Android\sdk
    • Platform android-35, build-tools 35.0.0
    • Java binary at: C:\Program Files\Android\Android Studio\jbr\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 17.0.11+0--11852314)
    • All Android licenses accepted.

[√] Chrome - develop for the web [96ms]
    • Chrome at C:\Program Files\Google\Chrome\Application\chrome.exe

[√] Visual Studio - develop Windows apps (Visual Studio Community 2022 17.2.3) [94ms]
    • Visual Studio at C:\Program Files\Microsoft Visual Studio\2022\Community
    • Visual Studio Community 2022 version 17.2.32526.322
    • Windows 10 SDK version 10.0.22621.0

[√] Android Studio (version 2024.1) [28ms]
    • Android Studio at C:\Program Files\Android\Android Studio
    • 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 17.0.11+0--11852314)

[√] VS Code, 64-bit edition (version 1.100.2) [27ms]
    • VS Code at C:\Program Files\Microsoft VS Code
    • Flutter extension version 3.114.0

[√] Connected device (3 available) [258ms]
    • Windows (desktop) • windows • windows-x64    • Microsoft Windows [Version 10.0.26100.4652]
    • Chrome (web)      • chrome  • web-javascript • Google Chrome 138.0.7204.98
    • Edge (web)        • edge    • web-javascript • Microsoft Edge 138.0.3351.95

[√] Network resources [322ms]
    • All expected network resources are available.

• No issues found!

Version

9.5.0

Steps to Reproduce

Create app from template:

flutter create -t app my_app
cd my_app
flutter pub add sentry_flutter

Modify main.dart:

Future<void> main() async {
  await SentryFlutter.init((options) {
    options.dsn = 'some-dsn'; // insert dsn here
    options.diagnosticLevel = SentryLevel.debug;
  }, appRunner: () => runApp(const MyApp()));
}

Build and run:

flutter build windows
flutter run

Expected Result

Build succeeds

Actual Result

Verbose log of failed build

The seeming smoking gun of the failure is here:

[  +13 ms]   CMake Error at _deps/sentry-native-build/crashpad_build/handler/cmake_install.cmake:41 (file):
[        ]     file cannot create directory:
[        ]     /path/to/project/my_app/build/windows/x64/$<TARGET_FILE_DIR:my_app>/bin.
[        ]     Maybe need administrative privileges.
[        ]   Call Stack (most recent call first):
[        ]     _deps/sentry-native-build/crashpad_build/cmake_install.cmake:46 (include)
[        ]     _deps/sentry-native-build/cmake_install.cmake:42 (include)
[        ]     plugins/sentry_flutter/cmake_install.cmake:37 (include)
[        ]     cmake_install.cmake:47 (include)

where crashpad is attempted to be installed into /path/to/project/my_app/build/windows/x64/$<TARGET_FILE_DIR:my_app>/bin. but the directory does not exist.

Are you willing to submit a PR?

No

jefflongo avatar Jul 24 '25 02:07 jefflongo

@jefflongo hey could you try setting the env var SENTRY_NATIVE_BACKEND to breakpad and then try to compile while we investigate this issue

buenaflor avatar Jul 24 '25 08:07 buenaflor

App does build using breakpad.

jefflongo avatar Jul 24 '25 14:07 jefflongo

@jefflongo which cmake version are you using?

buenaflor avatar Jul 24 '25 22:07 buenaflor

Tried with 3.23.0-rc3 then upgraded to 4.0.3 and tried again. Both failed in the same way.

jefflongo avatar Jul 25 '25 01:07 jefflongo

only in debug mode work

hbedford avatar Jul 25 '25 22:07 hbedford

Thanks for the infos, we'll have a look

buenaflor avatar Jul 28 '25 13:07 buenaflor

@vaind do you have an idea here?

buenaflor avatar Jul 29 '25 09:07 buenaflor

Can you please try a fresh flutter build, i.e. flutter clean or git clean -ffxd . (make sure you understand the latter before running - it removes all uncommitted changes)

vaind avatar Jul 29 '25 10:07 vaind

Clean build produces the same error. As mentioned before, this error happens in a fresh project.

jefflongo avatar Jul 29 '25 15:07 jefflongo

Started digging into this problem a bit..

The root cause is due to how the Flutter Windows CMake project template sets CMAKE_INSTALL_PREFIX. Check this snippet in the windows/CMakeLists.txt which sets CMAKE_INSTALL_PREFIX to $<TARGET_FILE_DIR:${BINARY_NAME}>

# === Installation ===
# Support files are copied into place next to the executable, so that it can
# run in place. This is done instead of making a separate bundle (as on Linux)
# so that building and running from within Visual Studio will work.
set(BUILD_BUNDLE_DIR "$<TARGET_FILE_DIR:${BINARY_NAME}>")
# Make the "install" step default, as it's required to run.
set(CMAKE_VS_INCLUDE_INSTALL_TO_DEFAULT_BUILD 1)
if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
  set(CMAKE_INSTALL_PREFIX "${BUILD_BUNDLE_DIR}" CACHE PATH "..." FORCE)
endif()

The sentry-native CMake project then calls install for crashpad which generates cmake_install.cmake with this snippet:

if(NOT DEFINED CMAKE_INSTALL_PREFIX)
  set(CMAKE_INSTALL_PREFIX "$<TARGET_FILE_DIR:my_app>")
endif()

because of how Flutter set CMAKE_INSTALL_PREFIX. $<TARGET_FILE_DIR:my_app> cannot be resolved at configure time, leading to the failure.

I'm no CMake expert, so I don't know what the correct solution is here, but it feels like the fix needs to be in the Flutter generated CMakeLists.txt.

jefflongo avatar Aug 02 '25 22:08 jefflongo

@vaind wdyt?

buenaflor avatar Aug 04 '25 09:08 buenaflor

Looks like related to the linux issue. Does the workaround work here as well? https://github.com/getsentry/sentry-dart/issues/3009#issuecomment-3019584030

vaind avatar Aug 04 '25 10:08 vaind

No, it does not. I tried modifying the CMAKE_INSTALL_PREFIX to not use a generator expression similar to how the Linux CMake script operates where it creates a new directory to copy the files into. This did allow the crashpad handler to build, and it did have execute privileges, however the app would not run. I'd get some error like "the log reader stopped unexpectedly or never started" when using flutter run.

I suspect making that change to the CMake script requires some other change, but I don't know enough about how Flutter works internally. Also that change probably breaks Visual Studio builds (which is why it's different to begin with), but I don't use VS so I'm not sure what needed there.

jefflongo avatar Aug 04 '25 13:08 jefflongo

hm does it make sense to consider setting breakpad by default for windows?

buenaflor avatar Aug 06 '25 14:08 buenaflor

IMO this should be a very solvable problem for someone more experienced in CMake and Flutter's ecosystem, but I do think that until that happens there should be a different default. Not being able to build a project without setting an environment variable is not good..

jefflongo avatar Aug 06 '25 16:08 jefflongo

Sorry to bump, but is there any planned resolution for this? Having to set an environment variable to build a project is a bit of a dealbreaker, and I'd like to avoid having to roll back to Sentry 8.x.

jefflongo avatar Sep 07 '25 08:09 jefflongo

hey sorry about that, I think it makes sense to set breakpad as default for Windows, there has been lots of issues coming up on Windows and although crasphad is much more preferable to using breakpad it's definitely not good if users can't even build the app without knowing this information.

I will be on PTO soon till the end of September so I will get back to this around that time

buenaflor avatar Sep 08 '25 10:09 buenaflor

https://sentry.zendesk.com/agent/tickets/166030

cobyeastwood183 avatar Nov 08 '25 00:11 cobyeastwood183

I'll consider making it as default in 9.10.0

buenaflor avatar Nov 12 '25 10:11 buenaflor