Skip to content

Commit 91fbcf4

Browse files
committed
Merge #16110: depends: Add Android NDK support
f9af3ce Android: add all arch support (Block Mechanic) d419ca7 depends: export dynamic JNI symbols from static qtforandroid.a (Igor Cota) ed30684 Qt: patch androidjnimain.cpp to make sure JNI is initialised when statically compiled (Igor Cota) e4c319e builds: remove superfluous config_opts_aarch64_android (Igor Cota) 24ffef0 Patch libevent when building for Android (fix arc4random_addrandom) (Igor Cota) f1e40b3 Update bitcoin_qt.m4 (BlockMechanic) b4057d8 Define TARGET_OS when host is android (Igor Cota) 80b475f Fix Android zlib cross compilation issue (https://stackoverflow.com/questions/21396988/zlib-build-not-configuring-properly-with-cross-compiler-ignores-ar) (Igor Cota) 45f8219 Add full Android build example command and instructions on getting SDK/NDK (Igor Cota) b68f2a6 Add config opts and patch for aarch64_android build of Qt (Igor Cota) 9c4cb01 Add ranlib to android.mk hosts file (fix OSX Android NDK build) (Igor Cota) c2a749c Add example Android host-platform-triplet and options (Igor Cota) 0b0cff3 Add support for building Android dependencies (Igor Cota) Pull request description: This allows one to build the dependencies with the Android SDK and goes towards fixing #11844. It has been tested to work with: `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` ACKs for top commit: Sjors: ACK f9af3ce. I'm OK with merging and then improving later. Tree-SHA512: cb805115ebe5c9e33db2bf3eab8628808fe3f50052053d8877d8b8e4406d6fea1ed9e5c4dff85d777fb99c81be6ffb9d95a0e6d32344e728e5e0da6c653e2ce7
2 parents c4b8dd2 + f9af3ce commit 91fbcf4

16 files changed

+191
-7
lines changed

build-aux/m4/bitcoin_qt.m4

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,8 +116,10 @@ AC_DEFUN([BITCOIN_QT_CONFIGURE],[
116116
if test "x$bitcoin_cv_static_qt" = xyes; then
117117
_BITCOIN_QT_FIND_STATIC_PLUGINS
118118
AC_DEFINE(QT_STATICPLUGIN, 1, [Define this symbol if qt plugins are static])
119-
_BITCOIN_QT_CHECK_STATIC_PLUGINS([Q_IMPORT_PLUGIN(QMinimalIntegrationPlugin)],[-lqminimal])
120-
AC_DEFINE(QT_QPA_PLATFORM_MINIMAL, 1, [Define this symbol if the minimal qt platform exists])
119+
if test "x$TARGET_OS" != xandroid; then
120+
_BITCOIN_QT_CHECK_STATIC_PLUGINS([Q_IMPORT_PLUGIN(QMinimalIntegrationPlugin)],[-lqminimal])
121+
AC_DEFINE(QT_QPA_PLATFORM_MINIMAL, 1, [Define this symbol if the minimal qt platform exists])
122+
fi
121123
if test "x$TARGET_OS" = xwindows; then
122124
_BITCOIN_QT_CHECK_STATIC_PLUGINS([Q_IMPORT_PLUGIN(QWindowsIntegrationPlugin)],[-lqwindows])
123125
AC_DEFINE(QT_QPA_PLATFORM_WINDOWS, 1, [Define this symbol if the qt platform is windows])
@@ -128,6 +130,9 @@ AC_DEFUN([BITCOIN_QT_CONFIGURE],[
128130
AX_CHECK_LINK_FLAG([[-framework IOKit]],[QT_LIBS="$QT_LIBS -framework IOKit"],[AC_MSG_ERROR(could not iokit framework)])
129131
_BITCOIN_QT_CHECK_STATIC_PLUGINS([Q_IMPORT_PLUGIN(QCocoaIntegrationPlugin)],[-lqcocoa])
130132
AC_DEFINE(QT_QPA_PLATFORM_COCOA, 1, [Define this symbol if the qt platform is cocoa])
133+
elif test "x$TARGET_OS" = xandroid; then
134+
QT_LIBS="-Wl,--export-dynamic,--undefined=JNI_OnLoad -lqtforandroid -ljnigraphics -landroid -lqtfreetype -lQt5EglSupport $QT_LIBS"
135+
AC_DEFINE(QT_QPA_PLATFORM_ANDROID, 1, [Define this symbol if the qt platform is android])
131136
fi
132137
fi
133138
CPPFLAGS=$TEMP_CPPFLAGS
@@ -345,6 +350,9 @@ AC_DEFUN([_BITCOIN_QT_FIND_STATIC_PLUGINS],[
345350
if test -d "$qt_plugin_path/accessible"; then
346351
QT_LIBS="$QT_LIBS -L$qt_plugin_path/accessible"
347352
fi
353+
if test -d "$qt_plugin_path/platforms/android"; then
354+
QT_LIBS="$QT_LIBS -L$qt_plugin_path/platforms/android -lqtfreetype -lEGL"
355+
fi
348356
if test "x$use_pkgconfig" = xyes; then
349357
: dnl
350358
m4_ifdef([PKG_CHECK_MODULES],[

configure.ac

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -597,6 +597,7 @@ case $host in
597597
;;
598598
*android*)
599599
dnl make sure android stays above linux for hosts like *linux-android*
600+
TARGET_OS=android
600601
LEVELDB_TARGET_FLAGS="-DOS_ANDROID"
601602
;;
602603
*linux*)

depends/Makefile

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,11 @@ full_host_os:=$(subst $(host_arch)-$(host_vendor)-,,$(canonical_host))
5858
host_os:=$(findstring linux,$(full_host_os))
5959
host_os+=$(findstring darwin,$(full_host_os))
6060
host_os+=$(findstring mingw32,$(full_host_os))
61+
62+
ifeq (android,$(findstring android,$(full_host_os)))
63+
host_os:=android
64+
endif
65+
6166
host_os:=$(strip $(host_os))
6267
ifeq ($(host_os),)
6368
host_os=$(full_host_os)

depends/README.md

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,17 @@ Common `host-platform-triplets` for cross compilation are:
3030
- `aarch64-linux-gnu` for Linux ARM 64 bit
3131
- `riscv32-linux-gnu` for Linux RISC-V 32 bit
3232
- `riscv64-linux-gnu` for Linux RISC-V 64 bit
33+
- `aarch64-linux-android` for Android ARM 64 bit
34+
35+
The paths are automatically configured and no other options are needed unless targeting Android.
36+
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).
37+
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.
38+
If the build includes Qt, environment variables `ANDROID_SDK` and `ANDROID_NDK` need to be set as well but can otherwise be omitted.
39+
This is an example command for a default build with no disabled dependencies:
40+
41+
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
42+
3343

34-
No other options are needed, the paths are automatically configured.
3544

3645
### Install the required dependencies: Ubuntu & Debian
3746

depends/hosts/android.mk

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
ifeq ($(HOST),armv7a-linux-android)
2+
android_AR=$(ANDROID_TOOLCHAIN_BIN)/arm-linux-androideabi-ar
3+
android_CXX=$(ANDROID_TOOLCHAIN_BIN)/$(HOST)eabi$(ANDROID_API_LEVEL)-clang++
4+
android_CC=$(ANDROID_TOOLCHAIN_BIN)/$(HOST)eabi$(ANDROID_API_LEVEL)-clang
5+
android_RANLIB=$(ANDROID_TOOLCHAIN_BIN)/arm-linux-androideabi-ranlib
6+
else
7+
android_AR=$(ANDROID_TOOLCHAIN_BIN)/$(HOST)-ar
8+
android_CXX=$(ANDROID_TOOLCHAIN_BIN)/$(HOST)$(ANDROID_API_LEVEL)-clang++
9+
android_CC=$(ANDROID_TOOLCHAIN_BIN)/$(HOST)$(ANDROID_API_LEVEL)-clang
10+
android_RANLIB=$(ANDROID_TOOLCHAIN_BIN)/$(HOST)-ranlib
11+
endif

depends/packages/boost.mk

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,17 @@ $(package)_config_opts_mingw32=binary-format=pe target-os=windows threadapi=win3
1515
$(package)_config_opts_x86_64_mingw32=address-model=64
1616
$(package)_config_opts_i686_mingw32=address-model=32
1717
$(package)_config_opts_i686_linux=address-model=32 architecture=x86
18+
$(package)_config_opts_i686_android=address-model=32
19+
$(package)_config_opts_aarch64_android=address-model=64
20+
$(package)_config_opts_x86_64_android=address-model=64
21+
$(package)_config_opts_armv7a_android=address-model=32
1822
$(package)_toolset_$(host_os)=gcc
1923
$(package)_archiver_$(host_os)=$($(package)_ar)
2024
$(package)_toolset_darwin=clang-darwin
2125
$(package)_config_libraries=chrono,filesystem,system,thread,test
2226
$(package)_cxxflags=-std=c++11 -fvisibility=hidden
2327
$(package)_cxxflags_linux=-fPIC
28+
$(package)_cxxflags_android=-fPIC
2429
endef
2530

2631
define $(package)_preprocess_cmds

depends/packages/libevent.mk

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,24 @@ $(package)_version=2.1.8-stable
33
$(package)_download_path=https://github.com/libevent/libevent/archive/
44
$(package)_file_name=release-$($(package)_version).tar.gz
55
$(package)_sha256_hash=316ddb401745ac5d222d7c529ef1eada12f58f6376a66c1118eee803cb70f83d
6+
$(package)_patches=fix_android_arc4random_addrandom.patch
67

7-
define $(package)_preprocess_cmds
8-
./autogen.sh
9-
endef
8+
ifneq (,$(findstring android,$(host)))
9+
define $(package)_preprocess_cmds
10+
./autogen.sh && patch -p1 < $($(package)_patch_dir)/fix_android_arc4random_addrandom.patch
11+
endef
12+
else
13+
define $(package)_preprocess_cmds
14+
./autogen.sh
15+
endef
16+
endif
1017

1118
define $(package)_set_vars
1219
$(package)_config_opts=--disable-shared --disable-openssl --disable-libevent-regress --disable-samples
1320
$(package)_config_opts += --disable-dependency-tracking --enable-option-checking
1421
$(package)_config_opts_release=--disable-debug-mode
1522
$(package)_config_opts_linux=--with-pic
23+
$(package)_config_opts_android=--with-pic
1624
endef
1725

1826
define $(package)_config_cmds

depends/packages/openssl.mk

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,11 @@ $(package)_config_opts_riscv64_linux=linux-generic64
5858
$(package)_config_opts_x86_64_darwin=darwin64-x86_64-cc
5959
$(package)_config_opts_x86_64_mingw32=mingw64
6060
$(package)_config_opts_i686_mingw32=mingw
61+
$(package)_config_opts_android=-fPIC
62+
$(package)_config_opts_aarch64_android=linux-generic64
63+
$(package)_config_opts_x86_64_android=linux-generic64
64+
$(package)_config_opts_armv7a_android=linux-generic32
65+
$(package)_config_opts_i686_android=linux-generic32
6166
endef
6267

6368
define $(package)_preprocess_cmds

depends/packages/packages.mk

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ packages:=boost openssl libevent
33
qt_packages = qrencode zlib
44

55
qt_linux_packages:=qt expat libxcb xcb_proto libXau xproto freetype fontconfig
6+
qt_android_packages=qt
67

78
rapidcheck_packages = rapidcheck
89

depends/packages/qrencode.mk

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ $(package)_config_opts=--disable-shared --without-tools --without-tests --disabl
99
$(package)_config_opts += --disable-gprof --disable-gcov --disable-mudflap
1010
$(package)_config_opts += --disable-dependency-tracking --enable-option-checking
1111
$(package)_config_opts_linux=--with-pic
12+
$(package)_config_opts_android=--with-pic
1213
endef
1314

1415
define $(package)_preprocess_cmds

0 commit comments

Comments
 (0)