text
stringlengths
1
474
Contains a meta-data entry that encodes
the mapping between loading units and component name the
loading unit is associated with. This mapping is used by the
embedder to convert Dart’s internal loading unit id
to the name of a deferred component to install. For example:The gen_snapshot validator won’t run until the prebuild
validator passes.For each of these checks,
the tool produces the modified or new files
needed to pass the check.
These files are placed in the
<projectDir>/build/android_deferred_components_setup_files directory.
It is recommended that the changes be applied by
copying and overwriting the same files in the
project’s android directory. Before overwriting,
the current project state should be committed to
source control and the recommended changes should be
reviewed to be appropriate. The tool won’t make any
changes to your android/ directory automatically.Once the available
loading units are generated and logged in
<projectDirectory>/deferred_components_loading_units.yaml,
it is possible to fully configure the pubspec’s
deferred-components section so that the loading units
are assigned to deferred components as desired.
To continue with the box example, the generated
deferred_components_loading_units.yaml file would contain:The loading unit id (‘2’ in this case) is used
internally by Dart, and can be ignored.
The base loading unit (id ‘1’) is not listed
and contains everything not explicitly contained
in another loading unit.You can now add the following to pubspec.yaml:To assign a loading unit to a deferred component,
add any Dart lib in the loading unit into the
libraries section of the feature module.
Keep the following guidelines in mind:Loading units should not be included
in more than one component.Including one Dart library from a
loading unit indicates that the entire loading
unit is assigned to the deferred component.All loading units not assigned to
a deferred component are included in the base component,
which always exists implicitly.Loading units assigned to the same
deferred component are downloaded, installed,
and shipped together.The base component is implicit and
need not be defined in the pubspec.Assets can also be included by adding
an assets section in the deferred component configuration:An asset can be included in multiple deferred components,
but installing both components results in a replicated asset.
Assets-only components can also be defined by omitting the
libraries section. These assets-only components must be
installed with the DeferredComponent utility class in
services rather than loadLibrary().
Since Dart libs are packaged together with assets,
if a Dart library is loaded with loadLibrary(),
any assets in the component are loaded as well.
However, installing by component name and the services utility
won’t load any dart libraries in the component.You are free to include assets in any component,
as long as they are installed and loaded when they
are first referenced, though typically,
assets and the Dart code that uses those assets
are best packed in the same component.Manually add all deferred components
that you defined in pubspec.yaml into the
android/settings.gradle file as includes.
For example, if there are three deferred components
defined in the pubspec named, boxComponent, circleComponent,
and assetComponent, ensure that android/settings.gradle
contains the following:Repeat steps 3.1 through 3.6 (this step)
until all validator recommendations are handled and the tool
runs without further recommendations.When successful, this command outputs an app-release.aab
file in build/app/outputs/bundle/release.A successful build does not always mean the app was
built as intended. It is up to you to ensure that all loading
units and Dart libraries are included in the way you intended.
For example, a common mistake is accidentally importing a
Dart library without the deferred keyword,
resulting in a deferred library being compiled as part of
the base loading unit. In this case, the Dart lib would
load properly because it is always present in the base,
and the lib would not be split off. This can be checked
by examining the deferred_components_loading_units.yaml
file to verify that the generated loading units are described
as intended.When adjusting the deferred components configurations,
or making Dart changes that add, modify, or remove loading units,
you should expect the validator to fail.
Follow steps 3.1 through 3.6 (this step) to apply any
recommended changes to continue the build.<topic_end>
<topic_start>
Running the app locally
Once your app has successfully built an .aab file,
use Android’s bundletool to perform
local testing with the --local-testing flag.To run the .aab file on a test device,
download the bundletool jar executable from
github.com/google/bundletool/releases and run:Where <your_app_project_dir> is the path to your app’s
project directory and <your_temp_dir> is any temporary
directory used to store the outputs of bundletool.
This unpacks your .aab file into an .apks file and
installs it on the device. All available Android dynamic
features are loaded onto the device locally and
installation of deferred components is emulated.Before running build-apks again,
remove the existing app .apks file:Changes to the Dart codebase require either incrementing
the Android build ID or uninstalling and reinstalling
the app, as Android won’t update the feature modules
unless it detects a new version number.<topic_end>
<topic_start>
Releasing to the Google Play Store
The built .aab file can be uploaded directly to
the Play store as normal. When loadLibrary() is called,
the needed Android module containing the Dart AOT lib and