rules_flutter
Bazel rules for building Flutter apps.
Status: beta. It works today, but the public API may still change. Feedback and contributions are welcome.
rules_flutter compiles Dart to kernel or AOT native code, bundles assets, and packages the result for macOS, iOS, Android, Linux, Windows, and the web. It builds on rules_dart for Dart compilation and hands platform packaging to the rulesets that already do it well: rules_apple, rules_android, and friends. It also ships a dev tool, flutter_bazel, that gives you hot reload, hot restart, and an HTTP channel for driving a running app from an AI agent or script. It also supports frustrate, which allows Rust code to be used in apps built with rules_flutter.
Migrating from 0.1.0
-
Bazel 9.3 or newer.
-
Flutter 3.50.0 or later. rules_flutter asks for 3.50.0, and 3.47 is no
longer supported: flutter.toolchain(flutter_version = "3.47.9") fails.
Raise the pin and regenerate pubspec.lock with the new Flutter (see
Regenerating pubspec.lock). A framework of
your own must be 3.50 or later too. package:flutter/material.dart and
cupertino.dart still work; to move to the material_ui and
cupertino_ui packages, as flutter create now writes an app, add the
package to pubspec.yaml and its @deps target to deps (see
Your first app).
-
Custom SDKs: flutter.toolchain takes only a release, and its
framework, engine and material_fonts_sha256 are removed. Each form
of custom SDK has a tag of its own, which requires the attributes that
form needs:
framework and engine → flutter.custom_sdk(name, framework, engine, hosts),
where hosts names the machines the engine serves (["host"] for
flutter_local_engine).
For a flutter/flutter checkout and the engine built in it,
flutter.checkout(name) replaces both repositories and reads the
engine from $FLUTTER_CHECKOUT/engine/src/out, never from
FLUTTER_ENGINE.
engine with flutter_version →
flutter.custom_engine(name, engine, hosts, flutter_version).
framework with flutter_version →
flutter.custom_framework(name, framework, flutter_version).
material_fonts_sha256 → the same attribute on flutter.custom_sdk,
flutter.custom_framework or flutter.checkout.
A custom SDK can't be named flutter, the release every module may ask
a version of. To build with one by default, give it another name and
choose it with flutter.use_sdk(name = "<name>") in MODULE.bazel,
which replaces setting --@rules_flutter//flutter:sdk=<name> in
.bazelrc; the flag still overrides it. The flag's default is now empty,
meaning that choice, so a config_setting matching the flag to flutter
no longer matches a build that does not set it. See
Custom engines and frameworks.
-
Every file in the srcs of a flutter_application,
flutter_application_variant or flutter_test must be loaded from its
main, through imports, exports and parts. A file it never loads fails
the build, naming it: remove it from srcs or import it, and put a file
read at run time in data. bazel run @rules_dart//dart/unused_deps -- //...
lists them. features = ["-dart_unused_deps"] turns this check off,
with the unused-deps check. See Pub packages.
-
Apple plugins that use remote Swift packages (the FlutterFire plugins'
firebase-ios-sdk, say): your root module now declares those packages,
and rules_flutter declares none. Run bazel run @<hub>//swift:packages
and add what it prints: a Package.swift at the workspace root listing
the packages, rules_swift_package_manager's swift_deps.from_package and
use_repo in MODULE.bazel, and inject_repo(flutter_pub, ...) naming
the packages' repositories. Keep swift_package_resolved on
flutter_pub.from_lock, naming the same Package.resolved, and re-pin it
with bazel run @swift_package//:update. A pin that a plugin's
Package.swift doesn't accept fails the build. bazel run @<hub>//swift:resolve
is removed. Firebase with explicit Clang modules also needs the target
modifications in Explicit Clang modules on macOS and iOS.
See Swift packages a plugin depends on.
-
Signed iOS apps get the entitlements Xcode gives them (see entitlements
under iOS), no longer all their provisioning profile grants:
- An app with no entitlements file was signed with everything its profile
grants. A grant it used only that way, such as push
(
aps-environment), associated domains or an App Group, now has to be
in its entitlements file.