From 8e2bc7b70e4e3111707a8a3568aadcb22ebd218a Mon Sep 17 00:00:00 2001 From: Ryan Macnak Date: Wed, 23 May 2018 17:09:51 -0700 Subject: [PATCH] Reapply "Don't link the core snapshot in the Android engine." (flutter/engine#5353) Add back the core snapshot to runtime_unittests and embedder_unittests. --- engine/src/flutter/runtime/BUILD.gn | 8 ----- .../android/io/flutter/view/FlutterMain.java | 35 ++++++++++++------- .../flutter/shell/platform/embedder/BUILD.gn | 1 + engine/src/flutter/shell/testing/BUILD.gn | 1 + 4 files changed, 24 insertions(+), 21 deletions(-) diff --git a/engine/src/flutter/runtime/BUILD.gn b/engine/src/flutter/runtime/BUILD.gn index 259f873cd5b..421bf3548f4 100644 --- a/engine/src/flutter/runtime/BUILD.gn +++ b/engine/src/flutter/runtime/BUILD.gn @@ -104,14 +104,6 @@ source_set("runtime") { public_configs = [ "$flutter_root:config" ] - # In AOT mode, precompiled snapshots contain the instruction buffer. - # Generation of the same requires all application specific script code to be - # specified up front. In such cases, there can be no generic snapshot. - # In Fuchsia, we load from a file instead of linking. - if (!flutter_aot && !is_fuchsia) { - deps += [ "$flutter_root/lib/snapshot" ] - } - if (flutter_runtime_mode != "release" && !is_fuchsia) { # Only link in Observatory in non-release modes on non-Fuchsia. Fuchsia # instead puts Observatory into the runner's package. diff --git a/engine/src/flutter/shell/platform/android/io/flutter/view/FlutterMain.java b/engine/src/flutter/shell/platform/android/io/flutter/view/FlutterMain.java index 54d34294d41..445af70a090 100644 --- a/engine/src/flutter/shell/platform/android/io/flutter/view/FlutterMain.java +++ b/engine/src/flutter/shell/platform/android/io/flutter/view/FlutterMain.java @@ -94,7 +94,7 @@ public class FlutterMain { private static boolean sInitialized = false; private static ResourceExtractor sResourceExtractor; - private static boolean sIsPrecompiled; + private static boolean sIsPrecompiledAsBlobs; private static boolean sIsPrecompiledAsSharedLibrary; private static Settings sSettings; @@ -201,19 +201,24 @@ public class FlutterMain { if (args != null) { Collections.addAll(shellArgs, args); } - if (sIsPrecompiled) { - shellArgs.add("--" + AOT_SNAPSHOT_PATH_KEY + "=" + - PathUtils.getDataDirectory(applicationContext)); + if (sIsPrecompiledAsSharedLibrary) { + shellArgs.add("--" + AOT_SHARED_LIBRARY_PATH + "=" + + new File(PathUtils.getDataDirectory(applicationContext), sAotSharedLibraryPath)); + } else { + if (sIsPrecompiledAsBlobs) { + shellArgs.add("--" + AOT_SNAPSHOT_PATH_KEY + "=" + + PathUtils.getDataDirectory(applicationContext)); + } else { + shellArgs.add("--cache-dir-path=" + + PathUtils.getCacheDirectory(applicationContext)); + + shellArgs.add("--" + AOT_SNAPSHOT_PATH_KEY + "=" + + PathUtils.getDataDirectory(applicationContext) + "/" + sFlutterAssetsDir); + } shellArgs.add("--" + AOT_VM_SNAPSHOT_DATA_KEY + "=" + sAotVmSnapshotData); shellArgs.add("--" + AOT_VM_SNAPSHOT_INSTR_KEY + "=" + sAotVmSnapshotInstr); shellArgs.add("--" + AOT_ISOLATE_SNAPSHOT_DATA_KEY + "=" + sAotIsolateSnapshotData); shellArgs.add("--" + AOT_ISOLATE_SNAPSHOT_INSTR_KEY + "=" + sAotIsolateSnapshotInstr); - } else if (sIsPrecompiledAsSharedLibrary) { - shellArgs.add("--" + AOT_SHARED_LIBRARY_PATH + "=" + - new File(PathUtils.getDataDirectory(applicationContext), sAotSharedLibraryPath)); - } else { - shellArgs.add("--cache-dir-path=" + - PathUtils.getCacheDirectory(applicationContext)); } if (sSettings.getLogTag() != null) { @@ -264,6 +269,10 @@ public class FlutterMain { .addResources(SKY_RESOURCES) .addResource(fromFlutterAssets(sFlx)) .addResource(fromFlutterAssets(sSnapshotBlob)) + .addResource(fromFlutterAssets(sAotVmSnapshotData)) + .addResource(fromFlutterAssets(sAotVmSnapshotInstr)) + .addResource(fromFlutterAssets(sAotIsolateSnapshotData)) + .addResource(fromFlutterAssets(sAotIsolateSnapshotInstr)) .addResource(fromFlutterAssets(DEFAULT_KERNEL_BLOB)) .addResource(fromFlutterAssets(DEFAULT_PLATFORM_DILL)); if (sIsPrecompiledAsSharedLibrary) { @@ -298,21 +307,21 @@ public class FlutterMain { private static void initAot(Context applicationContext) { Set assets = listRootAssets(applicationContext); - sIsPrecompiled = assets.containsAll(Arrays.asList( + sIsPrecompiledAsBlobs = assets.containsAll(Arrays.asList( sAotVmSnapshotData, sAotVmSnapshotInstr, sAotIsolateSnapshotData, sAotIsolateSnapshotInstr )); sIsPrecompiledAsSharedLibrary = assets.contains(sAotSharedLibraryPath); - if (sIsPrecompiled && sIsPrecompiledAsSharedLibrary) { + if (sIsPrecompiledAsBlobs && sIsPrecompiledAsSharedLibrary) { throw new RuntimeException( "Found precompiled app as shared library and as Dart VM snapshots."); } } public static boolean isRunningPrecompiledCode() { - return sIsPrecompiled || sIsPrecompiledAsSharedLibrary; + return sIsPrecompiledAsBlobs || sIsPrecompiledAsSharedLibrary; } public static String findAppBundlePath(Context applicationContext) { diff --git a/engine/src/flutter/shell/platform/embedder/BUILD.gn b/engine/src/flutter/shell/platform/embedder/BUILD.gn index 5e04cfcd47a..777dd5b869d 100644 --- a/engine/src/flutter/shell/platform/embedder/BUILD.gn +++ b/engine/src/flutter/shell/platform/embedder/BUILD.gn @@ -48,6 +48,7 @@ executable("embedder_unittests") { deps = [ ":embedder", ":fixtures", + "$flutter_root/lib/snapshot", "$flutter_root/testing", ] diff --git a/engine/src/flutter/shell/testing/BUILD.gn b/engine/src/flutter/shell/testing/BUILD.gn index e0384da2185..6c99a3466d9 100644 --- a/engine/src/flutter/shell/testing/BUILD.gn +++ b/engine/src/flutter/shell/testing/BUILD.gn @@ -17,6 +17,7 @@ executable("testing") { "$flutter_root/assets", "$flutter_root/common", "$flutter_root/fml", + "$flutter_root/lib/snapshot", "$flutter_root/shell/common", "//garnet/public/lib/fxl", "//third_party/dart/runtime:libdart_jit",