Completing the remaining steps for iOS. After successfully creating macOS, building the iOS version is relatively straightforward.
An common step for macOS / iOS is needed: creating an Xcode project inside of the Rust library project folder (rust/). This can be done using the
To install the
cargo install cargo-xcode
After the installation of the command, create the Rust Xcode project. Make sure to be in the rust/ directory. From the project's root folder you may switch into the right directory:
Our next task is to create the generated code. This will also copy the C header file
bridge_generated.h into the folder ios/Runner/. Use this command (you need to be in the root of your project):
flutter_rust_bridge_codegen \ --rust-input rust/src/api.rs \ --dart-output ./lib/bridge_generated.dart \ --dart-decl-output ./lib/bridge_definitions.dart \ --c-output ios/Runner/bridge_generated.h
As a shortcut, use the terminal and execute:
open -a simulator
Follow the video for the remaining steps.
A user informed me about encountering issues when attempting to run the app on the iOS Simulator. Having not used the app for several months, I decided to test it myself and encountered some problems, too. Here is my response to the user.
Upon receiving your notification about the issue, I dedicated time today to rebuild the project. Since I initially set up and completed the project, there have been changes in my personal development environment. Specifically, I upgraded to macOS Sonoma 14.1.1 and installed Xcode 15. Upon launching VS Code, the project prompted me to execute "flutter pub upgrade" due to a change in the Flutter version during this period. Unfortunately, when attempting to run the project on iOS using "flutter run," the build process encountered a failure.
Despite not being aware of your specific circumstances, I managed to resolve all errors, successfully rebuild the project, and run it on the iOS Simulator, specifically using iPhone 15 Pro Max with iOS 17.0.
I followed these steps to address the issue:
- Updated Rust to the latest version using "rustup update."
- Deleted the Cargo.lock file.
- Deleted the rust/target/ folder.
- Deleted the following generated files: rust/src/bridge_generated.io.rs, rust/src/bridge_generated.rs, bridge_definitions.dart, bridge_generated.dart.
- Removed the first generated line in rust/src/lib.rs.
- Restarted VS Code.
- Regenerated the Dart Code using the command in the tutorial, resulting in the creation of two Rust files and two Dart files.
- Initially, VS Code displayed an error in the bridge_generated.rs file. After restarting VS Code, the error disappeared.
- In the Terminal, navigated to the rust/ directory and executed "cargo build --target aarch64-apple-ios-sim," which was successful.
- Returned to the root directory (cd ..) and ran "flutter run"
- I received messages about "Xcode 15 compatibility" (or similar) and ultimately, the library and the app were successfully built, launching without any issues.
These steps were necessary because I initially created the project under macOS 13, Xcode 14, and lower versions of Flutter and Rust. I assume if you build the project from scratch using the Flutter-only version on GitHub and follow the steps outlined in the tutorial, you shouldn't encounter the same issue.