diff --git a/Building-Android.md b/Building-Android.md new file mode 100644 index 00000000..de19c563 --- /dev/null +++ b/Building-Android.md @@ -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`. +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=-linux-android` argument added. +For example: + +```sh +cargo build --target=i686-linux-android +``` diff --git a/Cargo.lock b/Cargo.lock index c832a32e..1881b947 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1540,6 +1540,7 @@ dependencies = [ "leafish_resources", "leafish_shared", "log", + "openssl", "parking_lot", "rand 0.8.4", "rand_pcg 0.3.1", @@ -2121,6 +2122,15 @@ version = "0.1.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "28988d872ab76095a6e6ac88d99b54fd267702734fd7ffe610ca27f533ddb95a" +[[package]] +name = "openssl-src" +version = "111.18.0+1.1.1n" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7897a926e1e8d00219127dc020130eca4292e5ca666dd592480d72c3eca2ff6c" +dependencies = [ + "cc", +] + [[package]] name = "openssl-sys" version = "0.9.66" @@ -2130,6 +2140,7 @@ dependencies = [ "autocfg 1.0.1", "cc", "libc", + "openssl-src", "pkg-config", "vcpkg", ] diff --git a/Cargo.toml b/Cargo.toml index cca075f7..0313dc46 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -74,4 +74,13 @@ version = "0" [dependencies.leafish_protocol] path = "./protocol" -version = "0" \ No newline at end of file +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"] }