- tags: Rust,Flutter,iOS
- source: “Using Dummy Headers - Flutter_rust_bridge.” Accessed July 25, 2022. http://cjycode.com/flutter_rust_bridge/integrate/ios_headers.html.
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:
- https://github.com/fzyzcjy/flutter_rust_bridge/issues/496
- http://cjycode.com/flutter_rust_bridge/integrate/ios_headers.html
In short:
- Xcode will strip the unused symbols in release mode, and won’t realize the FFI invocation;
- 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)
..
}