Skip to content

Commit

Permalink
Don't link the core snapshot in the Android engine. (flutter#5348)
Browse files Browse the repository at this point in the history
Allows one to use a different core snapshot without a custom engine build by just packaging a different one in the APK.
  • Loading branch information
rmacnak-google authored May 23, 2018
1 parent 84c2b5a commit e0d4c46
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 22 deletions.
9 changes: 0 additions & 9 deletions runtime/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -135,7 +127,6 @@ 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",
Expand Down
35 changes: 22 additions & 13 deletions shell/platform/android/io/flutter/view/FlutterMain.java
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ private static String fromFlutterAssets(String filePath) {

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;

Expand Down Expand Up @@ -201,19 +201,24 @@ public static void ensureInitializationComplete(Context applicationContext, Stri
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) {
Expand Down Expand Up @@ -264,6 +269,10 @@ private static void initResources(Context applicationContext) {
.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) {
Expand Down Expand Up @@ -298,21 +307,21 @@ private static Set<String> listRootAssets(Context applicationContext) {

private static void initAot(Context applicationContext) {
Set<String> 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) {
Expand Down
1 change: 1 addition & 0 deletions shell/testing/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit e0d4c46

Please sign in to comment.