website/v1_mdbook/src/integrate/ios_headers.md
flutter_rust_bridge_codegen created a C header which lists all the
exported symbols from our library, then uses it so that Xcode won't strip
the symbols.
Add ios/Runner/bridge_generated.h (or macos/Runner/bridge_generated.h)
to the project, either by dragging it onto the project tree or
via the Add Files to "Runner"... menu option.
Switch to the Build Phases tab and drag the bridge_generated.h file over
to the Copy Bundle Resources section, if it isn't already present.
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)
..
}
It is important that you use the result of dummy_method_to_enforce_bundling() (like in the example above), otherwise the symbols might still get stripped.
If you release your app through App Store, the steps above might not be sufficient. In that case you need to modify how Xcode strips the symbols:
Ref: https://docs.flutter.dev/development/platform-integration/ios/c-interop#stripping-ios-symbols
Flutter on MacOS does not use headers by default, so let's go ahead and add one ourselves. In the Build Settings tab, set the Objective-C Bridging Header to be Runner/bridge_generated.h.
Also, head over to the Build Phases tab, Bundle Framework section and add your $crate.dylib by clicking the plus button. This includes your dynamic library file in your app package.
Finally, use dummy_method_to_enforce_bundling somewhere within
macos/Runner/AppDelegate.swift, as long as Xcode does not consider it dead code.
If there are multi-blocks:
Runner-Bridging-Header.h.For all cases, the AppDelegate.swift should be the same as that in the single-block case.
related issue