Sub topic 10
Packaging Flutter for Release: Source, AAR, and Frameworks
This chapter assumes you know Flutter and Dart, and that you can build an Android or iOS app with its native tools. It focuses on choosing a release packaging method for a Flutter module already embedded in a native app.
Choose a packaging strategy
A Flutter module can reach the native app in two broad ways:
- Source integration: the host project points to the Flutter module. Flutter tooling builds the module during the native build.
- Prebuilt integration: Flutter produces Android libraries or iOS frameworks. The host project consumes those build outputs.
The choice affects build speed, repository size, CI setup, and how easily the native team can update Flutter code.
| Strategy | Best for | Main cost |
|---|---|---|
| Flutter source module | One repository or closely coordinated teams | Native builds depend on Flutter tooling |
| Android AAR | Separate Android consumers or controlled binary releases | You must publish and update binary artifacts |
| iOS frameworks or XCFrameworks | Separate iOS consumers or binary distribution | Framework versions must match the host and plugins |
A prebuilt package is not a complete native application. It contains Flutter code, the Flutter engine, assets, and plugin code needed by the module. The host app still supplies application configuration such as signing, permissions, and lifecycle integration.
Android source integration
Source integration is convenient when the native app and Flutter module are developed together. The Android project includes the module through Gradle settings, and the Flutter build process produces the required Android artifacts as part of the build.
This approach is usually simplest for a single application repository. It also makes Dart changes easy to test in CI because the build uses the module's current source.
Before a release build, verify that the native build invokes Flutter with the intended flavor and mode. A release build should not accidentally use debug artifacts.
Build Android AARs
An AAR is an Android Archive. It is a binary library that can contain compiled code, resources, assets, and metadata. Flutter can generate AAR files and a local Maven-style repository for them.
Run this command from the Flutter module:
flutter build aar --releaseThe output includes AARs for the Flutter module and its Android plugins. The generated repository can be copied to an internal artifact repository or consumed from a local directory during development.
The native Android project then adds that repository and declares the generated dependencies. The exact dependency names and versions come from the generated Maven metadata, so do not guess them. Keep all Flutter-related artifacts at the same version.
AAR packaging works well when:
- Native builds must not require a Flutter SDK.
- Several Android applications consume the same Flutter module.
- CI downloads versioned artifacts from an artifact repository.
- The Flutter team releases on a schedule independent of native application changes.
It adds release-management work. Every Dart, asset, engine, or plugin change requires a new AAR publication, and the host must update its dependency version.
> callout tip > Treat the Flutter module version as one release unit. Do not mix the AAR from one module build with plugin or engine artifacts from another build.
Build iOS frameworks
For iOS, Flutter can create frameworks or XCFrameworks for a native project to consume:
flutter build ios-framework \
--release \
--output=build/ios_frameworksAn XCFramework is an Apple bundle that can contain binaries for multiple platforms or architectures. The output normally includes Flutter engine and module frameworks, along with frameworks for plugins used by the module.
The host can integrate these outputs directly in Xcode or through an internal packaging process. Framework search paths, embedded frameworks, signing, and plugin registration must match the host application's configuration.
Source integration through CocoaPods is often easier during active development. Prebuilt frameworks are useful when the iOS team wants a stable binary contract, when the Flutter SDK should stay out of the native build environment, or when a module is distributed to multiple applications.
Release checks and trade-offs
Before shipping a prebuilt package, check the following:
- Build the package with
--release. - Confirm that all required assets are present.
- Test every native plugin used by the module.
- Verify architectures and minimum platform versions.
- Ensure the host uses matching Flutter artifacts.
- Test a clean native build on a machine without stale generated files.
- Record the Flutter version, module commit, plugin versions, and build mode.
Source packaging gives faster iteration and fewer artifact-publishing steps. Binary packaging gives repeatable inputs and separates Flutter builds from native builds. Neither option removes the need to test the complete host application.
Exercise
Your Android CI runners do not install the Flutter SDK, but several Android apps consume the same Flutter module. Which packaging strategy fits this requirement, and what must you version together?
Show answer
Build and publish release AARs to an internal Maven repository. Version the module AARs, plugin artifacts, assets, and compatible Flutter engine artifacts as one tested release set.