text
stringlengths
1
474
Flutter’s build modesTo leverage Flutter debugging functionality
such as hot reload, see Debugging your add-to-app module.Using Flutter increases your app size.<topic_end>
<topic_start>
Option A - Embed with CocoaPods and the Flutter SDK
This method requires every developer working on your
project to have a locally installed version of the Flutter SDK.
The Flutter module is compiled from source each time the app is built.
Simply build your application in Xcode to automatically
run the script to embed your Dart and plugin code.
This allows rapid iteration with the most up-to-date
version of your Flutter module without running additional
commands outside of Xcode.The following example assumes that your existing
application and the Flutter module are in sibling
directories. If you have a different directory structure,
you might need to adjust the relative paths.If your existing application (MyApp) doesn’t
already have a Podfile, run pod init in the
MyApp directory to create one.
You can find more details on using
CocoaPods in the CocoaPods getting started guide.Add the following lines to your Podfile:
<code_start>flutter_application_path = '../my_flutter'
load File.join(flutter_application_path, '.ios', 'Flutter', 'podhelper.rb')<code_end>
For each Podfile target that needs to
embed Flutter, call install_all_flutter_pods(flutter_application_path).
<code_start>target 'MyApp' do
install_all_flutter_pods(flutter_application_path)
end<code_end>
In the Podfile’s post_install block, call flutter_post_install(installer).
<code_start>post_install do |installer|
flutter_post_install(installer) if defined?(flutter_post_install)
end<code_end>
info Note
The flutter_post_install method (added in Flutter 3.1.0),
adds build settings to support native Apple Silicon arm64 iOS simulators.
Include the if defined?(flutter_post_install) check to ensure your Podfile
is valid if you are running on older versions of Flutter that don’t have this method.Run pod install.info Note
When you change the Flutter plugin dependencies in
my_flutter/pubspec.yaml, run flutter pub get
in your Flutter module directory to refresh the list
of plugins read by the podhelper.rb script.
Then, run pod install again from
your application at some/path/MyApp.The podhelper.rb script embeds your plugins,
Flutter.framework, and App.framework into your project.Your app’s Debug and Release build configurations embed
the Debug or Release build modes of Flutter, respectively.
Add a Profile build configuration
to your app to test in profile mode.lightbulb Tip
Flutter.framework is the bundle for the Flutter engine,
and App.framework is the compiled Dart code for this project.Open MyApp.xcworkspace in Xcode.
You can now build the project using ⌘B.<topic_end>
<topic_start>
Option B - Embed frameworks in Xcode
Alternatively, you can generate the necessary frameworks
and embed them in your application by manually editing
your existing Xcode project. You might do this if members of your
team can’t locally install Flutter SDK and CocoaPods,
or if you don’t want to use CocoaPods
as a dependency manager in your existing applications.
You must run flutter build ios-framework
every time you make code changes in your Flutter module.The following example assumes that you want to generate the
frameworks to some/path/MyApp/Flutter/.warning Warning
Always use Flutter.xcframework and App.xcframework
from the same directory. Mixing .xcframework imports
from different directories (such as Profile/Flutter.xcframework
with Debug/App.xcframework) causes runtime crashes.Link and embed the generated frameworks into your existing
application in Xcode. There are multiple ways to do
this—use the method that is best for your project.<topic_end>
<topic_start>Link on the frameworks
For example, you can drag the frameworks from
some/path/MyApp/Flutter/Release/ in Finder
into your target’s Build
Settings > Build Phases > Link Binary With Libraries.In the target’s build settings, add $(PROJECT_DIR)/Flutter/Release/
to the Framework Search Paths (FRAMEWORK_SEARCH_PATHS).lightbulb Tip
To use the simulator, you will need to
embed the Debug version of the Flutter frameworks in your
Debug build configuration. To do this
you can use $(PROJECT_DIR)/Flutter/$(CONFIGURATION)
in the Framework Search Paths (FRAMEWORK_SEARCH_PATHS)
build setting. This embeds the Release frameworks in the Release configuration,
and the Debug frameworks in the Debug Configuration.You must also open MyApp.xcodeproj/project.pbxproj (from Finder)
and replace path = Flutter/Release/example.xcframework;
with path = "Flutter/$(CONFIGURATION)/example.xcframework";
for all added frameworks. (Note the added ".)<topic_end>
<topic_start>Embed the frameworks
The generated dynamic frameworks must be embedded
into your app to be loaded at runtime.error Important
Plugins might produce static or dynamic frameworks.
Static frameworks should be linked on, but never embedded.
If you embed a static framework into your application,
your application is not publishable to the App Store
and fails with a
Found an unexpected Mach-O header code archive error.After linking the frameworks, you should see them in the
Frameworks, Libraries, and Embedded Content
section of your target’s General settings.
To embed the dynamic frameworks
select Embed & Sign.They will then appear under Embed Frameworks within
Build Phases as follows:You should now be able to build the project in Xcode using ⌘B.<topic_end>
<topic_start>
Option C - Embed application and plugin frameworks in Xcode and Flutter framework with CocoaPods
Alternatively, instead of distributing the large Flutter.xcframework
to other developers, machines, or continuous integration systems,
you can instead generate Flutter as CocoaPods podspec by adding