Load the ICU data file asset from the "flutter_shared" path (flutter/engine#5567)

See https://github.com/flutter/flutter/issues/18514
This commit is contained in:
Jason Simmons
2018-06-19 14:34:13 -07:00
committed by GitHub
parent e8df7055bc
commit 0b419727e7
2 changed files with 25 additions and 14 deletions

2
DEPS
View File

@@ -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
#

View File

@@ -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<String> SKY_RESOURCES = ImmutableSetBuilder.<String>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<T> {
static <T> ImmutableSetBuilder<T> newInstance() {
@@ -196,8 +194,7 @@ public class FlutterMain {
sResourceExtractor.waitForCompletion();
List<String> 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<String> 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<String> listRootAssets(Context applicationContext) {
private static Set<String> listAssets(Context applicationContext, String path) {
AssetManager manager = applicationContext.getResources().getAssets();
try {
return ImmutableSetBuilder.<String>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<String> assets = listRootAssets(applicationContext);
Set<String> assets = listAssets(applicationContext, "");
sIsPrecompiledAsBlobs = assets.containsAll(Arrays.asList(
sAotVmSnapshotData,
sAotVmSnapshotInstr,