name: build-android
on:
  schedule:
    - cron: '0 0 * * *'
#on:
#  push:
#    branches:
#      - master

env:
  QT_VERSION: 6.5.3
  QT_MODULES: 'qtcharts qtserialbus qtserialport qtwebsockets'
jobs:
  build:
    name: Build for Android
    runs-on: windows-2019
    steps:
      - name: Checkout
        uses: actions/checkout@v3
      - name: Install Qt for Android
        uses: jurplel/install-qt-action@v3
        with:
          target: android
          arch: android_armv7
          host: windows
          dir: ${{ github.workspace }}
          modules: ${{env.QT_MODULES}}
          version: ${{env.QT_VERSION}}
      - name: Install Qt for Desktop(mingw)
        uses: jurplel/install-qt-action@v3
        with:
          target: desktop
          arch: win64_mingw
          host: windows
          dir: ${{ github.workspace }}
          modules: ${{env.QT_MODULES}}
          version: "${{env.QT_VERSION}}"
      - name: CMake for Android
        shell: cmd
        run: |
          set JAVA_HOME=%JAVA_HOME_11_X64%
          ${{ github.workspace }}\Qt\${{env.QT_VERSION}}\android_armv7\bin\qt-cmake.bat ^
          -G "MinGW Makefiles" ^
          -S . ^
          -B "build\armeabi_v7a" ^
          -DQT_HOST_PATH:PATH="${{ github.workspace }}\Qt\${{env.QT_VERSION}}\mingw_64" ^
          -DCMAKE_BUILD_TYPE:STRING=Release ^
          -DCMAKE_CXX_COMPILER:FILEPATH="%ANDROID_NDK_ROOT%/toolchains/llvm/prebuilt/windows-x86_64/bin/clang++.exe" ^
          -DANDROID_SDK_ROOT:PATH="%ANDROID_SDK_ROOT%" ^
          -DANDROID_NDK_ROOT:PATH="%ANDROID_NDK_ROOT%" ^
          -DBUILD_SHARED_LIBS:BOOL=OFF
      - name: Directory of build\armeabi_v7a
        shell: cmd
        run: dir build\armeabi_v7a
      - name: Build for android
        shell: cmd
        run: |
          set JAVA_HOME=%JAVA_HOME_11_X64%
          echo %JAVA_HOME%
          cmake --build build\armeabi_v7a --target QtSwissArmyKnife --config Release
      - name: Directory of build\armeabi_v7a
        shell: cmd
        run: dir build\armeabi_v7a
      - name: Deploy for Android
        shell: cmd
        run: |
          set JAVA_HOME=%JAVA_HOME_11_X64%
          echo %JAVA_HOME%
          ${{ github.workspace }}\Qt\${{env.QT_VERSION}}\mingw_64\bin\androiddeployqt.exe ^
          --input build\armeabi_v7a\android-QtSwissArmyKnife-deployment-settings.json ^
          --output build\armeabi_v7a\android-build ^
          --android-platform android-34 ^
          --sign ${{ github.workspace }}\resources\android\android_release.keystore QtSwissArmyKnife --storepass QtSwissArmyKnife --keypass QtSwissArmyKnife ^
          --jdk %JAVA_HOME% --gradle --release
