Skip to content

Compiling RubiChess for Android

Andreas Matthies edited this page Jan 24, 2024 · 12 revisions

Some notes on how to cross-compile RubiChess for Android

Option 1: Native build on Android device using Termux

  • Install Termux in your Android device (I tested with version 0.118.0, com.termux_118.apk)
  • Run Termux and install missing packages inside the terminal: pkg install git make clang binutils
  • Clone RubiChess Github repository, go to src folder and build a release using the following commands:
git clone https://github.com/Matthies/RubiChess.git
cd RubiChess/src
make release COMP=clang EVALFILE=default

You can leave out EVALFILE=... but then the network file will not be embedded.

Option 2: Use the Android SDK with additional components (example for Linux)

  • Download latest SDK from https://developer.android.com/studio and unzip to Home directory: ~/android-studio
  • Start the studio ~/android-studio/bin/studio.sh
  • Finish the setup to default folder ~/Android and add some additional components (More actions / SDK Manager):
    • SDK Tools / NDK (Side by Side)
    • Android Emulator (should already be enabled in default setup)
    • Android SDK Platform-Tools
  • Create four virtual devices (More actions / Virtual Device Manager), all of them using the Pixel 5 device and the Android Open Source Project system image API level 23 - Android 6 Marshmallow with exactly the names seen in the following screenshot

Android SDK VMs

  • Prepare your shell: export PATH=~/Android/Sdk/ndk/25.2.9519653/toolchains/llvm/prebuilt/linux-x86_64/bin/:$PATH
  • Compile RubiChess using the ndk crosscompiler e.g. make release COMP=ndk or make profile-build ARCH=armv8 COMP=ndk

You may discover several problems when the build process starts the emulator like missing display and several warnings but it should be enough to run the emulator bench and create some profiling data.

Option 3: Just the NDK (example for Windows using Msys2 shell)

This option allows a crosscompilation without profiling, so the resulting binary will be slower than binaries of option 1.

Download and unzip latest NDK from https://developer.android.com/ndk/downloads or install via SDK manager in Android Studio; I'm using 25.1.8937393

Start msys2 shell and create a symbolic link /android for the tool chain folder

$ ln -s /c/Users/andreas/AppData/Local/Android/Sdk/ndk/25.1.8937393/toolchains/llvm/prebuilt/windows-x86_64/ /android

To cross-compile RubiChess for ARM cpu in msys2 shell first add /andoid/bin to your PATH and then set COMP=ndk and ARCH=armv7 resp. ARCH=armv8 in the make command

$ # Windows/MSYS2:
$ export PATH=/android/bin:$PATH
$ # Linux:
$ export PATH=~/Android/Sdk/ndk/25.1.8937393/toolchains/llvm/prebuilt/linux-x86_64/bin:$PATH
$ make COMP=ndk ARCH=armv7

Android Emulator

List VMs: /home/andreas/Android/Sdk/emulator/emulator -list-avds

Cold boot VM: /home/andreas/Android/Sdk/emulator/emulator -avd Android_5.0_API_21_armv8 -no-snapshot-load

Android SDK/NDK in WSL

Download of cmdline tools from https://developer.android.com/studio#command-tools

sudo unzip -d /usr/lib/android-sdk/ /path/to/zip

...

andreas@toenderup:~$ Android/Sdk/cmdline-tools/latest/bin/avdmanager  list avd
Available Android Virtual Devices:
    Name: armv7
  Device: pixel_2 (Google)
    Path: /home/andreas/.android/avd/Pixel_2_API_19_armv7.avd
  Target: 
          Based on: Android 6.0 (Marshmallow) Tag/ABI: default/armeabi-v7a
    Skin: 1080x1920
  Sdcard: 512 MB
---------
    Name: armv8
  Device: pixel_2_xl (Google)
    Path: /home/andreas/.android/avd/Pixel_2_XL_API_21.avd
  Target: 
          Based on: Android 5.0 (Lollipop) Tag/ABI: default/arm64-v8a
    Skin: 1440x2880
  Sdcard: 512 MB
---------
    Name: x86
  Device: pixel (Google)
    Path: /home/andreas/.android/avd/Pixel_API_23.avd
  Target: 
          Based on: Android 6.0 (Marshmallow) Tag/ABI: default/x86
    Skin: 1080x1920
  Sdcard: 512 MB
---------
    Name: x86_64
  Device: pixel (Google)
    Path: /home/andreas/.android/avd/Pixel_API_23_1.avd
  Target: 
          Based on: Android 6.0 (Marshmallow) Tag/ABI: default/x86_64
    Skin: 1080x1920
  Sdcard: 512 MB

No working results yet...