Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save huynguyennovem/5479c08f46d362ec738debcf7a91fea0 to your computer and use it in GitHub Desktop.
Save huynguyennovem/5479c08f46d362ec738debcf7a91fea0 to your computer and use it in GitHub Desktop.
[Hands-on] Integrate a Flutter module into your iOS project

Step by step

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. 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

Screenshot 2022-12-31 at 14 12 51

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)"

Screenshot 2022-12-31 at 14 12 01

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

Screenshot 2022-12-31 at 14 13 16

Check result in Build Phases: Screenshot 2022-12-31 at 14 13 48

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment