From aea6b625e768394f315be4f103cb1d36c0ed9aa7 Mon Sep 17 00:00:00 2001 From: Eric Seidel Date: Tue, 28 Mar 2023 12:25:17 -0700 Subject: [PATCH] Teach our fork of the engine to build on Android arm32 (#5) This required conditionally linking against separate builds of libupdater.a as well as providing a stub for getauxval. If we find a way to move off of using ring (via rust-tls, via reqwests) we could get rid of this. More likely Flutter will just move to a newer version of SDK/NDK: https://github.com/flutter/flutter/issues/82000 --- shell/platform/android/BUILD.gn | 6 +++++- shell/platform/android/flutter_main.cc | 16 ++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/shell/platform/android/BUILD.gn b/shell/platform/android/BUILD.gn index 05d95b6ad2259..284201ec10328 100644 --- a/shell/platform/android/BUILD.gn +++ b/shell/platform/android/BUILD.gn @@ -140,8 +140,12 @@ source_set("flutter_shell_native_src") { "android", "EGL", "GLESv2", - "//flutter/updater/android_aarch64/libupdater.a", ] + if (target_cpu == "arm") { + libs += [ "//flutter/updater/android_arm/libupdater.a" ] + } else if (target_cpu == "arm64") { + libs += [ "//flutter/updater/android_aarch64/libupdater.a" ] + } } action("gen_android_build_config_java") { diff --git a/shell/platform/android/flutter_main.cc b/shell/platform/android/flutter_main.cc index c30ba4cf48f86..82f8729b30270 100644 --- a/shell/platform/android/flutter_main.cc +++ b/shell/platform/android/flutter_main.cc @@ -77,6 +77,22 @@ const flutter::Settings& FlutterMain::GetSettings() const { return settings_; } +// Old Android versions (e.g. the v16 ndk Flutter uses) don't always include a +// getauxval symbol, but the Rust ring crate assumes it exists: +// https://github.com/briansmith/ring/blob/fa25bf3a7403c9fe6458cb87bd8427be41225ca2/src/cpu/arm.rs#L22 +// It uses it to determine if the CPU supports AES instructions. +// Making this a weak symbol allows the linker to use a real version instead +// if it can find one. +// BoringSSL just reads from procfs instead, which is what we would do if +// we needed to implement this ourselves. Implementation looks straightforward: +// https://lwn.net/Articles/519085/ +// https://github.com/google/boringssl/blob/6ab4f0ae7f2db96d240eb61a5a8b4724e5a09b2f/crypto/cpu_arm_linux.c +#if defined(__ANDROID__) && defined(__arm__) +extern "C" __attribute__((weak)) unsigned long getauxval(unsigned long type) { + return 0; +} +#endif + // TODO: Move this out into a separate file? void ConfigureShorebird(std::string android_cache_path, flutter::Settings& settings,