Official document: https://docs.flutter.dev/development/add-to-app/ios/project-setup
1. From the terminal, go to your current iOS native project, for eg: /Users/.../ios_native_addtoapp/
2. Create flutter module and go to module directory
flutter create --template module my_flutter
cd my_flutter
3. (Optional) Add plugin to flutter module, for eg:
flutter pub add webview_flutter
4. Create a new directory from your current iOS native project directory, for eg: ios_using_prebuilt_module/Flutter
5. Execute build ios-framework command, for eg:
flutter build ios-framework --xcframework --output='/Users/.../ios_native_addtoapp/ios_using_prebuilt_module/Flutter'
The result:
Flutter
├── Debug
│ ├── App.xcframework
│ ├── Flutter.xcframework
│ ├── FlutterPluginRegistrant.xcframework
│ ├── OrderedSet.xcframework
│ ├── flutter_inappwebview.xcframework
│ └── webview_flutter_wkwebview.xcframework
├── Profile
│ ├── App.xcframework
│ ├── Flutter.xcframework
│ ├── FlutterPluginRegistrant.xcframework
│ ├── OrderedSet.xcframework
│ ├── flutter_inappwebview.xcframework
│ └── webview_flutter_wkwebview.xcframework
└── Release
├── App.xcframework
├── Flutter.xcframework
├── FlutterPluginRegistrant.xcframework
├── OrderedSet.xcframework
├── flutter_inappwebview.xcframework
└── webview_flutter_wkwebview.xcframework
6. Link built frameworks
6.1.
- From XCode with current native ios project, select Build Phases > Link Binary With Libraries
- Open
/Users/.../ios_native_addtoapp/ios_using_prebuilt_module/Flutter/Release
in Finder and drag all frameworks there into Link Binary With Libraries
6.2.
- From XCode with current native ios project, select target’s Build Settings, find Framework Search Paths
- Drag
/Users/.../ios_native_addtoapp/ios_using_prebuilt_module/Flutter/Release
folder into Framework Search Paths value - To use the simulator, change
Release
in path value into$(CONFIGURATION)
. For eg:"$(SRCROOT)/ios_using_prebuilt_module/Flutter/$(CONFIGURATION)"
7. Embed frameworks
- From XCode with current native ios project, select General tab
- Find Frameworks, Libraries, and Embedded Content section, Embed & Sign all added frameworks
Use one of these flags when building
ios-framework
for saving time in case no need to use all of them: