name: Android NDK Build

on:
  pull_request:
    branches: [ dev, release, actionsTest ]
  push:
    branches: [ actionsTest, '*ndk*' ]

permissions: read-all

jobs:
  build:
    runs-on: ubuntu-latest

    steps:
    - uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # tag=v5.0.0

    - name: Set up JDK 17
      uses: actions/setup-java@c5195efecf7bdfc987ee8bae7a71cb8b11521c00 # v4.7.1
      with:
        java-version: '17'
        distribution: 'temurin'

    - name: Setup Android SDK
      uses: android-actions/setup-android@9fc6c4e9069bf8d3d10b2204b1fb8f6ef7065407 # v3.2.2

    - name: Install Android NDK
      run: |
        sdkmanager --install "ndk;27.0.12077973"
        echo "ANDROID_NDK_HOME=$ANDROID_SDK_ROOT/ndk/27.0.12077973" >> $GITHUB_ENV

    - name: Build with NDK
      run: |
        export PATH=$ANDROID_NDK_HOME/toolchains/llvm/prebuilt/linux-x86_64/bin:$PATH
        make CC=aarch64-linux-android21-clang \
             AR=llvm-ar \
             RANLIB=llvm-ranlib \
             STRIP=llvm-strip

    - name: Build with CMake and NDK
      run: |
        mkdir -p build-android
        cd build-android
        cmake --version
        cmake ../build/cmake \
          -DCMAKE_TOOLCHAIN_FILE=$ANDROID_NDK_HOME/build/cmake/android.toolchain.cmake \
          -DANDROID_ABI=arm64-v8a \
          -DANDROID_PLATFORM=android-21 \
          -DCMAKE_BUILD_TYPE=Release
        cmake --build . --parallel
