name: Android

on:
  push:
    branches:
      - master

jobs:
  build:
    name: GPXSee
    runs-on: ubuntu-latest
    steps:
      - name: Checkout
        uses: actions/checkout@v7
      - name: set up JDK
        uses: actions/setup-java@v5
        with:
          distribution: 'temurin'
          java-version: '17'
      - name: Setup Android SDK
        uses: android-actions/setup-android@v4
      - name: Install android platform, build-tools and ndk
        run:  ${ANDROID_HOME}/cmdline-tools/latest/bin/sdkmanager --install "platforms;android-36" "build-tools;36.0.0" "ndk;27.2.12479018"
      - name: Setup NDK path
        run: echo "ANDROID_NDK_ROOT=${ANDROID_HOME}/ndk/27.2.12479018/" >> $GITHUB_ENV
      - name: Install Qt (Desktop)
        uses: jurplel/install-qt-action@v4
        with:
          version: '6.11.1'
      - name: Install Qt (Android)
        uses: jurplel/install-qt-action@v4
        with:
          version: '6.11.1'
          target: 'android'
          arch: 'android_arm64_v8a'
          modules: qtimageformats qtpositioning qtserialport qtmultimedia qt5compat
      - name: Install Android OpenSSL
        run:  git clone https://github.com/KDAB/android_openssl.git
      - name: Create localization
        run:  lrelease-pro gpxsee.pro
      - name: Configure build
        run:  qmake gpxsee.pro OPENSSL_PATH=android_openssl
      - name: Build project
        run:  make -j4 apk
      - name: Upload artifacts
        uses: actions/upload-artifact@v7
        with:
          name: GPXSee-arm64_v8a.apk
          path: android-build/build/outputs/apk/debug/android-build-debug.apk
          archive: false
