Search code examples
flutterflutter-desktop

Flutter desktop app for MacOS using extra binaries crashes when exported


I want to distribute a Flutter desktop app outside of App Store. The app includes some extra binaries using the assets key in pubspec.yaml. The binaries end up in this directory inside the app:

flutter_sample.app/Contents/Frameworks/App.framework/Versions/A/Resources/flutter_assets/bin

So that's what I use with Process.run(...) and it works locally. However, if I try to notarize the app in Xcode and export it then app will crash immediately when trying to run an included binary. I opened Console and found the following entry in launchd.log corresponding to the time the app crashed:

2022-01-07 08:28:04.875197 (gui/501/application.com.example.flutterSample.1772919.1772925) : removing job: caller = runningboardd
2022-01-07 08:28:04.875204 (gui/501 [100020]) : removing service: application.com.example.flutterSample.1772919.1772925
2022-01-07 08:28:04.875309 (gui/501/application.com.example.flutterSample.1772919.1772925) : internal event: PETRIFIED, code = 0 2022-01-07 08:28:04.875311 (gui/501/application.com.example.flutterSample.1772919.1772925) : job state = removed

I wasn't able to find any other information about the error. If I enclose the code using Process.run in a try-catch block it doesn't change anything, the entire application crashes anyway. The same happens if I use a zone or onError handler as described on the handling errors page in Flutter docs.

Extra details:

  • I've disabled com.apple.security.app-sandbox in the *.entitlements files, with it running the processes didn't work even locally
  • I've enabled hardened runtime in Xcode, it was required to notarize the app.
  • the app also crashes if instead or exporting from Xcode I plainly archive the build directory (with tar) and send it via internet (or set com.apple.quarantine with xattr). It won't crash if I just pack and unpack it without marking it as quarantined. That makes sense but I expected that notarizing the app would fix it.

So, what can I do to prevent these crashes, or at least get more details when they happen so I can investigate further?


Solution

  • As it turns out, it was an issue with paths. If I go to my project directory and then enter the debug build directory:

    $ cd build/macos/Build/Products/Debug
    

    then from this point I can access two identical asset directories:

    $ ls -lh App.framework/Versions/A/Resources/flutter_assets
    (output omitted)
    
    $ ls -lh flutter_sample.app/Contents/Frameworks/App.framework/Versions/A/Resources/flutter_assets
    
    (the same output, omitted)
    

    As it turns out, I was actually trying to call the binary in the first asset directory (even though I posted the second one in the question). And apparently the other one is correct when the app is packaged for distribution. After changing this the binaries work in the exported, notarized app.