From 06e3b9c5b81253d89cb6c6c8bd34b0ce7a781a14 Mon Sep 17 00:00:00 2001 From: Jason Simmons Date: Wed, 12 Jun 2019 17:34:02 -0700 Subject: [PATCH] When running in AOT modes create a flutter_assets directory that can be used as the bundle path (#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 https://github.com/flutter/flutter/issues/34287 --- .../android/io/flutter/view/FlutterMain.java | 39 +++++++++++-------- 1 file changed, 23 insertions(+), 16 deletions(-) diff --git a/shell/platform/android/io/flutter/view/FlutterMain.java b/shell/platform/android/io/flutter/view/FlutterMain.java index 01c4aca79104a..c4c4af240150f 100644 --- a/shell/platform/android/io/flutter/view/FlutterMain.java +++ b/shell/platform/android/io/flutter/view/FlutterMain.java @@ -143,7 +143,9 @@ public static void ensureInitializationComplete(@NonNull Context applicationCont return; } try { - sResourceExtractor.waitForCompletion(); + if (sResourceExtractor != null) { + sResourceExtractor.waitForCompletion(); + } List shellArgs = new ArrayList<>(); shellArgs.add("--icu-symbol-prefix=_binary_icudtl_dat"); @@ -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