diff --git a/runtime/BUILD.gn b/runtime/BUILD.gn index 73288f20911..259f873cd5b 100644 --- a/runtime/BUILD.gn +++ b/runtime/BUILD.gn @@ -104,6 +104,14 @@ 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. @@ -127,6 +135,7 @@ executable("runtime_unittests") { ":runtime", ":runtime_fixtures", "$flutter_root/fml", + "$flutter_root/lib/snapshot", "$flutter_root/testing", "//garnet/public/lib/fxl", "//third_party/dart/runtime:libdart_jit", diff --git a/shell/platform/android/io/flutter/view/FlutterMain.java b/shell/platform/android/io/flutter/view/FlutterMain.java index 445af70a090..54d34294d41 100644 --- a/shell/platform/android/io/flutter/view/FlutterMain.java +++ b/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 sIsPrecompiledAsBlobs; + private static boolean sIsPrecompiled; private static boolean sIsPrecompiledAsSharedLibrary; private static Settings sSettings; @@ -201,24 +201,19 @@ public class FlutterMain { if (args != null) { Collections.addAll(shellArgs, args); } - 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); - } + if (sIsPrecompiled) { + shellArgs.add("--" + AOT_SNAPSHOT_PATH_KEY + "=" + + PathUtils.getDataDirectory(applicationContext)); 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) { @@ -269,10 +264,6 @@ 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) { @@ -307,21 +298,21 @@ public class FlutterMain { private static void initAot(Context applicationContext) { Set assets = listRootAssets(applicationContext); - sIsPrecompiledAsBlobs = assets.containsAll(Arrays.asList( + sIsPrecompiled = assets.containsAll(Arrays.asList( sAotVmSnapshotData, sAotVmSnapshotInstr, sAotIsolateSnapshotData, sAotIsolateSnapshotInstr )); sIsPrecompiledAsSharedLibrary = assets.contains(sAotSharedLibraryPath); - if (sIsPrecompiledAsBlobs && sIsPrecompiledAsSharedLibrary) { + if (sIsPrecompiled && sIsPrecompiledAsSharedLibrary) { throw new RuntimeException( "Found precompiled app as shared library and as Dart VM snapshots."); } } public static boolean isRunningPrecompiledCode() { - return sIsPrecompiledAsBlobs || sIsPrecompiledAsSharedLibrary; + return sIsPrecompiled || sIsPrecompiledAsSharedLibrary; } public static String findAppBundlePath(Context applicationContext) { diff --git a/shell/testing/BUILD.gn b/shell/testing/BUILD.gn index 6c99a3466d9..e0384da2185 100644 --- a/shell/testing/BUILD.gn +++ b/shell/testing/BUILD.gn @@ -17,7 +17,6 @@ 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",