[flutter_tools] hot reload/restart update for asset manager change (#66742)

Do not upload all assets on initial devFS sync. This should increase the reliability of the initial connection, even in the face of flaky devfs behavior, in addition to a moderate perf improvement.

Updates fast-start to build assets as part of the initial bundle

Requires flutter/engine#21436
Requires flutter/engine#21586
Requires flutter/engine#21611
This commit is contained in:
Jonah Williams
2020-10-09 12:25:15 -07:00
committed by GitHub
parent a755c03819
commit 9a3a0dc18f
7 changed files with 165 additions and 47 deletions

View File

@@ -34,11 +34,9 @@ abstract class AndroidAssetBundle extends Target {
@override
List<String> get depfiles => <String>[
if (_copyAssets)
'flutter_assets.d',
'flutter_assets.d',
];
bool get _copyAssets => true;
@override
Future<void> build(Environment environment) async {
@@ -61,21 +59,19 @@ abstract class AndroidAssetBundle extends Target {
environment.fileSystem.file(isolateSnapshotData)
.copySync(outputDirectory.childFile('isolate_snapshot_data').path);
}
if (_copyAssets) {
final Depfile assetDepfile = await copyAssets(
environment,
outputDirectory,
targetPlatform: TargetPlatform.android,
);
final DepfileService depfileService = DepfileService(
fileSystem: environment.fileSystem,
logger: environment.logger,
);
depfileService.writeToFile(
assetDepfile,
environment.buildDir.childFile('flutter_assets.d'),
);
}
final Depfile assetDepfile = await copyAssets(
environment,
outputDirectory,
targetPlatform: TargetPlatform.android,
);
final DepfileService depfileService = DepfileService(
fileSystem: environment.fileSystem,
logger: environment.logger,
);
depfileService.writeToFile(
assetDepfile,
environment.buildDir.childFile('flutter_assets.d'),
);
}
@override
@@ -108,17 +104,6 @@ class DebugAndroidApplication extends AndroidAssetBundle {
];
}
/// A minimal android application that does not include assets.
class FastStartAndroidApplication extends DebugAndroidApplication {
const FastStartAndroidApplication();
@override
String get name => 'faststart_android_application';
@override
bool get _copyAssets => false;
}
/// An implementation of [AndroidAssetBundle] that only includes assets.
class AotAndroidAssetBundle extends AndroidAssetBundle {
const AotAndroidAssetBundle();

View File

@@ -49,7 +49,6 @@ const List<Target> _kDefaultTargets = <Target>[
CopyFlutterBundle(),
// Android targets,
DebugAndroidApplication(),
FastStartAndroidApplication(),
ProfileAndroidApplication(),
// Android ABI specific AOT rules.
androidArmProfileBundle,

View File

@@ -472,7 +472,6 @@ class DevFS {
String dillOutputPath,
bool fullRestart = false,
String projectRootPath,
bool skipAssets = false,
}) async {
assert(trackWidgetCreation != null);
assert(generator != null);
@@ -484,24 +483,23 @@ class DevFS {
final Map<Uri, DevFSContent> dirtyEntries = <Uri, DevFSContent>{};
int syncedBytes = 0;
if (bundle != null && !skipAssets) {
if (bundle != null) {
final String assetBuildDirPrefix = _asUriPath(getAssetBuildDirectory());
// We write the assets into the AssetBundle working dir so that they
// The tool writes the assets into the AssetBundle working dir so that they
// are in the same location in DevFS and the iOS simulator.
final String assetDirectory = getAssetBuildDirectory();
bundle.entries.forEach((String archivePath, DevFSContent content) {
if (!content.isModified || bundleFirstUpload) {
return;
}
final Uri deviceUri = _fileSystem.path.toUri(_fileSystem.path.join(assetDirectory, archivePath));
if (deviceUri.path.startsWith(assetBuildDirPrefix)) {
archivePath = deviceUri.path.substring(assetBuildDirPrefix.length);
}
// Only update assets if they have been modified, or if this is the
// first upload of the asset bundle.
if (content.isModified || (bundleFirstUpload && archivePath != null)) {
dirtyEntries[deviceUri] = content;
syncedBytes += content.size;
if (archivePath != null && !bundleFirstUpload) {
assetPathsToEvict.add(archivePath);
}
dirtyEntries[deviceUri] = content;
syncedBytes += content.size;
if (archivePath != null && !bundleFirstUpload) {
assetPathsToEvict.add(archivePath);
}
});
}

View File

@@ -818,7 +818,6 @@ class WebDevFS implements DevFS {
String dillOutputPath,
bool fullRestart = false,
String projectRootPath,
bool skipAssets = false,
}) async {
assert(trackWidgetCreation != null);
assert(generator != null);