From 0b0cff3c61610fb56f8c5c9451ace01598117a8d Mon Sep 17 00:00:00 2001 From: Igor Cota Date: Tue, 28 May 2019 03:12:59 +0200 Subject: [PATCH 01/13] Add support for building Android dependencies --- depends/Makefile | 5 +++++ depends/hosts/android.mk | 3 +++ depends/packages/openssl.mk | 1 + 3 files changed, 9 insertions(+) create mode 100644 depends/hosts/android.mk diff --git a/depends/Makefile b/depends/Makefile index b7e9a9213ed..6643b664f37 100644 --- a/depends/Makefile +++ b/depends/Makefile @@ -55,6 +55,11 @@ full_host_os:=$(subst $(host_arch)-$(host_vendor)-,,$(canonical_host)) host_os:=$(findstring linux,$(full_host_os)) host_os+=$(findstring darwin,$(full_host_os)) host_os+=$(findstring mingw32,$(full_host_os)) + +ifeq (android,$(findstring android,$(full_host_os))) +host_os:=android +endif + host_os:=$(strip $(host_os)) ifeq ($(host_os),) host_os=$(full_host_os) diff --git a/depends/hosts/android.mk b/depends/hosts/android.mk new file mode 100644 index 00000000000..ff1b07d55ba --- /dev/null +++ b/depends/hosts/android.mk @@ -0,0 +1,3 @@ +android_AR=$(ANDROID_TOOLCHAIN_BIN)/$(HOST)-ar +android_CXX=$(ANDROID_TOOLCHAIN_BIN)/$(HOST)$(ANDROID_API_LEVEL)-clang++ +android_CC=$(ANDROID_TOOLCHAIN_BIN)/$(HOST)$(ANDROID_API_LEVEL)-clang diff --git a/depends/packages/openssl.mk b/depends/packages/openssl.mk index db47113b2f9..6a316a308e0 100644 --- a/depends/packages/openssl.mk +++ b/depends/packages/openssl.mk @@ -57,6 +57,7 @@ $(package)_config_opts_riscv64_linux=linux-generic64 $(package)_config_opts_x86_64_darwin=darwin64-x86_64-cc $(package)_config_opts_x86_64_mingw32=mingw64 $(package)_config_opts_i686_mingw32=mingw +$(package)_config_opts_android=linux-generic64 endef define $(package)_preprocess_cmds From c2a749c9c16697e744ecfb283fdf4095d0278066 Mon Sep 17 00:00:00 2001 From: Igor Cota Date: Tue, 28 May 2019 03:28:01 +0200 Subject: [PATCH 02/13] Add example Android host-platform-triplet and options --- depends/README.md | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/depends/README.md b/depends/README.md index cfb9bbfeb0d..a2fb592f344 100644 --- a/depends/README.md +++ b/depends/README.md @@ -30,8 +30,12 @@ Common `host-platform-triplets` for cross compilation are: - `aarch64-linux-gnu` for Linux ARM 64 bit - `riscv32-linux-gnu` for Linux RISC-V 32 bit - `riscv64-linux-gnu` for Linux RISC-V 64 bit +- `aarch64-linux-android` for Android ARM 64 bit -No other options are needed, the paths are automatically configured. +The paths are automatically configured and no other options are needed unless targeting Android. +In that case one needs to set `ANDROID_API_LEVEL` and `ANDROID_TOOLCHAIN_BIN`: + + make HOST=aarch64-linux-android ANDROID_API_LEVEL=28 ANDROID_TOOLCHAIN_BIN=/home/user/Android/Sdk/ndk-bundle/toolchains/llvm/prebuilt/linux-x86_64/bin NO_QT=1 NO_WALLET=1 ### Install the required dependencies: Ubuntu & Debian From 9c4cb0166e801471f8cb3d82656c86bacf051db6 Mon Sep 17 00:00:00 2001 From: Igor Cota Date: Wed, 10 Jul 2019 13:56:00 +0200 Subject: [PATCH 03/13] Add ranlib to android.mk hosts file (fix OSX Android NDK build) --- depends/hosts/android.mk | 1 + 1 file changed, 1 insertion(+) diff --git a/depends/hosts/android.mk b/depends/hosts/android.mk index ff1b07d55ba..c2a30d7a4d6 100644 --- a/depends/hosts/android.mk +++ b/depends/hosts/android.mk @@ -1,3 +1,4 @@ android_AR=$(ANDROID_TOOLCHAIN_BIN)/$(HOST)-ar android_CXX=$(ANDROID_TOOLCHAIN_BIN)/$(HOST)$(ANDROID_API_LEVEL)-clang++ android_CC=$(ANDROID_TOOLCHAIN_BIN)/$(HOST)$(ANDROID_API_LEVEL)-clang +android_RANLIB=$(ANDROID_TOOLCHAIN_BIN)/$(HOST)-ranlib From b68f2a68c211aa2264e9ca824d10a90f4a5a5af4 Mon Sep 17 00:00:00 2001 From: Igor Cota Date: Mon, 16 Sep 2019 13:34:14 +0200 Subject: [PATCH 04/13] Add config opts and patch for aarch64_android build of Qt --- depends/packages/packages.mk | 1 + depends/packages/qt.mk | 18 ++++++++++++++++- .../patches/qt/fix_android_qmake_conf.patch | 20 +++++++++++++++++++ 3 files changed, 38 insertions(+), 1 deletion(-) create mode 100644 depends/patches/qt/fix_android_qmake_conf.patch diff --git a/depends/packages/packages.mk b/depends/packages/packages.mk index 667fde5271a..61b4b53ab33 100644 --- a/depends/packages/packages.mk +++ b/depends/packages/packages.mk @@ -6,6 +6,7 @@ protobuf_packages = protobuf qt_packages = qrencode zlib qt_linux_packages:=qt expat libxcb xcb_proto libXau xproto freetype fontconfig +qt_android_packages=qt rapidcheck_packages = rapidcheck diff --git a/depends/packages/qt.mk b/depends/packages/qt.mk index 56045ade504..ff80eb26488 100644 --- a/depends/packages/qt.mk +++ b/depends/packages/qt.mk @@ -8,7 +8,7 @@ $(package)_dependencies=openssl zlib $(package)_linux_dependencies=freetype fontconfig libxcb $(package)_build_subdir=qtbase $(package)_qt_libs=corelib network widgets gui plugins testlib -$(package)_patches=fix_qt_pkgconfig.patch mac-qmake.conf fix_configure_mac.patch fix_no_printer.patch fix_rcc_determinism.patch fix_riscv64_arch.patch xkb-default.patch no-xlib.patch +$(package)_patches=fix_qt_pkgconfig.patch mac-qmake.conf fix_configure_mac.patch fix_no_printer.patch fix_rcc_determinism.patch fix_riscv64_arch.patch xkb-default.patch no-xlib.patch fix_android_qmake_conf.patch $(package)_qttranslations_file_name=qttranslations-$($(package)_suffix) $(package)_qttranslations_sha256_hash=fb5a47799754af73d3bf501fe513342cfe2fc37f64e80df5533f6110e804220c @@ -19,6 +19,8 @@ $(package)_qttools_sha256_hash=a97556eb7b2f30252cdd8a598c396cfce2b2f79d2bae883af $(package)_extra_sources = $($(package)_qttranslations_file_name) $(package)_extra_sources += $($(package)_qttools_file_name) +$(package)_config_opts_aarch64_android = -xplatform android-clang -android-sdk $(ANDROID_SDK) -android-ndk $(ANDROID_NDK) -android-ndk-platform android-$(ANDROID_API_LEVEL) -device-option CROSS_COMPILE="$(host)-" -egl -qpa xcb -no-eglfs -opengl es2 -qt-freetype -no-fontconfig -L $(host_prefix)/lib -I $(host_prefix)/include + define $(package)_set_vars $(package)_config_opts_release = -release $(package)_config_opts_debug = -debug @@ -127,6 +129,19 @@ $(package)_config_opts_x86_64_linux = -xplatform linux-g++-64 $(package)_config_opts_aarch64_linux = -xplatform linux-aarch64-gnu-g++ $(package)_config_opts_riscv64_linux = -platform linux-g++ -xplatform bitcoin-linux-g++ $(package)_config_opts_mingw32 = -no-opengl -xplatform win32-g++ -device-option CROSS_COMPILE="$(host)-" +$(package)_config_opts_aarch64_android = -xplatform android-clang +$(package)_config_opts_aarch64_android += -android-sdk $(ANDROID_SDK) +$(package)_config_opts_aarch64_android += -android-ndk $(ANDROID_NDK) +$(package)_config_opts_aarch64_android += -android-ndk-platform android-$(ANDROID_API_LEVEL) +$(package)_config_opts_aarch64_android += -device-option CROSS_COMPILE="$(host)-" +$(package)_config_opts_aarch64_android += -egl +$(package)_config_opts_aarch64_android += -qpa xcb +$(package)_config_opts_aarch64_android += -no-eglfs +$(package)_config_opts_aarch64_android += -opengl es2 +$(package)_config_opts_aarch64_android += -qt-freetype +$(package)_config_opts_aarch64_android += -no-fontconfig +$(package)_config_opts_aarch64_android += -L $(host_prefix)/lib +$(package)_config_opts_aarch64_android += -I $(host_prefix)/include $(package)_build_env = QT_RCC_TEST=1 $(package)_build_env += QT_RCC_SOURCE_DATE_OVERRIDE=1 endef @@ -169,6 +184,7 @@ define $(package)_preprocess_cmds patch -p1 -i $($(package)_patch_dir)/fix_no_printer.patch &&\ patch -p1 -i $($(package)_patch_dir)/fix_rcc_determinism.patch &&\ patch -p1 -i $($(package)_patch_dir)/xkb-default.patch &&\ + patch -p1 -i $($(package)_patch_dir)/fix_android_qmake_conf.patch &&\ echo "!host_build: QMAKE_CFLAGS += $($(package)_cflags) $($(package)_cppflags)" >> qtbase/mkspecs/common/gcc-base.conf && \ echo "!host_build: QMAKE_CXXFLAGS += $($(package)_cxxflags) $($(package)_cppflags)" >> qtbase/mkspecs/common/gcc-base.conf && \ echo "!host_build: QMAKE_LFLAGS += $($(package)_ldflags)" >> qtbase/mkspecs/common/gcc-base.conf && \ diff --git a/depends/patches/qt/fix_android_qmake_conf.patch b/depends/patches/qt/fix_android_qmake_conf.patch new file mode 100644 index 00000000000..13bfff97764 --- /dev/null +++ b/depends/patches/qt/fix_android_qmake_conf.patch @@ -0,0 +1,20 @@ +--- old/qtbase/mkspecs/android-clang/qmake.conf ++++ new/qtbase/mkspecs/android-clang/qmake.conf +@@ -30,7 +30,7 @@ + QMAKE_CFLAGS += -target mips64el-none-linux-android + + QMAKE_CFLAGS += -gcc-toolchain $$NDK_TOOLCHAIN_PATH +-QMAKE_LINK = $$QMAKE_CXX $$QMAKE_CFLAGS -Wl,--exclude-libs,libgcc.a ++QMAKE_LINK = $$QMAKE_CXX $$QMAKE_CFLAGS -Wl,--exclude-libs,libgcc.a -nostdlib++ + QMAKE_CFLAGS += -DANDROID_HAS_WSTRING --sysroot=$$NDK_ROOT/sysroot \ + -isystem $$NDK_ROOT/sysroot/usr/include/$$NDK_TOOLS_PREFIX \ + -isystem $$NDK_ROOT/sources/cxx-stl/llvm-libc++/include \ +@@ -40,7 +40,7 @@ + ANDROID_SOURCES_CXX_STL_LIBDIR = $$NDK_ROOT/sources/cxx-stl/llvm-libc++/libs/$$ANDROID_TARGET_ARCH + + ANDROID_STDCPP_PATH = $$ANDROID_SOURCES_CXX_STL_LIBDIR/libc++_shared.so +-ANDROID_CXX_STL_LIBS = -lc++ ++ANDROID_CXX_STL_LIBS = -lc++_shared + + QMAKE_ARM_CFLAGS_RELEASE = -Oz + QMAKE_ARM_CFLAGS_RELEASE_WITH_DEBUGINFO = -g -Oz From 45f82190150b3feef333724ea7395ba080e700b1 Mon Sep 17 00:00:00 2001 From: Igor Cota Date: Tue, 17 Sep 2019 11:15:08 +0200 Subject: [PATCH 05/13] Add full Android build example command and instructions on getting SDK/NDK --- depends/README.md | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/depends/README.md b/depends/README.md index a2fb592f344..bf140f9c11d 100644 --- a/depends/README.md +++ b/depends/README.md @@ -33,9 +33,14 @@ Common `host-platform-triplets` for cross compilation are: - `aarch64-linux-android` for Android ARM 64 bit The paths are automatically configured and no other options are needed unless targeting Android. -In that case one needs to set `ANDROID_API_LEVEL` and `ANDROID_TOOLCHAIN_BIN`: +Before proceeding with an Android build one needs to get the [Android SDK](https://developer.android.com/studio) and use the "SDK Manager" tool to download the NDK and one or more "Platform packages" (these are Android versions and have a corresponding API level). +In order to build `ANDROID_API_LEVEL` (API level corresponding to the Android version targeted, e.g. Android 9.0 Pie is 28 and its "Platform package" needs to be available) and `ANDROID_TOOLCHAIN_BIN` (path to toolchain binaries depending on the platform the build is being performed on) need to be set. +If the build includes Qt, environment variables `ANDROID_SDK` and `ANDROID_NDK` need to be set as well but can otherwise be omitted. +This is an example command for a default build with no disabled dependencies: + + ANDROID_SDK=/home/user/Android/Sdk ANDROID_NDK=/home/user/Android/Sdk/ndk-bundle make HOST=aarch64-linux-android ANDROID_API_LEVEL=28 ANDROID_TOOLCHAIN_BIN=/home/user/Android/Sdk/ndk-bundle/toolchains/llvm/prebuilt/linux-x86_64/bin + - make HOST=aarch64-linux-android ANDROID_API_LEVEL=28 ANDROID_TOOLCHAIN_BIN=/home/user/Android/Sdk/ndk-bundle/toolchains/llvm/prebuilt/linux-x86_64/bin NO_QT=1 NO_WALLET=1 ### Install the required dependencies: Ubuntu & Debian From 80b475f159525737e242161397f35d0729449545 Mon Sep 17 00:00:00 2001 From: Igor Cota Date: Thu, 19 Sep 2019 11:43:10 +0200 Subject: [PATCH 06/13] Fix Android zlib cross compilation issue (https://stackoverflow.com/questions/21396988/zlib-build-not-configuring-properly-with-cross-compiler-ignores-ar) --- depends/packages/zlib.mk | 1 + 1 file changed, 1 insertion(+) diff --git a/depends/packages/zlib.mk b/depends/packages/zlib.mk index 168f85e65ee..017e7b2cf11 100644 --- a/depends/packages/zlib.mk +++ b/depends/packages/zlib.mk @@ -11,6 +11,7 @@ $(package)_config_opts+=RANLIB="$($(package)_ranlib)" $(package)_config_opts+=AR="$($(package)_ar)" $(package)_config_opts_darwin+=AR="$($(package)_libtool)" $(package)_config_opts_darwin+=ARFLAGS="-o" +$(package)_config_opts_aarch64_android+=CHOST=$(host) endef # zlib has its own custom configure script that takes in options like CC, From b4057d82618a21720f39f448b689cebf475cc2dc Mon Sep 17 00:00:00 2001 From: Igor Cota Date: Sun, 22 Sep 2019 14:35:41 +0200 Subject: [PATCH 07/13] Define TARGET_OS when host is android --- configure.ac | 1 + 1 file changed, 1 insertion(+) diff --git a/configure.ac b/configure.ac index 2445b72683e..78873f38594 100644 --- a/configure.ac +++ b/configure.ac @@ -590,6 +590,7 @@ case $host in ;; *android*) dnl make sure android stays above linux for hosts like *linux-android* + TARGET_OS=android LEVELDB_TARGET_FLAGS="-DOS_ANDROID" ;; *linux*) From f1e40b3e7114b18bc03f45c3a97f9f673543ddef Mon Sep 17 00:00:00 2001 From: BlockMechanic Date: Thu, 19 Sep 2019 15:09:47 +0200 Subject: [PATCH 08/13] Update bitcoin_qt.m4 Fix to allow configure to detect at --- build-aux/m4/bitcoin_qt.m4 | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/build-aux/m4/bitcoin_qt.m4 b/build-aux/m4/bitcoin_qt.m4 index 675fb6d3fb6..8a5bdd840e6 100644 --- a/build-aux/m4/bitcoin_qt.m4 +++ b/build-aux/m4/bitcoin_qt.m4 @@ -116,8 +116,10 @@ AC_DEFUN([BITCOIN_QT_CONFIGURE],[ if test "x$bitcoin_cv_static_qt" = xyes; then _BITCOIN_QT_FIND_STATIC_PLUGINS AC_DEFINE(QT_STATICPLUGIN, 1, [Define this symbol if qt plugins are static]) - _BITCOIN_QT_CHECK_STATIC_PLUGINS([Q_IMPORT_PLUGIN(QMinimalIntegrationPlugin)],[-lqminimal]) - AC_DEFINE(QT_QPA_PLATFORM_MINIMAL, 1, [Define this symbol if the minimal qt platform exists]) + if test "x$TARGET_OS" != xandroid; then + _BITCOIN_QT_CHECK_STATIC_PLUGINS([Q_IMPORT_PLUGIN(QMinimalIntegrationPlugin)],[-lqminimal]) + AC_DEFINE(QT_QPA_PLATFORM_MINIMAL, 1, [Define this symbol if the minimal qt platform exists]) + fi if test "x$TARGET_OS" = xwindows; then _BITCOIN_QT_CHECK_STATIC_PLUGINS([Q_IMPORT_PLUGIN(QWindowsIntegrationPlugin)],[-lqwindows]) AC_DEFINE(QT_QPA_PLATFORM_WINDOWS, 1, [Define this symbol if the qt platform is windows]) From 24ffef0c271739a2ca75feecb816f3218c1850bf Mon Sep 17 00:00:00 2001 From: Igor Cota Date: Sun, 22 Sep 2019 15:40:15 +0200 Subject: [PATCH 09/13] Patch libevent when building for Android (fix arc4random_addrandom) --- depends/packages/libevent.mk | 13 +++- .../fix_android_arc4random_addrandom.patch | 68 +++++++++++++++++++ 2 files changed, 78 insertions(+), 3 deletions(-) create mode 100644 depends/patches/libevent/fix_android_arc4random_addrandom.patch diff --git a/depends/packages/libevent.mk b/depends/packages/libevent.mk index a3ade899b73..df6029828d8 100644 --- a/depends/packages/libevent.mk +++ b/depends/packages/libevent.mk @@ -3,10 +3,17 @@ $(package)_version=2.1.8-stable $(package)_download_path=https://github.com/libevent/libevent/archive/ $(package)_file_name=release-$($(package)_version).tar.gz $(package)_sha256_hash=316ddb401745ac5d222d7c529ef1eada12f58f6376a66c1118eee803cb70f83d +$(package)_patches=fix_android_arc4random_addrandom.patch -define $(package)_preprocess_cmds - ./autogen.sh -endef +ifneq (,$(findstring android,$(host))) + define $(package)_preprocess_cmds + ./autogen.sh && patch -p1 < $($(package)_patch_dir)/fix_android_arc4random_addrandom.patch + endef +else + define $(package)_preprocess_cmds + ./autogen.sh + endef +endif define $(package)_set_vars $(package)_config_opts=--disable-shared --disable-openssl --disable-libevent-regress --disable-samples diff --git a/depends/patches/libevent/fix_android_arc4random_addrandom.patch b/depends/patches/libevent/fix_android_arc4random_addrandom.patch new file mode 100644 index 00000000000..5bcc64bef6b --- /dev/null +++ b/depends/patches/libevent/fix_android_arc4random_addrandom.patch @@ -0,0 +1,68 @@ +From cadae3ab7abf45e61ecae8aac39d97d1f3cbd336 Mon Sep 17 00:00:00 2001 +From: Lawrence Nahum +Date: Sun, 3 Dec 2017 22:56:09 +0100 +Subject: [PATCH] fixup + +--- + configure.ac | 1 + + evutil_rand.c | 3 +++ + include/event2/util.h | 4 ++-- + 3 files changed, 6 insertions(+), 2 deletions(-) + +diff --git a/configure.ac b/configure.ac +index 7528d37..3bb2121 100644 +--- a/configure.ac ++++ b/configure.ac +@@ -341,6 +341,7 @@ dnl Checks for library functions. + AC_CHECK_FUNCS([ \ + accept4 \ + arc4random \ ++ arc4random_addrandom \ + arc4random_buf \ + eventfd \ + epoll_create1 \ +diff --git a/evutil_rand.c b/evutil_rand.c +index 046a14b..3f0bf2c 100644 +--- a/evutil_rand.c ++++ b/evutil_rand.c +@@ -191,6 +191,7 @@ evutil_secure_rng_get_bytes(void *buf, size_t n) + { + ev_arc4random_buf(buf, n); + } ++#ifdef HAVE_ARC4RANDOM_ADDRANDOM + + void + evutil_secure_rng_add_bytes(const char *buf, size_t n) +@@ -199,6 +200,8 @@ evutil_secure_rng_add_bytes(const char *buf, size_t n) + n>(size_t)INT_MAX ? INT_MAX : (int)n); + } + ++#endif ++ + void + evutil_free_secure_rng_globals_(void) + { +diff --git a/include/event2/util.h b/include/event2/util.h +index dd4bbb6..a9a169d 100644 +--- a/include/event2/util.h ++++ b/include/event2/util.h +@@ -841,7 +841,7 @@ int evutil_secure_rng_init(void); + */ + EVENT2_EXPORT_SYMBOL + int evutil_secure_rng_set_urandom_device_file(char *fname); +- ++#ifdef HAVE_ARC4RANDOM_ADDRANDOM + /** Seed the random number generator with extra random bytes. + + You should almost never need to call this function; it should be +@@ -858,7 +858,7 @@ int evutil_secure_rng_set_urandom_device_file(char *fname); + */ + EVENT2_EXPORT_SYMBOL + void evutil_secure_rng_add_bytes(const char *dat, size_t datlen); +- ++#endif + #ifdef __cplusplus + } + #endif +-- +2.14.3 From e4c319e8a1c6e40a953036b942bd5d732b0bbf69 Mon Sep 17 00:00:00 2001 From: Igor Cota Date: Mon, 23 Sep 2019 14:44:49 +0200 Subject: [PATCH 10/13] builds: remove superfluous config_opts_aarch64_android --- depends/packages/qt.mk | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/depends/packages/qt.mk b/depends/packages/qt.mk index ff80eb26488..a0cf930a710 100644 --- a/depends/packages/qt.mk +++ b/depends/packages/qt.mk @@ -19,8 +19,6 @@ $(package)_qttools_sha256_hash=a97556eb7b2f30252cdd8a598c396cfce2b2f79d2bae883af $(package)_extra_sources = $($(package)_qttranslations_file_name) $(package)_extra_sources += $($(package)_qttools_file_name) -$(package)_config_opts_aarch64_android = -xplatform android-clang -android-sdk $(ANDROID_SDK) -android-ndk $(ANDROID_NDK) -android-ndk-platform android-$(ANDROID_API_LEVEL) -device-option CROSS_COMPILE="$(host)-" -egl -qpa xcb -no-eglfs -opengl es2 -qt-freetype -no-fontconfig -L $(host_prefix)/lib -I $(host_prefix)/include - define $(package)_set_vars $(package)_config_opts_release = -release $(package)_config_opts_debug = -debug @@ -134,6 +132,7 @@ $(package)_config_opts_aarch64_android += -android-sdk $(ANDROID_SDK) $(package)_config_opts_aarch64_android += -android-ndk $(ANDROID_NDK) $(package)_config_opts_aarch64_android += -android-ndk-platform android-$(ANDROID_API_LEVEL) $(package)_config_opts_aarch64_android += -device-option CROSS_COMPILE="$(host)-" +$(package)_config_opts_aarch64_android += -android-arch arm64-v8a $(package)_config_opts_aarch64_android += -egl $(package)_config_opts_aarch64_android += -qpa xcb $(package)_config_opts_aarch64_android += -no-eglfs From ed30684d03d3a1d5496e69c488d848fe92ae6fb4 Mon Sep 17 00:00:00 2001 From: Igor Cota Date: Sat, 12 Oct 2019 12:49:25 +0200 Subject: [PATCH 11/13] Qt: patch androidjnimain.cpp to make sure JNI is initialised when statically compiled --- depends/packages/qt.mk | 3 ++- .../patches/qt/fix_android_jni_static.patch | 18 ++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 depends/patches/qt/fix_android_jni_static.patch diff --git a/depends/packages/qt.mk b/depends/packages/qt.mk index a0cf930a710..2f10a587c4c 100644 --- a/depends/packages/qt.mk +++ b/depends/packages/qt.mk @@ -8,7 +8,7 @@ $(package)_dependencies=openssl zlib $(package)_linux_dependencies=freetype fontconfig libxcb $(package)_build_subdir=qtbase $(package)_qt_libs=corelib network widgets gui plugins testlib -$(package)_patches=fix_qt_pkgconfig.patch mac-qmake.conf fix_configure_mac.patch fix_no_printer.patch fix_rcc_determinism.patch fix_riscv64_arch.patch xkb-default.patch no-xlib.patch fix_android_qmake_conf.patch +$(package)_patches=fix_qt_pkgconfig.patch mac-qmake.conf fix_configure_mac.patch fix_no_printer.patch fix_rcc_determinism.patch fix_riscv64_arch.patch xkb-default.patch no-xlib.patch fix_android_qmake_conf.patch fix_android_jni_static.patch $(package)_qttranslations_file_name=qttranslations-$($(package)_suffix) $(package)_qttranslations_sha256_hash=fb5a47799754af73d3bf501fe513342cfe2fc37f64e80df5533f6110e804220c @@ -184,6 +184,7 @@ define $(package)_preprocess_cmds patch -p1 -i $($(package)_patch_dir)/fix_rcc_determinism.patch &&\ patch -p1 -i $($(package)_patch_dir)/xkb-default.patch &&\ patch -p1 -i $($(package)_patch_dir)/fix_android_qmake_conf.patch &&\ + patch -p1 -i $($(package)_patch_dir)/fix_android_jni_static.patch &&\ echo "!host_build: QMAKE_CFLAGS += $($(package)_cflags) $($(package)_cppflags)" >> qtbase/mkspecs/common/gcc-base.conf && \ echo "!host_build: QMAKE_CXXFLAGS += $($(package)_cxxflags) $($(package)_cppflags)" >> qtbase/mkspecs/common/gcc-base.conf && \ echo "!host_build: QMAKE_LFLAGS += $($(package)_ldflags)" >> qtbase/mkspecs/common/gcc-base.conf && \ diff --git a/depends/patches/qt/fix_android_jni_static.patch b/depends/patches/qt/fix_android_jni_static.patch new file mode 100644 index 00000000000..2f6ff00f40c --- /dev/null +++ b/depends/patches/qt/fix_android_jni_static.patch @@ -0,0 +1,18 @@ +--- old/qtbase/src/plugins/platforms/android/androidjnimain.cpp ++++ new/qtbase/src/plugins/platforms/android/androidjnimain.cpp +@@ -890,6 +890,14 @@ + __android_log_print(ANDROID_LOG_FATAL, "Qt", "registerNatives failed"); + return -1; + } ++ ++ const jint ret = QT_PREPEND_NAMESPACE(QtAndroidPrivate::initJNI(vm, env)); ++ if (ret != 0) ++ { ++ __android_log_print(ANDROID_LOG_FATAL, "Qt", "initJNI failed"); ++ return ret; ++ } ++ + QWindowSystemInterfacePrivate::TabletEvent::setPlatformSynthesizesMouse(false); + + m_javaVM = vm; + From d419ca7e32bfc71e8dd1f1b91870463eacd6ad8e Mon Sep 17 00:00:00 2001 From: Igor Cota Date: Sat, 12 Oct 2019 13:25:06 +0200 Subject: [PATCH 12/13] depends: export dynamic JNI symbols from static qtforandroid.a --- build-aux/m4/bitcoin_qt.m4 | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/build-aux/m4/bitcoin_qt.m4 b/build-aux/m4/bitcoin_qt.m4 index 8a5bdd840e6..bab89a3dcc3 100644 --- a/build-aux/m4/bitcoin_qt.m4 +++ b/build-aux/m4/bitcoin_qt.m4 @@ -130,6 +130,9 @@ AC_DEFUN([BITCOIN_QT_CONFIGURE],[ AX_CHECK_LINK_FLAG([[-framework IOKit]],[QT_LIBS="$QT_LIBS -framework IOKit"],[AC_MSG_ERROR(could not iokit framework)]) _BITCOIN_QT_CHECK_STATIC_PLUGINS([Q_IMPORT_PLUGIN(QCocoaIntegrationPlugin)],[-lqcocoa]) AC_DEFINE(QT_QPA_PLATFORM_COCOA, 1, [Define this symbol if the qt platform is cocoa]) + elif test "x$TARGET_OS" = xandroid; then + QT_LIBS="-Wl,--export-dynamic,--undefined=JNI_OnLoad -lqtforandroid -ljnigraphics -landroid -lqtfreetype -lQt5EglSupport $QT_LIBS" + AC_DEFINE(QT_QPA_PLATFORM_ANDROID, 1, [Define this symbol if the qt platform is android]) fi fi CPPFLAGS=$TEMP_CPPFLAGS @@ -343,6 +346,9 @@ AC_DEFUN([_BITCOIN_QT_FIND_STATIC_PLUGINS],[ if test -d "$qt_plugin_path/accessible"; then QT_LIBS="$QT_LIBS -L$qt_plugin_path/accessible" fi + if test -d "$qt_plugin_path/platforms/android"; then + QT_LIBS="$QT_LIBS -L$qt_plugin_path/platforms/android -lqtfreetype -lEGL" + fi if test "x$use_pkgconfig" = xyes; then : dnl m4_ifdef([PKG_CHECK_MODULES],[ From f9af3ced1c69d65c5c530ec5526f5eefaf786126 Mon Sep 17 00:00:00 2001 From: Block Mechanic Date: Fri, 18 Oct 2019 22:03:51 +0200 Subject: [PATCH 13/13] Android: add all arch support Add support for armv7a, i686 and x86_64 archs to android.mk Add -fPIC to depends file as anddroid requires it see https://stackoverflow.com/questions/30498776/position-independent-executables-and-android --- depends/hosts/android.mk | 7 +++++++ depends/packages/boost.mk | 5 +++++ depends/packages/libevent.mk | 1 + depends/packages/openssl.mk | 6 +++++- depends/packages/qrencode.mk | 1 + depends/packages/qt.mk | 32 +++++++++++++++++++------------- depends/packages/zeromq.mk | 1 + depends/packages/zlib.mk | 2 +- 8 files changed, 40 insertions(+), 15 deletions(-) diff --git a/depends/hosts/android.mk b/depends/hosts/android.mk index c2a30d7a4d6..969ec2a1cb0 100644 --- a/depends/hosts/android.mk +++ b/depends/hosts/android.mk @@ -1,4 +1,11 @@ +ifeq ($(HOST),armv7a-linux-android) +android_AR=$(ANDROID_TOOLCHAIN_BIN)/arm-linux-androideabi-ar +android_CXX=$(ANDROID_TOOLCHAIN_BIN)/$(HOST)eabi$(ANDROID_API_LEVEL)-clang++ +android_CC=$(ANDROID_TOOLCHAIN_BIN)/$(HOST)eabi$(ANDROID_API_LEVEL)-clang +android_RANLIB=$(ANDROID_TOOLCHAIN_BIN)/arm-linux-androideabi-ranlib +else android_AR=$(ANDROID_TOOLCHAIN_BIN)/$(HOST)-ar android_CXX=$(ANDROID_TOOLCHAIN_BIN)/$(HOST)$(ANDROID_API_LEVEL)-clang++ android_CC=$(ANDROID_TOOLCHAIN_BIN)/$(HOST)$(ANDROID_API_LEVEL)-clang android_RANLIB=$(ANDROID_TOOLCHAIN_BIN)/$(HOST)-ranlib +endif diff --git a/depends/packages/boost.mk b/depends/packages/boost.mk index 5df49b2af85..5dfa1d2cdf3 100644 --- a/depends/packages/boost.mk +++ b/depends/packages/boost.mk @@ -15,6 +15,10 @@ $(package)_config_opts_mingw32=binary-format=pe target-os=windows threadapi=win3 $(package)_config_opts_x86_64_mingw32=address-model=64 $(package)_config_opts_i686_mingw32=address-model=32 $(package)_config_opts_i686_linux=address-model=32 architecture=x86 +$(package)_config_opts_i686_android=address-model=32 +$(package)_config_opts_aarch64_android=address-model=64 +$(package)_config_opts_x86_64_android=address-model=64 +$(package)_config_opts_armv7a_android=address-model=32 $(package)_toolset_$(host_os)=gcc $(package)_archiver_$(host_os)=$($(package)_ar) $(package)_toolset_darwin=darwin @@ -22,6 +26,7 @@ $(package)_archiver_darwin=$($(package)_libtool) $(package)_config_libraries=chrono,filesystem,system,thread,test $(package)_cxxflags=-std=c++11 -fvisibility=hidden $(package)_cxxflags_linux=-fPIC +$(package)_cxxflags_android=-fPIC endef define $(package)_preprocess_cmds diff --git a/depends/packages/libevent.mk b/depends/packages/libevent.mk index df6029828d8..bf5de610290 100644 --- a/depends/packages/libevent.mk +++ b/depends/packages/libevent.mk @@ -19,6 +19,7 @@ define $(package)_set_vars $(package)_config_opts=--disable-shared --disable-openssl --disable-libevent-regress --disable-samples $(package)_config_opts_release=--disable-debug-mode $(package)_config_opts_linux=--with-pic + $(package)_config_opts_android=--with-pic endef define $(package)_config_cmds diff --git a/depends/packages/openssl.mk b/depends/packages/openssl.mk index 6a316a308e0..ad922778acb 100644 --- a/depends/packages/openssl.mk +++ b/depends/packages/openssl.mk @@ -57,7 +57,11 @@ $(package)_config_opts_riscv64_linux=linux-generic64 $(package)_config_opts_x86_64_darwin=darwin64-x86_64-cc $(package)_config_opts_x86_64_mingw32=mingw64 $(package)_config_opts_i686_mingw32=mingw -$(package)_config_opts_android=linux-generic64 +$(package)_config_opts_android=-fPIC +$(package)_config_opts_aarch64_android=linux-generic64 +$(package)_config_opts_x86_64_android=linux-generic64 +$(package)_config_opts_armv7a_android=linux-generic32 +$(package)_config_opts_i686_android=linux-generic32 endef define $(package)_preprocess_cmds diff --git a/depends/packages/qrencode.mk b/depends/packages/qrencode.mk index 3bc2cb768cc..eed2bcd9803 100644 --- a/depends/packages/qrencode.mk +++ b/depends/packages/qrencode.mk @@ -8,6 +8,7 @@ define $(package)_set_vars $(package)_config_opts=--disable-shared --without-tools --without-tests --disable-sdltest $(package)_config_opts += --disable-gprof --disable-gcov --disable-mudflap $(package)_config_opts_linux=--with-pic +$(package)_config_opts_android=--with-pic endef define $(package)_preprocess_cmds diff --git a/depends/packages/qt.mk b/depends/packages/qt.mk index 2f10a587c4c..d4c4ab0ae8a 100644 --- a/depends/packages/qt.mk +++ b/depends/packages/qt.mk @@ -127,20 +127,26 @@ $(package)_config_opts_x86_64_linux = -xplatform linux-g++-64 $(package)_config_opts_aarch64_linux = -xplatform linux-aarch64-gnu-g++ $(package)_config_opts_riscv64_linux = -platform linux-g++ -xplatform bitcoin-linux-g++ $(package)_config_opts_mingw32 = -no-opengl -xplatform win32-g++ -device-option CROSS_COMPILE="$(host)-" -$(package)_config_opts_aarch64_android = -xplatform android-clang -$(package)_config_opts_aarch64_android += -android-sdk $(ANDROID_SDK) -$(package)_config_opts_aarch64_android += -android-ndk $(ANDROID_NDK) -$(package)_config_opts_aarch64_android += -android-ndk-platform android-$(ANDROID_API_LEVEL) -$(package)_config_opts_aarch64_android += -device-option CROSS_COMPILE="$(host)-" + +$(package)_config_opts_android = -xplatform android-clang +$(package)_config_opts_android += -android-sdk $(ANDROID_SDK) +$(package)_config_opts_android += -android-ndk $(ANDROID_NDK) +$(package)_config_opts_android += -android-ndk-platform android-$(ANDROID_API_LEVEL) +$(package)_config_opts_android += -device-option CROSS_COMPILE="$(host)-" +$(package)_config_opts_android += -egl +$(package)_config_opts_android += -qpa xcb +$(package)_config_opts_android += -no-eglfs +$(package)_config_opts_android += -opengl es2 +$(package)_config_opts_android += -qt-freetype +$(package)_config_opts_android += -no-fontconfig +$(package)_config_opts_android += -L $(host_prefix)/lib +$(package)_config_opts_android += -I $(host_prefix)/include + $(package)_config_opts_aarch64_android += -android-arch arm64-v8a -$(package)_config_opts_aarch64_android += -egl -$(package)_config_opts_aarch64_android += -qpa xcb -$(package)_config_opts_aarch64_android += -no-eglfs -$(package)_config_opts_aarch64_android += -opengl es2 -$(package)_config_opts_aarch64_android += -qt-freetype -$(package)_config_opts_aarch64_android += -no-fontconfig -$(package)_config_opts_aarch64_android += -L $(host_prefix)/lib -$(package)_config_opts_aarch64_android += -I $(host_prefix)/include +$(package)_config_opts_armv7a_android += -android-arch armeabi-v7a +$(package)_config_opts_x86_64_android += -android-arch x86_64 +$(package)_config_opts_i686_android += -android-arch i686 + $(package)_build_env = QT_RCC_TEST=1 $(package)_build_env += QT_RCC_SOURCE_DATE_OVERRIDE=1 endef diff --git a/depends/packages/zeromq.mk b/depends/packages/zeromq.mk index 9ac037ebb5c..eb60f7dee0a 100644 --- a/depends/packages/zeromq.mk +++ b/depends/packages/zeromq.mk @@ -10,6 +10,7 @@ define $(package)_set_vars $(package)_config_opts += --without-libsodium --without-libgssapi_krb5 --without-pgm --without-norm --without-vmci $(package)_config_opts += --disable-libunwind --disable-radix-tree --without-gcov $(package)_config_opts_linux=--with-pic + $(package)_config_opts_android=--with-pic $(package)_cxxflags=-std=c++11 endef diff --git a/depends/packages/zlib.mk b/depends/packages/zlib.mk index 017e7b2cf11..acb02020a80 100644 --- a/depends/packages/zlib.mk +++ b/depends/packages/zlib.mk @@ -11,7 +11,7 @@ $(package)_config_opts+=RANLIB="$($(package)_ranlib)" $(package)_config_opts+=AR="$($(package)_ar)" $(package)_config_opts_darwin+=AR="$($(package)_libtool)" $(package)_config_opts_darwin+=ARFLAGS="-o" -$(package)_config_opts_aarch64_android+=CHOST=$(host) +$(package)_config_opts_android+=CHOST=$(host) endef # zlib has its own custom configure script that takes in options like CC,