-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild-android.sh
More file actions
executable file
·52 lines (42 loc) · 2 KB
/
build-android.sh
File metadata and controls
executable file
·52 lines (42 loc) · 2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#!/bin/bash
# Build Rust FFI library for Android and generate Kotlin bindings
# See ADR-0011 for implementation plan
set -e
# Source Android environment variables
source "$(dirname "$0")/set-android-envs.sh"
# Force rebuild of FFI and its dependencies to pick up engine changes
# (cargo-ndk cross-compilation doesn't always detect dependency changes)
for pkg in markdown-neuraxis-ffi markdown-neuraxis-engine markdown-neuraxis-syntax; do
cargo clean -p "$pkg" --target aarch64-linux-android 2>/dev/null || true
cargo clean -p "$pkg" --target x86_64-linux-android 2>/dev/null || true
done
# Build for arm64 (primary target - modern phones)
echo "Building for aarch64-linux-android (arm64-v8a)..."
cargo ndk -t aarch64-linux-android build --release -p markdown-neuraxis-ffi
# Build for x86_64 (emulator)
echo "Building for x86_64-linux-android (x86_64)..."
cargo ndk -t x86_64-linux-android build --release -p markdown-neuraxis-ffi
# Create jniLibs directory structure
mkdir -p android/app/src/main/jniLibs/arm64-v8a
mkdir -p android/app/src/main/jniLibs/x86_64
# Copy .so files to Android jniLibs
cp target/aarch64-linux-android/release/libmarkdown_neuraxis_ffi.so \
android/app/src/main/jniLibs/arm64-v8a/
cp target/x86_64-linux-android/release/libmarkdown_neuraxis_ffi.so \
android/app/src/main/jniLibs/x86_64/
# Generate Kotlin bindings
# UniFFI creates package structure: uniffi/markdown_neuraxis_ffi/
echo "Generating Kotlin bindings..."
cargo run -p markdown-neuraxis-ffi --bin uniffi-bindgen generate \
--library target/aarch64-linux-android/release/libmarkdown_neuraxis_ffi.so \
--language kotlin \
--out-dir android/app/src/main/java/
# Ensure gradle wrapper exists
if [ ! -f android/gradlew ]; then
echo "Generating gradle wrapper..."
(cd android && gradle wrapper --gradle-version 8.9)
fi
# Build the APK (clean first to ensure native libs are repackaged)
echo "Building APK..."
(cd android && ./gradlew clean assembleDebug)
echo "Done! APK at android/app/build/outputs/apk/debug/app-debug.apk"