Building and Running a full Grin Node (Grin++) on Android

BIG NOTES: the node is still unstable. I will keep this thread up to date. Do not waste your time trying to do this on Windows. The target for now is Android 10.

The first thing that we need is the Android NDK. The Android NDK is a toolset that lets you embed components that make use of native code in your Android applications. Grin++ is written in the almighty C++ therefore we could use the Android NDK to build this little baby. At this moment we will need to download the NDK from the Canary (or Dev) Channel because it is a mess to update the toolchain for the stable release, if anyone is able to do it, please let me know commenting this post.

vcpkg

vcpkg is a command-line package manager for C++. It greatly simplifies the acquisition and installation of third-party libraries on Windows, Linux, and macOS. If your project uses third-party libraries, we recommend that you use vcpkg to install them. vcpkg supports both open-source and proprietary libraries. Installing this tool is as easy as this:

$ sudo apt-get update
$ sudo apt-get install build-essential tar curl zip unzip
$ git clone https://github.com/microsoft/vcpkg
$ cd vcpkg
$ bash bootstrap-vcpkg.sh
$ ./vcpkg integrate install

Android ADB

Android Debug Bridge (adb) is a versatile command-line tool that lets you communicate with a device. The adb command facilitates a variety of device actions, such as installing and debugging apps, and it provides access to a Unix shell that you can use to run a variety of commands on a device.Install Android ADB using this guide https://androidmore.com/install-adb-fastboot-linux/

Downloading the Latest build of the Android NDK.

Go the Android CI https://ci.android.com/builds/branches/aosp-master-ndk/grid and pick the latest build:

AndroidNDK

Now download the zip file of more than 1GB of course:

Extract the zip file into your preferred folder.

Show Time!!! :call_me_hand:

I wrote a bash script to simplify the process:

cd /home/david/Projects/
git clone https://github.com/GrinPlusPlus/GrinPlusPlus
cd GrinPlusPlus
git checkout android-arm64

vcpkg install --overlay-triplets=vcpkg/custom_triplets --triplet arm64-android-static --debug mio && \
vcpkg install --overlay-triplets=vcpkg/custom_triplets --triplet arm64-android-static --debug libuuid && \
vcpkg install --overlay-triplets=vcpkg/custom_triplets --triplet arm64-android-static --debug fmt && \
vcpkg install --overlay-triplets=vcpkg/custom_triplets --triplet arm64-android-static --debug asio && \
vcpkg install --overlay-triplets=vcpkg/custom_triplets --triplet arm64-android-static --debug zlib && \
vcpkg install --overlay-triplets=vcpkg/custom_triplets --overlay-ports=vcpkg/custom_ports --triplet arm64-android-static --debug minizip && \
vcpkg install --overlay-triplets=vcpkg/custom_triplets --overlay-ports=vcpkg/custom_ports --triplet arm64-android-static --debug secp256k1-zkp && \
vcpkg install --overlay-triplets=vcpkg/custom_triplets --overlay-ports=vcpkg/custom_ports --triplet arm64-android-static --debug rocksdb && \
vcpkg install --overlay-triplets=vcpkg/custom_triplets --overlay-ports=vcpkg/custom_ports --triplet arm64-android-static --debug civetweb && \
vcpkg install --overlay-triplets=vcpkg/custom_triplets --overlay-ports=vcpkg/custom_ports --triplet arm64-android-static --debug roaring && \
vcpkg install --overlay-triplets=vcpkg/custom_triplets --overlay-ports=vcpkg/custom_ports --triplet arm64-android-static --debug libsodium

export NDK=/home/david/Android/Sdk/ndk/canary
export API=29
export TOOLCHAIN=$NDK/toolchains/llvm/prebuilt/linux-x86_64
export TARGET=aarch64-linux-android
export AR=$TOOLCHAIN/bin/$TARGET-ar
export AS=$TOOLCHAIN/bin/$TARGET-as
export CC=$TOOLCHAIN/bin/$TARGET$API-clang
export CXX=$TOOLCHAIN/bin/$TARGET$API-clang++
export LD=$TOOLCHAIN/bin/$TARGET-ld
export RANLIB=$TOOLCHAIN/bin/$TARGET-ranlib
export STRIP=$TOOLCHAIN/bin/$TARGET-strip

rm -Rf /home/david/Projects/GrinPlusPlus/build && mkdir /home/david/Projects/GrinPlusPlus/build && \
cmake -S /home/david/Projects/GrinPlusPlus -B /home/david/Projects/GrinPlusPlus/build -G Ninja \
      -D CMAKE_BUILD_TYPE=Release -D GRINPP_TESTS=OFF -D GRINPP_TOOLS=OFF \
      -D CMAKE_MAKE_PROGRAM=/home/david/Tools/vcpkg/downloads/tools/ninja-1.10.0-linux/ninja \
      -D CMAKE_TOOLCHAIN_FILE=/home/david/Tools/vcpkg/scripts/buildsystems/vcpkg.cmake -DVCPKG_TARGET_TRIPLET=arm64-android-static
cmake --build /home/david/Projects/GrinPlusPlus/build

*** If you want to do it by yourself, please update the paths.

Running Grin++

Now, we need Termux or any other Terminal for Android or we can run it using ADB after copying the binary into your device, your device needs to the Developer Mode enabled; then use this command to copy the binary into the android device: adb push build/GrinNode /sdcard/Download. If you’re using the Termux you need to move the binary into the Termux directory.

What’s Next?!

After getting a stable build, this will be packaged into the Android App, the branch will remains even with the master branch. Stay tuned!

13 Likes

Grin++ (full node) is running now on Android, and it is actually really stable now.

I will continue working on connecting the APK with the Node. You can find the binary here: https://keybase.pub/dtavarez/android/ but also the code is here: https://github.com/GrinPlusPlus/GrinPlusPlus/tree/android-arm64

11 Likes

Cool, finally there will be some use for the 8-12GB RAM most mid-high end phones have nowadays.

Small update:

Note: I’m currently testing the apk using the binary for Android 9.0

5 Likes

It worked great. I could send and receive. After shutting it down overnight it resynced to network in seconds

4 Likes

It’s fair to say that the initial sync could take between 25 and 40 minutes depending on the device :sweat_smile: therefore I’m working on adding a disclaimer in the app before starting to sync the first time.