#!/usr/bin/env bash # Builds tethercore for Android and drops the artifacts the Gradle app needs: # - libtethercore.so per ABI → app/src/main/jniLibs// # - Kotlin bindings → app/src/main/java/uniffi/tethercore/ # # Requires the Android NDK + cargo-ndk (cargo install cargo-ndk) and # ANDROID_NDK_HOME pointing at the NDK. Outputs are git-ignored. set -euo pipefail cd "$(dirname "$0")" APP="../android/app/src/main" ABIS=(arm64-v8a x86_64) # Optional Cargo features, e.g. TETHER_FEATURES=iroh-transport for the iroh core. # Plain string (not an array) for macOS bash 3.2 + `set -u`. FEATURES="${TETHER_FEATURES:-}" FEAT_ARGS="" [ -n "$FEATURES" ] && FEAT_ARGS="--features $FEATURES" && echo "▸ features: $FEATURES" if ! command -v cargo-ndk >/dev/null; then echo "missing cargo-ndk → cargo install cargo-ndk; also install the Android NDK and set ANDROID_NDK_HOME" >&2 exit 1 fi echo "▸ building .so for ${ABIS[*]}…" rustup target add aarch64-linux-android x86_64-linux-android >/dev/null 2>&1 || true # shellcheck disable=SC2086 # intentional word-split of FEAT_ARGS cargo ndk -t arm64-v8a -t x86_64 -o "$APP/jniLibs" build --release $FEAT_ARGS echo "▸ generating Kotlin bindings…" # shellcheck disable=SC2086 cargo build --release --lib $FEAT_ARGS cargo run --release --bin uniffi-bindgen -- \ generate --library target/release/libtethercore.dylib \ --language kotlin --out-dir "$APP/java" echo "✅ done — open ../android in Android Studio (or ./gradlew :app:assembleDebug)."