xmrwallet external-libs 编译

@pfrong  November 25, 2018

1.前言

xmrwallet 是门罗币钱包的安卓版本

2 环境准备

2.1 系统

系统采用 docker 安装 ubuntu 16.04 或者 debian jessie

2.2 安装必要的依赖库

#建议版本PKG名称
GCC4.7.3build-essential
CMake3.0.0cmake
pkg-config4.7.3pkg-config
Boost1.5.8libboost-all-dev
OpenSSL1.0.1libssl-dev
libzmq3.0.0libzmq3-dev
libunbound1.4.16libunbound-dev
libsodiumany libsodium-dev
libminiupnpc2.0liblzma-dev
liblzmaanybuild-essential
libreadline6.3.0libreadline6-dev
ldns1.6.17libldns-dev
expatanylibexpat1-dev
GTest1.1libgtest-dev
Doxygen1.5doxygen
Graphvizanygraphviz
pcscliteanylibpcsclite-dev

2.3 创建目录

sudo mkdir /opt/android
sudo chown $LOGNAME /opt/android

注:如果是docker环境,第二步可以不用执行。

3. 安装 Android NDK

NDK推荐版本 r16b

cd /opt/android
wget https://dl.google.com/android/repository/android-ndk-r16b-linux-x86_64.zip
unzip android-ndk-r16b-linux-x86_64.zip
ln -s android-ndk-r16b ndk
ndk/build/tools/make_standalone_toolchain.py --api 21 --stl=libc++ --arch arm --install-dir /opt/android/tool/arm
ndk/build/tools/make_standalone_toolchain.py --api 21 --stl=libc++ --arch arm64 --install-dir /opt/android/tool/arm64
ndk/build/tools/make_standalone_toolchain.py --api 21 --stl=libc++ --arch x86 --install-dir /opt/android/tool/x86
ndk/build/tools/make_standalone_toolchain.py --api 21 --stl=libc++ --arch x86_64 --install-dir /opt/android/tool/x86_64

创建输出目录

mkdir -p /opt/android/build

4 编译 OpenSSL

cd /opt/android
git clone https://github.com/m2049r/android-openssl.git
wget https://github.com/openssl/openssl/archive/OpenSSL_1_0_2l.tar.gz
cd android-openssl
tar xfz ../OpenSSL_1_0_2l.tar.gz
ANDROID_NDK_ROOT=/opt/android/ndk ./build-all-arch.sh

安装和链接

