Skip to content

feat: Add Android platform release targets with integrated JNI support #1145

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions c_api/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ serde_json = "1.0"
thiserror = "1.0.64"
zip = { version = "3.0.0", default-features = false, features = ["deflate"] }

[target.'cfg(target_os = "android")'.dependencies]
jni = { version = "0.21", optional = false }

[dev-dependencies]
tempfile = "3.7.0"

Expand Down
42 changes: 42 additions & 0 deletions c_api/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,48 @@ release-linux-gnu-arm:
cargo build --target=aarch64-unknown-linux-gnu $(CARGO_BUILD_FLAGS)
@$(call make_zip,$(TARGET_DIR)/aarch64-unknown-linux-gnu/release,aarch64-unknown-linux-gnu)


##Android NDK needs to be in your environment
##export ANDROID_NDK_HOME=${NDK_HOME} // https://developer.android.com/ndk
##we currently recommend: android-ndk-r26d

release-android: release-android-arm64 release-android-x86_64

release-android-arm64: android-install-deps
rustup target add aarch64-linux-android
RUSTFLAGS='-C link-arg=-s' cargo ndk -t arm64-v8a build $(CARGO_BUILD_FLAGS)
@$(call make_zip,$(TARGET_DIR)/aarch64-linux-android/release,aarch64-linux-android)

release-android-x86_64: android-install-deps
rustup target add x86_64-linux-android
RUSTFLAGS='-C link-arg=-s' cargo ndk -t x86_64 build $(CARGO_BUILD_FLAGS)
@$(call make_zip,$(TARGET_DIR)/x86_64-linux-android/release,x86_64-linux-android)

cache/ndk/android-ndk-r26d: cache/ndk.zip
unzip -n -d cache/ndk cache/ndk.zip
touch cache/ndk.zip #MacOS' unzip might delete the zip file, so recreate an empty file to calm make.

cache/ndk.zip:
mkdir -p cache

ifeq ($(OS),Windows_NT)
wget https://dl.google.com/android/repository/android-ndk-r26d-windows.zip -O $@
else ifeq ($(shell uname), Linux)
wget https://dl.google.com/android/repository/android-ndk-r26d-linux.zip -O $@
else ifeq ($(shell uname), Darwin)
wget https://dl.google.com/android/repository/android-ndk-r26d-darwin.zip -O $@
else
@echo "No NDK found for your system, please download it by yourself."
@false
endif

android-install-deps: cache/ndk/android-ndk-r26d cargo-ndk

cargo-ndk:
ifeq ($(shell command -v cargo-ndk),)
cargo install cargo-ndk
endif

# make release
# Builds and packages a zip for c_api for each platform
ifeq ($(PLATFORM), mac)
Expand Down
Loading
Loading