|
| 1 | +# Android Build Setup for Tauri on Apple Silicon (M-series chip) |
| 2 | + |
| 3 | +## Overview |
| 4 | +This guide documents how to set up a complete Android development environment for Vector on Apple Silicon (M1/M2/etc) Macs, focusing on resolving common cross-compilation issues with potential Clang linker issues. |
| 5 | + |
| 6 | +## Prerequisites |
| 7 | + |
| 8 | +It is ideal that you first attempt a native compile (`npm run tauri dev`), ensuring that Vector builds and runs successfully natively, first and foremost; prior to moving on to cross-compiling. |
| 9 | + |
| 10 | +### 1. Install Android Studio |
| 11 | +Download and install from [developer.android.com](https://developer.android.com/studio) |
| 12 | + |
| 13 | +### 2. Install Homebrew packages |
| 14 | +```bash |
| 15 | +# Install Java |
| 16 | +brew install openjdk@17 |
| 17 | +sudo ln -sfn /opt/homebrew/opt/openjdk@17/libexec/openjdk.jdk /Library/Java/JavaVirtualMachines/openjdk-17.jdk |
| 18 | + |
| 19 | +# Install Android NDK |
| 20 | +brew install --cask android-ndk |
| 21 | +``` |
| 22 | + |
| 23 | +### 3. Install Rust Android targets |
| 24 | +```bash |
| 25 | +rustup target add aarch64-linux-android |
| 26 | +rustup target add armv7-linux-androideabi |
| 27 | +rustup target add x86_64-linux-android |
| 28 | +rustup target add i686-linux-android |
| 29 | +``` |
| 30 | + |
| 31 | +## Environment Configuration |
| 32 | + |
| 33 | +### 1. Set up environment variables |
| 34 | +Add to `~/.zshrc`: |
| 35 | + |
| 36 | +```bash |
| 37 | +# Android Development Environment for Tauri |
| 38 | +export ANDROID_HOME="$HOME/Library/Android/sdk" |
| 39 | +export NDK_HOME="/opt/homebrew/Caskroom/android-ndk/28b/AndroidNDK13356709.app/Contents/NDK" |
| 40 | +export JAVA_HOME=$(/usr/libexec/java_home) |
| 41 | +export PATH="$NDK_HOME/toolchains/llvm/prebuilt/darwin-x86_64/bin:$PATH" |
| 42 | +export PATH="$PATH:$ANDROID_HOME/platform-tools" |
| 43 | +export PATH="$PATH:$ANDROID_HOME/cmdline-tools/latest/bin" |
| 44 | +export PATH="$PATH:$ANDROID_HOME/emulator" |
| 45 | +``` |
| 46 | + |
| 47 | +Reload your environment: |
| 48 | +```bash |
| 49 | +source ~/.zshrc |
| 50 | +``` |
| 51 | + |
| 52 | +## Fixing Cross-Compilation Issues |
| 53 | + |
| 54 | +### 1. Create missing NDK tool symlinks |
| 55 | +```bash |
| 56 | +cd $NDK_HOME/toolchains/llvm/prebuilt/darwin-x86_64/bin/ |
| 57 | +sudo ln -sf llvm-ranlib aarch64-linux-android-ranlib |
| 58 | +sudo ln -sf llvm-ar aarch64-linux-android-ar |
| 59 | +``` |
| 60 | + |
| 61 | +### 2. Fix AAudio linking issue |
| 62 | +The linker may fail to find AAudio (used by Vector Voice) when using API level 24. Create wrapper scripts to force API level 26+ in the Tauri Build System: |
| 63 | + |
| 64 | +```bash |
| 65 | +cd $NDK_HOME/toolchains/llvm/prebuilt/darwin-x86_64/bin/ |
| 66 | + |
| 67 | +# Create wrapper for clang |
| 68 | +sudo tee aarch64-linux-android24-clang << 'EOF' |
| 69 | +#!/bin/bash |
| 70 | +exec "$(dirname "$0")/aarch64-linux-android26-clang" "$@" |
| 71 | +EOF |
| 72 | +sudo chmod +x aarch64-linux-android24-clang |
| 73 | + |
| 74 | +# Create wrapper for clang++ |
| 75 | +sudo tee aarch64-linux-android24-clang++ << 'EOF' |
| 76 | +#!/bin/bash |
| 77 | +exec "$(dirname "$0")/aarch64-linux-android26-clang++" "$@" |
| 78 | +EOF |
| 79 | +sudo chmod +x aarch64-linux-android24-clang++ |
| 80 | +``` |
| 81 | + |
| 82 | +## Building Your App |
| 83 | + |
| 84 | +### Development build with Android Studio emulator |
| 85 | + |
| 86 | +You'll need to be running an emulation device before performing the build, as such, please ensure **Android Studio** is open, click **More Actions** in the **Projects** tab, open **Virtual Device Manager**, and launch a device, once it's fully booted, you can continue building. |
| 87 | + |
| 88 | +```bash |
| 89 | +npm run tauri android dev --open |
| 90 | +``` |
| 91 | + |
| 92 | +### Release build |
| 93 | + |
| 94 | +To be able to install the APK, you'll need to Sign the APK, please follow the [Tauri v2 Android Signing documentation](https://tauri.app/distribute/sign/android/) to configure APK signing, it is possible to self-sign, making the process fairly straightforward. |
| 95 | + |
| 96 | +All signing code and configuration edits have already been applied to the Vector Android files, as such, **you only need to add your Keystore file to complete the signing process.** |
| 97 | + |
| 98 | +```bash |
| 99 | +# Build an APK for a specific architecture (aarch64 is the standard at >95% adoption, thus, the recommended APK arch) |
| 100 | +npm run tauri android build -- --apk --target aarch64 |
| 101 | + |
| 102 | +# Build an APK for all architectures (bulky binary, not recommended) |
| 103 | +npm run tauri android build -- --apk |
| 104 | +``` |
| 105 | + |
| 106 | +## Troubleshooting |
| 107 | + |
| 108 | +### Verify environment setup |
| 109 | +```bash |
| 110 | +echo "ANDROID_HOME: $ANDROID_HOME" |
| 111 | +echo "NDK_HOME: $NDK_HOME" |
| 112 | +echo "JAVA_HOME: $JAVA_HOME" |
| 113 | +which aarch64-linux-android-ranlib |
| 114 | +``` |
| 115 | + |
| 116 | +### Clean build if issues persist |
| 117 | +```bash |
| 118 | +cd src-tauri && cargo clean |
| 119 | +``` |
| 120 | + |
| 121 | +## Key Takeaways |
| 122 | + |
| 123 | +1. **OpenSSL vendoring**: Essential for cross-compilation - the `vendored` feature compiles OpenSSL from source for the target architecture |
| 124 | +2. **NDK toolchain path**: Must be in PATH for build tools to find `ranlib`, `ar`, etc. |
| 125 | +3. **API level consistency**: AAudio requires API 26+, so force this even when build system requests API 24 (due to Tauri bug?) |
| 126 | +4. **M1 compatibility**: Use `darwin-x86_64` NDK binaries - they work fine via Rosetta 2 |
| 127 | + |
| 128 | +## Success Indicators |
| 129 | +- ✅ No "archive member is neither ET_REL nor LLVM bitcode" warnings |
| 130 | +- ✅ No "unable to find library -laaudio" errors |
| 131 | +- ✅ `android dev` runs in Android Studio emulator |
| 132 | +- ✅ `android build` produces APKs easily installable on physical Android phones |
| 133 | + |
| 134 | +--- |
| 135 | + |
| 136 | +*This setup was tested on MacBook Air M1 with Tauri v2.5.1, targeting Android API 26* |
0 commit comments