mkdir -p /opt/android/build/openssl/{arm,arm64,x86,x86_64}
cp -a /opt/android/android-openssl/prebuilt/armeabi   /opt/android/build/openssl/arm/lib
cp -a /opt/android/android-openssl/prebuilt/arm64-v8a /opt/android/build/openssl/arm64/lib
cp -a /opt/android/android-openssl/prebuilt/x86       /opt/android/build/openssl/x86/lib
cp -a /opt/android/android-openssl/prebuilt/x86_64    /opt/android/build/openssl/x86_64/lib
cp -aL /opt/android/android-openssl/openssl-OpenSSL_1_0_2l/include/openssl/ /opt/android/build/openssl/include
ln -s /opt/android/build/openssl/include /opt/android/build/openssl/arm/include
ln -s /opt/android/build/openssl/include /opt/android/build/openssl/arm64/include
ln -s /opt/android/build/openssl/include /opt/android/build/openssl/x86/include
ln -s /opt/android/build/openssl/include /opt/android/build/openssl/x86_64/include
ln -sf /opt/android/build/openssl/include /opt/android/tool/arm/sysroot/usr/include/openssl
ln -sf /opt/android/build/openssl/arm/lib/*.so /opt/android/tool/arm/sysroot/usr/lib

ln -sf /opt/android/build/openssl/include /opt/android/tool/arm64/sysroot/usr/include/openssl
ln -sf /opt/android/build/openssl/arm64/lib/*.so /opt/android/tool/arm64/sysroot/usr/lib

ln -sf /opt/android/build/openssl/include /opt/android/tool/x86/sysroot/usr/include/openssl
ln -sf /opt/android/build/openssl/x86/lib/*.so /opt/android/tool/x86/sysroot/usr/lib

ln -sf /opt/android/build/openssl/include /opt/android/tool/x86_64/sysroot/usr/include/openssl
ln -sf /opt/android/build/openssl/x86_64/lib/*.so /opt/android/tool/x86_64/sysroot/usr/lib64

5 编译 Boost

cd /opt/android
wget https://sourceforge.net/projects/boost/files/boost/1.58.0/boost_1_58_0.tar.gz/download -O boost_1_58_0.tar.gz
tar xfz boost_1_58_0.tar.gz
cd boost_1_58_0
./bootstrap.sh

找到 /opt/android/boost_1_58_0/compatibility/cpp_c_headers 文件夹下的 cstdio 文件,打开并注释掉 using ::fgetpos;using ::fsetpos;

然后继续编译:

PATH=/opt/android/tool/arm/arm-linux-androideabi/bin:/opt/android/tool/arm/bin:$PATH      ./b2 --build-type=minimal link=static runtime-link=static --with-chrono --with-atomic --with-date_time --with-filesystem --with-program_options --with-regex --with-serialization --with-system --with-thread --build-dir=android-arm    --prefix=/opt/android/build/boost/arm    --includedir=/opt/android/build/boost/include toolset=clang threading=multi threadapi=pthread target-os=android install
ln -sf ../include /opt/android/build/boost/arm
PATH=/opt/android/tool/arm64/aarch64-linux-android/bin:/opt/android/tool/arm64/bin:$PATH  ./b2 --build-type=minimal link=static runtime-link=static --with-chrono --with-atomic --with-date_time --with-filesystem --with-program_options --with-regex --with-serialization --with-system --with-thread --build-dir=android-arm64  --prefix=/opt/android/build/boost/arm64  --includedir=/opt/android/build/boost/include toolset=clang threading=multi threadapi=pthread target-os=android install
ln -sf ../include /opt/android/build/boost/arm64
PATH=/opt/android/tool/x86/i686-linux-android/bin:/opt/android/tool/x86/bin:$PATH         ./b2 --build-type=minimal link=static runtime-link=static --with-chrono --with-atomic --with-date_time --with-filesystem --with-program_options --with-regex --with-serialization --with-system --with-thread --build-dir=android-x86    --prefix=/opt/android/build/boost/x86    --includedir=/opt/android/build/boost/include toolset=clang threading=multi threadapi=pthread target-os=android install
ln -sf ../include /opt/android/build/boost/x86
PATH=/opt/android/tool/x86_64/x86_64-linux-android/bin:/opt/android/tool/x86_64/bin:$PATH ./b2 --build-type=minimal link=static runtime-link=static --with-chrono --with-atomic --with-date_time --with-filesystem --with-program_options --with-regex --with-serialization --with-system --with-thread --build-dir=android-x86_64 --prefix=/opt/android/build/boost/x86_64 --includedir=/opt/android/build/boost/include toolset=clang threading=multi threadapi=pthread target-os=android install
ln -sf ../include /opt/android/build/boost/x86_64

6 编译 Monero

https://github.com/m2049r/monero 找到 0.12 版本的最新分支(最好跟 xmrwallet 描述一致的版本),如 release-v0.12.3-ledger 版本:

cd /opt/android
git clone --recursive -b release-v0.12.3-ledger https://github.com/m2049r/monero.git

这里有个坑,monero 项目链接了子模块,所有必须检索出子项目才能编译成功!

接下来参考 https://pastebin.com/E8ZMSnhD 修改 build-all-arch.shCMakeLists.txt 文件,不然无法编译通过!

From fd656bf488bc3c58a62b13067e18621c498f02ed Mon Sep 17 00:00:00 2001
From: 0140454 <s1994928@yahoo.com.tw>
Date: Mon, 23 Apr 2018 23:23:21 +0800
Subject: [PATCH 1/2] Set OPENSSL_INCLUDE_DIR to ensure cmake detecting correct
 version
 
---
build-all-arch.sh | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
 
diff --git a/build-all-arch.sh b/build-all-arch.sh
index 8d5e48dc..f1e8fe00 100755
--- a/build-all-arch.sh
+++ b/build-all-arch.sh
@@ -44,7 +44,7 @@ for arch in ${archs[@]}; do
    mkdir -p $OUTPUT_DIR
    cd $OUTPUT_DIR
 
-   PATH=/opt/android/tool/$arch/$target_host/bin:/opt/android/tool/$arch/bin:$PATH CC=clang CXX=clang++ cmake -D BUILD_GUI_DEPS=1 -D BUILD_TESTS=OFF -D ARCH="$xarch" -D STATIC=ON -D BUILD_64=$sixtyfour -D CMAKE_BUILD_TYPE=$build_type -D ANDROID=true -D BUILD_TAG="android" -D BOOST_ROOT=/opt/android/build/boost/$arch -D BOOST_LIBRARYDIR=/opt/android/build/boost/$arch/lib -D OPENSSL_ROOT_DIR=/opt/android/build/openssl/$arch -D OPENSSL_CRYPTO_LIBRARY=/opt/android/build/openssl/$arch/lib/libcrypto.so -D OPENSSL_SSL_LIBRARY=/opt/android/build/openssl/$arch/lib/libssl.so -D CMAKE_POSITION_INDEPENDENT_CODE:BOOL=true ../..
+   PATH=/opt/android/tool/$arch/$target_host/bin:/opt/android/tool/$arch/bin:$PATH CC=clang CXX=clang++ cmake -D BUILD_GUI_DEPS=1 -D BUILD_TESTS=OFF -D ARCH="$xarch" -D STATIC=ON -D BUILD_64=$sixtyfour -D CMAKE_BUILD_TYPE=$build_type -D ANDROID=true -D BUILD_TAG="android" -D BOOST_ROOT=/opt/android/build/boost/$arch -D BOOST_LIBRARYDIR=/opt/android/build/boost/$arch/lib -D OPENSSL_ROOT_DIR=/opt/android/build/openssl/$arch -D OPENSSL_INCLUDE_DIR=/opt/android/build/openssl/$arch -D OPENSSL_CRYPTO_LIBRARY=/opt/android/build/openssl/$arch/lib/libcrypto.so -D OPENSSL_SSL_LIBRARY=/opt/android/build/openssl/$arch/lib/libssl.so -D CMAKE_POSITION_INDEPENDENT_CODE:BOOL=true ../..
    make -j4 wallet_api
    find . -path ./lib -prune -o -name '*.a' -exec cp '{}' lib \;
 
--
2.14.1
 
 
From d8aedb205b249d16d038683af788740b5074f265 Mon Sep 17 00:00:00 2001
From: 0140454 <s1994928@yahoo.com.tw>
Date: Mon, 23 Apr 2018 23:25:38 +0800
Subject: [PATCH 2/2] Suppress 'user-defined-warnings'
 
---
CMakeLists.txt | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
 
diff --git a/CMakeLists.txt b/CMakeLists.txt
index f2350281..8a029354 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -489,7 +489,7 @@ else()
   else()
     set(ARCH_FLAG "-march=${ARCH}")
   endif()
-  set(WARNINGS "-Wall -Wextra -Wpointer-arith -Wundef -Wvla -Wwrite-strings -Wno-error=extra -Wno-error=deprecated-declarations -Wno-unused-parameter -Wno-unused-variable -Wno-error=unused-variable -Wno-error=undef -Wno-error=uninitialized")
+  set(WARNINGS "-Wall -Wextra -Wpointer-arith -Wundef -Wvla -Wwrite-strings -Wno-error=extra -Wno-error=deprecated-declarations -Wno-unused-parameter -Wno-unused-variable -Wno-error=unused-variable -Wno-error=undef -Wno-error=uninitialized -Wno-error=user-defined-warnings")
   if(NOT MINGW)
     set(WARNINGS_AS_ERRORS_FLAG "-Werror")
   endif()
--
2.14.1

修改完后开始编译

cd /opt/android/monero
./build-all-arch.sh

然后等待编译完成!

7 拷贝文件

  • 拷贝/opt/android/build文件夹下所有的 .a 文件到 external-libs 的对应文件夹下
  • 拷贝 /opt/android/monero/src/wallet/api/wallet2_api.h 文件到 external-libs/monero/include

完结。。。


添加新评论