diff --git a/shell/common/switches.cc b/shell/common/switches.cc index 0ef45a944a644..997cd846ec613 100644 --- a/shell/common/switches.cc +++ b/shell/common/switches.cc @@ -123,13 +123,29 @@ static bool GetSwitchValue(const fml::CommandLine& command_line, return false; } -std::unique_ptr GetSymbolMapping(std::string symbol_prefix) { - fml::RefPtr proc_library = +std::unique_ptr GetSymbolMapping(std::string symbol_prefix, + std::string native_lib_path) { + const uint8_t* mapping; + intptr_t size; + + auto lookup_symbol = [&mapping, &size, symbol_prefix]( + const fml::RefPtr& library) { + mapping = library->ResolveSymbol((symbol_prefix + "_start").c_str()); + size = reinterpret_cast( + library->ResolveSymbol((symbol_prefix + "_size").c_str())); + }; + + fml::RefPtr library = fml::NativeLibrary::CreateForCurrentProcess(); - const uint8_t* mapping = - proc_library->ResolveSymbol((symbol_prefix + "_start").c_str()); - const intptr_t size = reinterpret_cast( - proc_library->ResolveSymbol((symbol_prefix + "_size").c_str())); + lookup_symbol(library); + + if (!(mapping && size)) { + // Symbol lookup for the current process fails on some devices. As a + // fallback, try doing the lookup based on the path to the Flutter library. + library = fml::NativeLibrary::Create(native_lib_path.c_str()); + lookup_symbol(library); + } + FML_CHECK(mapping && size) << "Unable to resolve symbols: " << symbol_prefix; return std::make_unique(mapping, size); } @@ -228,11 +244,13 @@ blink::Settings SettingsFromCommandLine(const fml::CommandLine& command_line) { command_line.GetOptionValue(FlagForSwitch(Switch::ICUDataFilePath), &settings.icu_data_path); if (command_line.HasOption(FlagForSwitch(Switch::ICUSymbolPrefix))) { - std::string icu_symbol_prefix; + std::string icu_symbol_prefix, native_lib_path; command_line.GetOptionValue(FlagForSwitch(Switch::ICUSymbolPrefix), &icu_symbol_prefix); - settings.icu_mapper = [icu_symbol_prefix] { - return GetSymbolMapping(icu_symbol_prefix); + command_line.GetOptionValue(FlagForSwitch(Switch::ICUNativeLibPath), + &native_lib_path); + settings.icu_mapper = [icu_symbol_prefix, native_lib_path] { + return GetSymbolMapping(icu_symbol_prefix, native_lib_path); }; } } diff --git a/shell/common/switches.h b/shell/common/switches.h index c20589dea6226..a5da872d6d1c9 100644 --- a/shell/common/switches.h +++ b/shell/common/switches.h @@ -52,6 +52,9 @@ DEF_SWITCH(ICUSymbolPrefix, "icu-symbol-prefix", "Prefix for the symbols representing ICU data linked into the " "Flutter library.") +DEF_SWITCH(ICUNativeLibPath, + "icu-native-lib-path", + "Path to the library file that exports the ICU data.") DEF_SWITCH(DartFlags, "dart-flags", "Flags passed directly to the Dart VM without being interpreted " diff --git a/shell/platform/android/io/flutter/view/FlutterMain.java b/shell/platform/android/io/flutter/view/FlutterMain.java index ae712708573cc..c632dca387ced 100644 --- a/shell/platform/android/io/flutter/view/FlutterMain.java +++ b/shell/platform/android/io/flutter/view/FlutterMain.java @@ -6,6 +6,7 @@ import android.content.Context; import android.content.Intent; +import android.content.pm.ApplicationInfo; import android.content.pm.PackageManager; import android.content.res.AssetManager; import android.app.AlarmManager; @@ -195,7 +196,12 @@ public static void ensureInitializationComplete(Context applicationContext, Stri sResourceExtractor.waitForCompletion(); List shellArgs = new ArrayList<>(); + shellArgs.add("--icu-symbol-prefix=_binary_icudtl_dat"); + ApplicationInfo applicationInfo = applicationContext.getPackageManager().getApplicationInfo( + applicationContext.getPackageName(), PackageManager.GET_META_DATA); + shellArgs.add("--icu-native-lib-path=" + applicationInfo.nativeLibraryDir + File.separator + DEFAULT_LIBRARY); + if (args != null) { Collections.addAll(shellArgs, args); }