Skip to content

Commit

Permalink
WIP: document and enable building for Android
Browse files Browse the repository at this point in the history
Currently this fails because of an Android incompatibility in glutin:
rust-windowing/glutin#1307
rust-windowing/glutin#1313
  • Loading branch information
PureTryOut committed Jul 1, 2022
1 parent d4ed949 commit 9bb67fc
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 1 deletion.
58 changes: 58 additions & 0 deletions Building-Android.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# Building Leafish for Android

This guide assumes a Linux host using glibc (most distributions).

## Install the Android NDK

You can either download the NDK directly, or use the Android SDK tools to manage your NDK's.
The latter has the benefit of being able to keep your NDK up-to-date relatively easy.

### Download the NDK directly

The NDK can be downloaded from [the Android developer site](https://developer.android.com/ndk/downloads/).
Download the Linux package and unzip it somewhere, we'll use `~/.android` as the target directory in this guide.

The eventual path will then be `~/.android/android-ndk-r<version>`.
To finish up, export that path as `$NDK_HOME`, so for example `export NDK_HOME=~/.android/android-ndk-r23`.

### Android SDK tools

Download either Android Studio or the Android command line tools from [here](https://developer.android.com/studio/#downloads).
Since you probably won't use the editor, this guide will use the command line tools.

Create a directory `~/.android/cmdline-tools` and unzip the downloaded archive to there.
Rename the unzip directory to `latest`, so the ending path will be `~/.android/cmdline-tools/latest` which includes the `bin` and `lib` directories.

Use the sdkmanager to install the `ndk-bundle`:

```sh
~/.android/cmdline-tools/latest/bin/sdkmanager install ndk-bundle
```

To finish up, export the installed NDK as `$NDK_HOME`, so for example `export NDK_HOME=~/.android/ndk-bundle/`.

### Configure Rust and Cargo

Using `rustup`, install the Android target for which you want to build:

```sh
rustup target add armv7-linux-android aarch64-linux-android i686-linux-android
```

Then we have to tell Cargo what cross-compiler to use depending on what platform we want to target.
For example for a x86 Android device:

```sh
export CC="$NDK_HOME/toolchains/llvm/prebuilt/linux-x86_64/bin/i686-linux-android30-clang"
```

When building for `aarch64` replace `i686` for `aarch64`, and for `armv7` replace it for `armv7a`.

### Building

Invoke Cargo as usual but with the `--target=<target>-linux-android` argument added.
For example:

```sh
cargo build --target=i686-linux-android
```
11 changes: 11 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 10 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -74,4 +74,13 @@ version = "0"

[dependencies.leafish_protocol]
path = "./protocol"
version = "0"
version = "0"

[target.i686-linux-android.dependencies]
openssl = { version = "*", features = ["vendored"] }

[target.armv7a-linux-android.dependencies]
openssl = { version = "*", features = ["vendored"] }

[target.aarch64-linux-android.dependencies]
openssl = { version = "*", features = ["vendored"] }

0 comments on commit 9bb67fc

Please sign in to comment.