Please login or register.

Building Monero v0.10.3.1 for Android

The current Monero source code builds on 32 bit Android without any further patching, but the fixes in https://github.com/monero-project/monero/pull/1968 are required to get a 64 bit Android build working. The instructions here are for building from Linux, and I assume you've already got a working build environment for Linux. For Android you'll need to get a current Android SDK and NDK. (Though in fact, we're only using the NDK for this particular build.)

For this example, I'm setting up all of the build environment in /opt/android.

Preparing the Build Environment

  • Download and setup the Boost 1.62 source
  • Download and extract the Android SDK and NDK
  • Set up the Android NDK toolchain(s)
  • Build Boost
  • Add OpenSSL to the Android NDK toolchain
  • Build Monero
mkdir /opt/android
cd /opt/android
wget https://sourceforge.net/projects/boost/files/boost/1.62.0/boost_1_62_0.tar.bz2/download -O boost_1_62_0.tar.bz2
tar xjf boost_1_62_0.tar.bz2
(cd boost_1_62_0; ./bootstrap.sh)
wget http://dl.google.com/android/android-sdk_r24.4.1-linux.tgz
tar xzf android-sdk_r24.4.1-linux.tgz
wget https://dl.google.com/android/repository/android-ndk-r14-beta1-linux-x86_64.zip
unzip android-ndk-r14-beta1-linux-x86_64.zip

To set up the 32 bit toolchain, use

android-ndk-r14-beta1/build/tools/make_standalone_toolchain.py --api 21 --stl=libc++ --arch arm --install-dir /opt/android/tool32
PATH=/opt/android/tool32/arm-linux-androideabi/bin:/opt/android/tool32/bin:$PATH

For the 64 bit toolchain, use

android-ndk-r14-beta1/build/tools/make_standalone_toolchain.py --api 21 --stl=libc++ --arch arm64 --install-dir /opt/android/tool64
PATH=/opt/android/tool64/aarch64-linux-android/bin:/opt/android/tool64/bin:$PATH

Note - don't add both 32 and 64 bit toolchains to your path at the same time.

To build Boost with the 32 bit toolchain, use

cd boost_1_62_0
./b2 --build-type=minimal link=static runtime-link=static --with-chrono --with-date_time --with-filesystem --with-program_options --with-regex --with-serialization --with-system --with-thread --build-dir=android32 --stagedir=android32 toolset=clang threading=multi threadapi=pthread target-os=android stage

With the 64 bit toolchain, use

cd boost_1_62_0
./b2 --build-type=minimal link=static runtime-link=static --with-chrono --with-date_time --with-filesystem --with-program_options --with-regex --with-serialization --with-system --with-thread --build-dir=android64 --stagedir=android64 toolset=clang threading=multi threadapi=pthread target-os=android stage

Android ships with a build of OpenSSL already, but they don't include the files as part of the NDK. We need to grab the include files so that Monero will build. We also need some shared libraries for the build to link against, which you can obtain from any Android device. Note that Android now uses BoringSSL, not the actual OpenSSL libraries.

To get the header files

cd /opt/android
git clone https://android.googlesource.com/platform/external/boringssl

To add them to the 32 bit toolchain

cd /opt/android/tool32/sysroot/usr/include
ln -s ../../../../boringssl/src/include/openssl

Likewise for the 64 bit toolchain

cd /opt/android/tool64/sysroot/usr/include
ln -s ../../../../boringssl/src/include/openssl

The easiest way to get the libraries is to use adb to pull them off a phone

cd /opt/android
mkdir target target/lib32 target/lib64
cd target/lib32
adb pull /system/lib/libssl.so
adb pull /system/lib/libcrypto.so
cd ../lib64
adb pull /system/lib64/libssl.so
adb pull /system/lib64/libcrypto.so

To add these to the 32 bit toolchain

cd /opt/android/tool32/sysroot/usr/lib
ln -s ../../../../target/lib32/libssl.so
ln -s ../../../../target/lib32/libcrypto.so

And the likewise for the 64 bit toolchain

cd /opt/android/tool64/sysroot/usr/lib
ln -s ../../../../target/lib64/libssl.so
ln -s ../../../../target/lib64/libcrypto.so

To build Monero for 32 bit Android, use

cd monero
mkdir -p build/release.android32
cd build/release.android32
CC=clang CXX=clang++ cmake -D BUILD_TESTS=OFF -D ARCH="armv7-a" -D STATIC=ON -D BUILD_64=OFF -D CMAKE_BUILD_TYPE=release -D ANDROID=true -D BUILD_TAG="android" -D BOOST_ROOT=/opt/android/boost_1_62_0 -D BOOST_LIBRARYDIR=/opt/android/boost_1_62_0/android32/lib ../..

To build Monero for 64 bit Android, use

cd monero
mkdir -p build/release.android64
cd build/release.android64
CC=clang CXX=clang++ cmake -D BUILD_TESTS=OFF -D ARCH="armv8-a" -D STATIC=ON -D BUILD_64=ON -D CMAKE_BUILD_TYPE=release -D ANDROID=true -D BUILD_TAG="android" -D BOOST_ROOT=/opt/android/boost_1_62_0 -D BOOST_LIBRARYDIR=/opt/android/boost_1_62_0/android64/lib ../..

That should be all you need.

Replies: 0