Recently, I met a problem that the iOS app didn’t work properly in release mode. After a little searching, I found it’s a Flutter app and invoked a Rust function by FFI. The inital call were not invoked during app startup, and it should be.

I finally resolved the problem by following:

In short:

  1. Xcode will strip the unused symbols in release mode, and won’t realize the FFI invocation;
  2. So we need add some dummy invocations to the AppDelegate.swift to make sure it have been used.

Next, add this line to ios/Runner/Runner-Bridging-Header.h:

+#import "bridge_generated.h"

and in ios/Runner/AppDelegate.swift:

 override func application(
     _ application: UIApplication,
     didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
 ) -> Bool {
+    let dummy = dummy_method_to_enforce_bundling()
+    print(dummy)
     ..
 }