steps:
- task: PowerShell@2
  displayName: Install CMake 3.18.6
  inputs:
    targetType: 'inline'
    script: |
      # Download specific version of CMake
      $ToolsDirectory = Join-Path -Path $Env:BUILD_SOURCESDIRECTORY -ChildPath tools
      $CMakeZipFile = Join-Path $ToolsDirectory -ChildPath cmake.zip

      Invoke-WebRequest -Uri "https://cmake.org/files/v3.18/cmake-3.18.6-win64-x64.zip" -OutFile $CMakeZipFile
      New-Item -Path $ToolsDirectory -Name "cmake" -ItemType "directory"
      Expand-Archive -Path $CMakeZipFile -DestinationPath $ToolsDirectory/cmake
      Copy-Item -Path $ToolsDirectory/cmake/cmake-3.18.6-win64-x64/* -Destination "c:/Program Files/CMake" -Recurse -Force

- task: CMake@1
  displayName: Verify CMake version
  inputs:
    workingDirectory: '$(Build.SourcesDirectory)'
    cmakeArgs: '--version'

- task: PowerShell@2
  displayName: Download Ninja
  inputs:
    targetType: 'inline'
    script: |
      # Download Ninja
      $ToolsDirectory = Join-Path -Path $Env:BUILD_SOURCESDIRECTORY -ChildPath tools
      $NinjaZipFile = Join-Path $ToolsDirectory -ChildPath ninja.zip
      $NinjaExeFile = Join-Path $ToolsDirectory -ChildPath ninja.exe

      Invoke-WebRequest -Uri "https://github.com/ninja-build/ninja/releases/download/v1.10.0/ninja-win.zip" -OutFile $NinjaZipFile
      Expand-Archive -Path $NinjaZipFile -DestinationPath $ToolsDirectory
      Copy-Item -Path $NinjaExeFile -Destination "c:/Program Files/CMake/bin"

- task: CmdLine@2
  displayName: Update NDK
  inputs:
    script: |
      echo Android home: %ANDROID_SDK_ROOT%
      "%ANDROID_SDK_ROOT%/tools/bin/sdkmanager" --install "ndk;22.1.7171670"

- task: Gradle@2
  displayName: Compile Android Native Libraries
  inputs:
    workingDirectory: '$(Build.SourcesDirectory)/android'
    gradleWrapperFile: '$(Build.SourcesDirectory)/android/gradlew'
    gradleOptions: ''
    options: '--stacktrace --no-parallel'
    publishJUnitResults: false
    testResultsFiles: '**/TEST-*.xml'
    tasks: 'compileReleaseSources'

- task: CopyFiles@2
  displayName: Copy files to staging directory
  inputs:
    SourceFolder: '$(Build.SourcesDirectory)/android/app/.cxx/cmake/release/arm64-v8a/lib/arm64-v8a'
    Contents: 'libsealc.so'
    TargetFolder: '$(Build.ArtifactStagingDirectory)/lib/arm64-v8a'

- task: CopyFiles@2
  displayName: Copy files to staging directory
  inputs:
    SourceFolder: '$(Build.SourcesDirectory)/android/app/.cxx/cmake/release/x86_64/lib/x86_64'
    Contents: 'libsealc.so'
    TargetFolder: '$(Build.ArtifactStagingDirectory)/lib/x86_64'

- task: PublishBuildArtifacts@1
  displayName: Publish build artifacts
  inputs:
    PathtoPublish: '$(Build.ArtifactStagingDirectory)'
    ArtifactName: ${{ parameters.artifactName }}
