Skip to content

Commit

Permalink
When running in AOT modes create a flutter_assets directory that can …
Browse files Browse the repository at this point in the history
…be used as the bundle path (flutter#9306)

The engine RunBundleAndSnapshotFromLibrary API expects a bundle path directory
containing the application's assets.  If the Android embedding is using
AOT ELF library packaging and does not need to extract assets, then create an
empty directory at the bundle path.

Fixes flutter#34287
  • Loading branch information
jason-simmons committed Jun 13, 2019
1 parent 1593838 commit 209250d
Showing 1 changed file with 23 additions and 16 deletions.
39 changes: 23 additions & 16 deletions shell/platform/android/io/flutter/view/FlutterMain.java
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,9 @@ public static void ensureInitializationComplete(@NonNull Context applicationCont
return;
}
try {
sResourceExtractor.waitForCompletion();
if (sResourceExtractor != null) {
sResourceExtractor.waitForCompletion();
}

List<String> shellArgs = new ArrayList<>();
shellArgs.add("--icu-symbol-prefix=_binary_icudtl_dat");
Expand Down Expand Up @@ -258,23 +260,28 @@ private static void initResources(@NonNull Context applicationContext) {
new ResourceCleaner(applicationContext).start();

final String dataDirPath = PathUtils.getDataDirectory(applicationContext);
final String packageName = applicationContext.getPackageName();
final PackageManager packageManager = applicationContext.getPackageManager();
final AssetManager assetManager = applicationContext.getResources().getAssets();
sResourceExtractor = new ResourceExtractor(dataDirPath, packageName, packageManager, assetManager);

// In debug/JIT mode these assets will be written to disk and then
// mapped into memory so they can be provided to the Dart VM.
// AOT modes obtain compiled Dart assets from a ELF library that does
// not need to be extracted out of the APK.

if (BuildConfig.DEBUG) {
sResourceExtractor
.addResource(fromFlutterAssets(sVmSnapshotData))
.addResource(fromFlutterAssets(sIsolateSnapshotData))
.addResource(fromFlutterAssets(DEFAULT_KERNEL_BLOB));
final String packageName = applicationContext.getPackageName();
final PackageManager packageManager = applicationContext.getPackageManager();
final AssetManager assetManager = applicationContext.getResources().getAssets();
sResourceExtractor = new ResourceExtractor(dataDirPath, packageName, packageManager, assetManager);

// In debug/JIT mode these assets will be written to disk and then
// mapped into memory so they can be provided to the Dart VM.
sResourceExtractor
.addResource(fromFlutterAssets(sVmSnapshotData))
.addResource(fromFlutterAssets(sIsolateSnapshotData))
.addResource(fromFlutterAssets(DEFAULT_KERNEL_BLOB));

sResourceExtractor.start();
} else {
// AOT modes obtain compiled Dart assets from a ELF library that does
// not need to be extracted out of the APK.
// Create an empty directory that can be passed as the bundle path
// in the engine RunBundle API.
new File(dataDirPath, sFlutterAssetsDir).mkdirs();
}

sResourceExtractor.start();
}

@Nullable
Expand Down

0 comments on commit 209250d

Please sign in to comment.