Skip to content

Instantly share code, notes, and snippets.

@CompeyDev
Created September 30, 2023 17:34
Show Gist options
  • Save CompeyDev/7852bf43d6bcb49b4c5bb6442fccbe65 to your computer and use it in GitHub Desktop.
Save CompeyDev/7852bf43d6bcb49b4c5bb6442fccbe65 to your computer and use it in GitHub Desktop.
A guide to compiling lune for Android (to be ran with termux).

Note

This guide assumes that you're building for aarch64-linux-android only, but a similar approach should apply to other CPU architectures too.

To build and run lune for android, you need to do the following:

  • Set up your cargo config:
[target.aarch64-linux-android]
ar = "$ANDROID_NDK_HOME/toolchains/llvm/prebuilt/linux-x86_64/bin/aarch64-linux-android-ar"
rustflags = ["-C", "linker=aarch64-linux-android-clang", "-C", "link-args=-rdynamic", "-C", "default-linker-libraries"]
linker = "$ANDROID_NDK_HOME/toolchains/llvm/prebuilt/linux-x86_64/bin/aarch64-linux-android-clang"
  • The latest android NDK has paths different from those that cargo expects, so we need to create the following symlinks:

    • $ANDROID_NDK_HOME/toolchains/llvm/prebuilt/linux-x86_64/bin/llvm-ar -> aarch64-linux-android-ar
    • $ANDROID_NDK_HOME/toolchains/llvm/prebuilt/linux-x86_64/bin/aarch64-linux-android33-clang -> aarch64-linux-android-clang
  • Make sure that $ANDROID_NDK_HOME/toolchains/llvm/prebuilt/linux-x86_64/bin is in your path.

  • Build the binary:

cargo build --release --target aarch64-linux-android
  • The compiled output can be found at: ./target/aarch64-linux-android/release/lune

  • To run lune, we'll need libc++ for the linker as libc is always linked dynamically by cargo. We can find the library at $ANDROID_NDK_HOME/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/lib/aarch64-linux-android/libc++_shared.so.

  • On android, store the libc++_shared.so file at $PREFIX/lib/libc++_shared.so.

  • Add the $PREFIX/lib to LD_LIBRARY_PATH.

export LD_LIBRARY_PATH=$PREFIX/lib
  • Run lune.
  • Profit?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment