AOT Compilation Error with flutter_local_notifications
Describe the bug
When building a Flutter application for Windows, the AOT compilation fails with an error related to the flutter_local_notifications_windows plugin. Specifically, the snapshot generator crashes with an "Unexpected object" error referring to the NativeLaunchDetails class in the plugin's bindings.
To Reproduce
- Add flutter_local_notifications ^19.2.0 to pubspec.yaml
- Configure the plugin according to the README
- Run
flutter build windows --release - Build fails during AOT compilation with error code -1073740791
Expected behavior The Windows application should build successfully without any errors related to the AOT compilation.
Sample code to reproduce the problem I am using the standard Flutter application with local notifications added. The error occurs during the build process, specifically in the AOT compilation step.
Error details Unexpected object (Class with illegal cid, full-aot): 0x1e3e8fa1ba1 Library:'package/src/ffi/bindings.dart' Class: NativeLaunchDetails Dart snapshot generator failed with exit code -1073740791 Target aot_elf_release failed: Exception: AOT snapshotter exited with code -1073740791 Environment info flutter_local_notifications: ^19.2.0 [√] Flutter (Channel stable, 3.29.3, on Microsoft Windows [Version 10.0.26100.3915], locale uk-UA) [√] Windows Version (Њ ©Єа®б®дв Windows 11 Pro 64-bit, 24H2, 2009) [√] Android toolchain - develop for Android devices (Android SDK version 34.0.0) [√] Chrome - develop for the web [√] Visual Studio - develop Windows apps (Visual Studio Community 2022 17.13.6) [√] Android Studio (version 2022.2) [√] VS Code (version 1.95.3) [√] Connected device (3 available) [√] Network resources Additional context The issue appears to be specific to the Windows build and related to FFI bindings in the plugin. The error only occurs during the AOT compilation for release mode.
I'm also facing the same error MSB8066 with exit code -1073740791.
@MaikuB
I can't reproduce this with the example app. Can you provide a link to repository hosting a minimal app that can reproduce the issue?
@bitscoper this is a bit of a weird one. The build error is happening due to no code calling this method. I don't know if there's a better way to manage this or why this causes a build issue (my assumption is due to tree shaking) but adding that solved the issue for your repo. You able to see if you can confirm it on your end? Either way, it's something apps would typically need to handle when a user taps/clicks on a notification whilst an app is in a terminated state
@bitscoper I'd suggest getting help from others on this one and posting about this on the Flutter repo may help. I can't tell what the issue is here but what I found from using your repository is that a release build without obfuscation works. There might be something specific to your codebase where enabling obfuscation is causing an issue
I can't help more on this as I was able build the app locally without obfuscation.
The other unrelated advice to give you is improving on how you structure your code. Trying to initialise the plugin and check if the app was launched by a notification should happen on startup. You had this all happen when calling a method to send a notification
I'm also facing the same error
MSB8066withexit code -1073740791.
Using subosito/[email protected] in GitHub Actions resolved the issue for me.
Same issue. For me it only worked when I uninstalled Windows SDK version 10.0.26100.4188 and installed version 10.0.22621.0 on visual studio installer.
~~@AndreLuizNogueira~~ (sorry, meant to ping @AndriiReverchuk) do either of these suggestions help you?
@Levi-Lesches I did a bit of investigation and noticed that when initializing NotificationDetails with windows: WindowsNotificationDetails() (leaving all parameters empty), it results in a compilation error.
In my implementation, I later added action buttons, and once I specified them in WindowsNotificationDetails, the compilation error was no longer present.
This suggests the issue might be related to the Windows notification API requiring a minimal set of parameters to be defined. When those parameters (such as actions) are provided, the compiler has the necessary data and the error disappears.
That's very strange. If you're able to reproduce it, can you provide your flutter doctor -v? And if you can, try updating to the latest Flutter and Windows SDK in Microsoft Visual Studio and try again.
This suggests the issue might be related to the Windows notification API requiring a minimal set of parameters to be defined. When those parameters (such as actions) are provided, the compiler has the necessary data and the error disappears.
I don't think anything Dart-side should yield a compiler error since the Windows code (C++) is completely independent. It has all the fields filled out at compile time, just with C++ variables. At runtime, these values are substituted with the values you passed in initialize(). So the Windows SDK can't "realize" they're empty until runtime.