OXYGENHUB
# e955ae0c1342 oxygenhub-android / scripts / build_rust.sh
1.2 KiB · Bourne Again Shell (bash) · executable · last changed Android: Hook up Rust FFI greeting to Compose UI 1 month ago source blame history raw
1
#!/usr/bin/env bash
2
set -e
3
4
echo "=== 🦀 Building Oxygen Rust Core for Android ==="
5
6
# Check if cargo-ndk is installed
7
if ! command -v cargo-ndk &> /dev/null; then
8
    echo "Installing cargo-ndk (Android build helper)..."
9
    cargo install cargo-ndk
10
fi
11
12
# Ensure Android targets are installed
13
echo "Adding Rust Android targets..."
14
rustup target add aarch64-linux-android armv7-linux-androideabi x86_64-linux-android
15
16
# Ensure NDK is set
17
if [ -z "$ANDROID_NDK_HOME" ]; then
18
    echo "⚠️ ANDROID_NDK_HOME is not set!"
19
    echo "Please set it to your NDK path, e.g.:"
20
    echo "export ANDROID_NDK_HOME=\$HOME/Android/Sdk/ndk/27.x.x.x"
21
    exit 1
22
fi
23
24
cd rust-core
25
26
echo "Building shared libraries using cargo-ndk..."
27
# Build for all common Android architectures and output to the JNI libs folder
28
cargo ndk -t armeabi-v7a -t arm64-v8a -t x86_64 -o ../app/src/main/jniLibs build --release
29
30
echo "Generating Kotlin bindings using uniffi-bindgen..."
31
# Use uniffi-bindgen to generate Kotlin files
32
cargo run --features=uniffi/cli --bin uniffi-bindgen generate \
33
    --library ../app/src/main/jniLibs/arm64-v8a/librust_core.so \
34
    --language kotlin \
35
    --out-dir ../app/src/main/java
36
37
echo "✅ Rust build complete! The JNI libraries and Kotlin bindings are ready."