Skip to content

Commit

Permalink
refactor: allow specifying target arch in Android build script (#383)
Browse files Browse the repository at this point in the history
Fixes #375
  • Loading branch information
maelchiotti authored Jan 4, 2025
1 parent 4c13a5a commit 3033b16
Showing 1 changed file with 33 additions and 21 deletions.
54 changes: 33 additions & 21 deletions scripts/build-android.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,33 +3,45 @@
# Setup
BUILD_DIR=platform-build
mkdir $BUILD_DIR
cd $BUILD_DIR
cd $BUILD_DIR || exit

# Create the jniLibs build directory
JNI_DIR=jniLibs
mkdir -p $JNI_DIR

# Set up cargo-ndk
cargo install cargo-ndk
cargo install cargo-ndk --locked

# Add targets
rustup target add \
aarch64-linux-android \
armv7-linux-androideabi \
x86_64-linux-android \
i686-linux-android
aarch64-linux-android \
armv7-linux-androideabi \
x86_64-linux-android \
i686-linux-android

# Build the android libraries in the jniLibs directory
cargo ndk -o $JNI_DIR \
--manifest-path ../Cargo.toml \
-t armeabi-v7a \
-t arm64-v8a \
-t x86 \
-t x86_64 \
build --release

# Archive the dynamic libs
cd $JNI_DIR
tar -czvf ../EmbeddedMilliAndroid.tar.gz *
cd -

# Cleanup
rm -rf $JNI_DIR
if [ "$#" -eq 0 ]; then
cargo ndk -o $JNI_DIR \
--manifest-path ../Cargo.toml \
-t armeabi-v7a \
-t arm64-v8a \
-t x86 \
-t x86_64 \
build --release
# Archive the dynamic libs
cd $JNI_DIR || exit
tar -czvf ../EmbeddedMilliAndroid.tar.gz ./*
cd - || exit
# Cleanup
rm -rf $JNI_DIR
elif [ "$1" = "x86" ]; then
cargo ndk -o $JNI_DIR --manifest-path ../Cargo.toml -t x86 build --release
elif [ "$1" = "x64" ]; then
cargo ndk -o $JNI_DIR --manifest-path ../Cargo.toml -t x86_64 build --release
elif [ "$1" = "armv7" ]; then
cargo ndk -o $JNI_DIR --manifest-path ../Cargo.toml -t armeabi-v7a build --release
elif [ "$1" = "arm64" ]; then
cargo ndk -o $JNI_DIR --manifest-path ../Cargo.toml -t arm64-v8a build --release
else
echo "Invalid architecture: '$1'"
fi

0 comments on commit 3033b16

Please sign in to comment.