46 lines
1.5 KiB
Bash
46 lines
1.5 KiB
Bash
#!/usr/bin/env bash
|
|
set -euo pipefail
|
|
|
|
# Cross-platform helper for Unix-like shells
|
|
ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
|
|
cd "$ROOT"
|
|
|
|
echo "Preparing Android assets and native libs..."
|
|
|
|
if command -v npm >/dev/null 2>&1; then
|
|
echo "Running npm install & build"
|
|
npm install
|
|
npm run build || true
|
|
fi
|
|
|
|
DIST_DIR="dist"
|
|
if [ ! -d "$DIST_DIR" ]; then DIST_DIR="build"; fi
|
|
if [ -d "$DIST_DIR" ]; then
|
|
echo "Copying $DIST_DIR -> android/app/src/main/assets"
|
|
mkdir -p android/app/src/main/assets
|
|
rsync -a --delete "$DIST_DIR/" android/app/src/main/assets/
|
|
else
|
|
echo "No dist/build found, copying src/ -> android assets"
|
|
mkdir -p android/app/src/main/assets
|
|
rsync -a --delete src/ android/app/src/main/assets/
|
|
fi
|
|
|
|
if command -v cargo-ndk >/dev/null 2>&1; then
|
|
echo "Building native libs with cargo-ndk"
|
|
cargo-ndk -t aarch64 -t armv7 build --release || true
|
|
# copy so files
|
|
find target -type f -name "*.so" | while read -r f; do
|
|
if [[ "$f" =~ aarch64|aarch64-linux-android ]]; then abi=arm64-v8a; fi
|
|
if [[ "$f" =~ armv7|armv7-linux-androideabi ]]; then abi=armeabi-v7a; fi
|
|
if [ -n "${abi-}" ]; then
|
|
mkdir -p android/app/src/main/jniLibs/$abi
|
|
cp "$f" android/app/src/main/jniLibs/$abi/
|
|
echo "Copied $f -> android/app/src/main/jniLibs/$abi/"
|
|
fi
|
|
done
|
|
else
|
|
echo "cargo-ndk not found; skipping native lib build"
|
|
fi
|
|
|
|
echo "Prepared Android project. Open android/ in Android Studio to build the APK (or run ./gradlew assembleDebug)."
|