From 0b419727e7d2d77ff51ea2d4e0fa41e4740068d0 Mon Sep 17 00:00:00 2001 From: Jason Simmons Date: Tue, 19 Jun 2018 14:34:13 -0700 Subject: [PATCH] Load the ICU data file asset from the "flutter_shared" path (flutter/engine#5567) See https://github.com/flutter/flutter/issues/18514 --- DEPS | 2 +- .../android/io/flutter/view/FlutterMain.java | 37 ++++++++++++------- 2 files changed, 25 insertions(+), 14 deletions(-) diff --git a/DEPS b/DEPS index 5410e2b068..deb65f2dfd 100644 --- a/DEPS +++ b/DEPS @@ -114,7 +114,7 @@ allowed_hosts = [ ] deps = { - 'src': 'https://github.com/flutter/buildroot.git' + '@' + '71c24e682181d0b6a7e3974e5a678678650f4da3', + 'src': 'https://github.com/flutter/buildroot.git' + '@' + '457c1f45560b35072fb13c1bbf2bbe96fd077474', # Fuchsia compatibility # 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 445af70a09..876617bdc5 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 @@ -71,17 +71,14 @@ public class FlutterMain { private static final String DEFAULT_PLATFORM_DILL = "platform.dill"; private static final String DEFAULT_FLUTTER_ASSETS_DIR = "flutter_assets"; - private static final String MANIFEST = "flutter.yaml"; + // Assets that are shared among all Flutter apps within an APK. + private static final String SHARED_ASSET_DIR = "flutter_shared"; + private static final String SHARED_ASSET_ICU_DATA = "icudtl.dat"; private static String fromFlutterAssets(String filePath) { return sFlutterAssetsDir + File.separator + filePath; } - private static final Set SKY_RESOURCES = ImmutableSetBuilder.newInstance() - .add("icudtl.dat") - .add(MANIFEST) - .build(); - // Mutable because default values can be overridden via config properties private static String sAotSharedLibraryPath = DEFAULT_AOT_SHARED_LIBRARY_PATH; private static String sAotVmSnapshotData = DEFAULT_AOT_VM_SNAPSHOT_DATA; @@ -97,6 +94,7 @@ public class FlutterMain { private static boolean sIsPrecompiledAsBlobs; private static boolean sIsPrecompiledAsSharedLibrary; private static Settings sSettings; + private static String sIcuDataPath; private static final class ImmutableSetBuilder { static ImmutableSetBuilder newInstance() { @@ -196,8 +194,7 @@ public class FlutterMain { sResourceExtractor.waitForCompletion(); List shellArgs = new ArrayList<>(); - shellArgs.add("--icu-data-file-path=" + - new File(PathUtils.getDataDirectory(applicationContext), "icudtl.dat")); + shellArgs.add("--icu-data-file-path=" + sIcuDataPath); if (args != null) { Collections.addAll(shellArgs, args); } @@ -265,8 +262,22 @@ public class FlutterMain { private static void initResources(Context applicationContext) { Context context = applicationContext; new ResourceCleaner(context).start(); - sResourceExtractor = new ResourceExtractor(context) - .addResources(SKY_RESOURCES) + + sResourceExtractor = new ResourceExtractor(context); + + // Search for the icudtl.dat file at the old and new locations. + // TODO(jsimmons): remove the old location when all tools have been updated. + Set sharedAssets = listAssets(applicationContext, SHARED_ASSET_DIR); + String icuAssetPath; + if (sharedAssets.contains(SHARED_ASSET_ICU_DATA)) { + icuAssetPath = SHARED_ASSET_DIR + File.separator + SHARED_ASSET_ICU_DATA; + } else { + icuAssetPath = SHARED_ASSET_ICU_DATA; + } + sResourceExtractor.addResource(icuAssetPath); + sIcuDataPath = PathUtils.getDataDirectory(applicationContext) + File.separator + icuAssetPath; + + sResourceExtractor .addResource(fromFlutterAssets(sFlx)) .addResource(fromFlutterAssets(sSnapshotBlob)) .addResource(fromFlutterAssets(sAotVmSnapshotData)) @@ -293,11 +304,11 @@ public class FlutterMain { * Returns a list of the file names at the root of the application's asset * path. */ - private static Set listRootAssets(Context applicationContext) { + private static Set listAssets(Context applicationContext, String path) { AssetManager manager = applicationContext.getResources().getAssets(); try { return ImmutableSetBuilder.newInstance() - .add(manager.list("")) + .add(manager.list(path)) .build(); } catch (IOException e) { Log.e(TAG, "Unable to list assets", e); @@ -306,7 +317,7 @@ public class FlutterMain { } private static void initAot(Context applicationContext) { - Set assets = listRootAssets(applicationContext); + Set assets = listAssets(applicationContext, ""); sIsPrecompiledAsBlobs = assets.containsAll(Arrays.asList( sAotVmSnapshotData, sAotVmSnapshotInstr,