| 1 |
on: |
| 2 |
push: |
| 3 |
branches: |
| 4 |
- master |
| 5 |
pull_request: |
| 6 |
branches: |
| 7 |
- master |
| 8 |
|
| 9 |
name: android |
| 10 |
|
| 11 |
env: |
| 12 |
NDK_VERSION: "r26d" |
| 13 |
ANDROID_VERSION: "12.0.0" |
| 14 |
|
| 15 |
jobs: |
| 16 |
build: |
| 17 |
runs-on: ubuntu-latest |
| 18 |
timeout-minutes: 30 |
| 19 |
steps: |
| 20 |
- uses: actions/checkout@v4 |
| 21 |
- uses: dtolnay/rust-toolchain@stable |
| 22 |
with: |
| 23 |
targets: x86_64-linux-android |
| 24 |
- name: Setup Android Environment |
| 25 |
run: | |
| 26 |
NDK_URL="https://dl.google.com/android/repository/android-ndk-${NDK_VERSION}-linux.zip" |
| 27 |
NDK_DIR="${HOME}/android-ndk-${NDK_VERSION}" |
| 28 |
|
| 29 |
# Download and extract NDK |
| 30 |
echo "Downloading NDK from $NDK_URL" |
| 31 |
wget -q "$NDK_URL" -O android-ndk.zip |
| 32 |
unzip -q android-ndk.zip -d "$HOME" |
| 33 |
|
| 34 |
# Set ANDROID_NDK_ROOT environment variable |
| 35 |
echo "ANDROID_NDK_ROOT=$NDK_DIR" >> $GITHUB_ENV |
| 36 |
|
| 37 |
# Setup & start redroid container |
| 38 |
sudo apt-get install -y linux-modules-extra-$(uname -r) android-tools-adb |
| 39 |
sudo modprobe binder_linux devices=binder,hwbinder,vndbinder |
| 40 |
|
| 41 |
docker run -itd --rm --privileged \ |
| 42 |
--mount "type=bind,src=$(pwd),dst=/data/host$(pwd),ro" \ |
| 43 |
--mount "type=bind,src=/tmp,dst=/data/host/tmp,ro" \ |
| 44 |
--mount "type=bind,src=$(pwd)/.github/workflows/run-on-host.sh,dst=/system/xbin/run-on-host,ro" \ |
| 45 |
--name redroid-test \ |
| 46 |
-p 5555:5555 \ |
| 47 |
redroid/redroid:${ANDROID_VERSION}_64only-latest |
| 48 |
|
| 49 |
# Start ADB server and connect to our redroid container |
| 50 |
adb start-server |
| 51 |
timeout 60 bash -c 'until adb connect localhost:5555; do sleep 2; done' |
| 52 |
|
| 53 |
# Configure Android environment |
| 54 |
echo "CARGO_TARGET_X86_64_LINUX_ANDROID_RUNNER=adb -s localhost:5555 shell run-on-host" >> $GITHUB_ENV |
| 55 |
echo "CC_X86_64_linux_android=$NDK_DIR/toolchains/llvm/prebuilt/linux-x86_64/bin/x86_64-linux-android34-clang" >> $GITHUB_ENV |
| 56 |
echo "AR_x86_64_linux_android=$NDK_DIR/toolchains/llvm/prebuilt/linux-x86_64/bin/llvm-ar" >> $GITHUB_ENV |
| 57 |
echo "CARGO_TARGET_X86_64_LINUX_ANDROID_LINKER=$NDK_DIR/toolchains/llvm/prebuilt/linux-x86_64/bin/x86_64-linux-android34-clang" >> $GITHUB_ENV |
| 58 |
echo "CARGO_TARGET_AARCH64_LINUX_ANDROID_RUSTFLAGS=-C link-arg=-Wl,--as-needed" >> $GITHUB_ENV |
| 59 |
- run: cargo build --verbose --target x86_64-linux-android |
| 60 |
- run: cargo test --verbose --target x86_64-linux-android -- --nocapture |
| 61 |
- name: Stop the redroid container |
| 62 |
run: docker stop redroid-test || true |