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.

Revisions

  1. CompeyDev created this gist Sep 30, 2023.
    39 changes: 39 additions & 0 deletions lune_for_android.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,39 @@
    > [!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:

    ```toml
    [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:

    ```sh
    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.

    ```sh
    export LD_LIBRARY_PATH=$PREFIX/lib
    ```

    - Run lune.
    - Profit?