Skip to content

Instantly share code, notes, and snippets.

@huycozy
Last active September 25, 2023 14:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save huycozy/ef762c86a6db2fdcde1ac50be5596b86 to your computer and use it in GitHub Desktop.
Save huycozy/ef762c86a6db2fdcde1ac50be5596b86 to your computer and use it in GitHub Desktop.
Add to app iOS - Embed frameworks in Xcode (option B)

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

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

@huycozy
Copy link
Author

huycozy commented Mar 10, 2023

Use one of these flags when building ios-framework for saving time in case no need to use all of them:

--no-debug
--no-release
--no-profile

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