Search code examples
azure-devopsxamarin.androidyamlpipeline

Azure Pipeline Build fails in VSBuild@1 task displaying Error XA5207: Could not find android.jar for API level 29. The script was working fine before


I have to deploy a new nuget package for an existing Xamarin application(while the .Net Maui migration is still on-going). Anyhow the pipeline was working fine until last December 2023. In the VSBuild@1, it is looking for API level 29 which was installed fine in our project.

This is the script:

variables:  
  NugetVersion: 6.4.0
  BuildConfiguration: Release
  RestoreSolution: src/App.Core.sln
  MONO_VERSION: 6_12_0
  XCODE_VERSION: 13.2.1
  MACOS_VERSION: macOS-11
#Source: https://github.com/actions/runner-images/blob/main/images/macos/macos-11-Readme.md#xamarin
#Update macOS 10.15: https://github.com/actions/runner-images/issues/5583

jobs: 
- job: build_android
  displayName: Build Android Library
  pool:
    vmImage: windows-latest

  steps:
  - task: NuGetToolInstaller@0
    displayName: 'Use NuGet $(NugetVersion)'
    inputs:
      versionSpec: $(NugetVersion)

  - task: NuGetCommand@2
    displayName: 'NuGet restore'
    inputs:
      restoreSolution: $(RestoreSolution)

  - task: VSBuild@1
    displayName: 'Build Droid Project'
    inputs:
      solution: src/App.Droid/App.Droid.csproj      
      msbuildArgs: '/p:JavaSdkDirectory="$(JAVA_HOME_8_X64)"'
      platform: 'AnyCPU'
      configuration: $(BuildConfiguration)

this is the error result:


Project "D:\a\1\s\src\App.Droid\App.Droid.csproj" on node 1 (default targets).
_CreateStampDirectory:
  Creating directory "obj\Release\monoandroid10.0\stamp\".
_ResolveAndroidTooling:
  Found Java SDK version 1.8.0.
  Found Java SDK version 1.8.0.
_CheckInstantRunCondition:
  Dex Fast Deployment Enabled: False
_ResolveMonoAndroidSdks:
  MonoAndroid Tools: C:\Program Files\Microsoft Visual Studio\2022\Enterprise\MSBuild\Xamarin\Android\
  Android Platform API level: 29
  TargetFrameworkVersion: v10.0
  Android NDK: C:\Program Files (x86)\Android\android-sdk\ndk\25.2.9519653\
  Android SDK: C:\Program Files (x86)\Android\android-sdk\
  Android SDK Build Tools: C:\Program Files (x86)\Android\android-sdk\build-tools\32.0.0\
  Java SDK: C:\hostedtoolcache\windows\Java_Temurin-Hotspot_jdk\8.0.402-6\x64\
  Application Java class: android.app.Application
_CleanIntermediateIfNeeded:
  Creating "obj\Release\monoandroid10.0\stamp\_CleanIntermediateIfNeeded.stamp" because "AlwaysCreate" was specified.
  Touching "obj\Release\monoandroid10.0\stamp\_CleanIntermediateIfNeeded.stamp".
##[error]C:\Program Files\Microsoft Visual Studio\2022\Enterprise\MSBuild\Xamarin\Android\Xamarin.Android.Tooling.targets(100,5): **Error XA5207: Could not find android.jar for API level 29. This means the Android SDK platform for API level 29 is not installed. Either install it in the Android SDK Manager (Tools > Android > Android SDK Manager...), or change the Xamarin.Android project to target an API version that is installed. (C:\Program Files (x86)\Android\android-sdk\platforms\android-29\android.jar missing.)**

My expected result is that it should build the Android project and generate the files that would be needed for Copy Files and Publish Artifact tasks like the one below:

Creating "obj\Release\monoandroid10.0\stamp\_CleanIntermediateIfNeeded.stamp" because "AlwaysCreate" was specified.
Touching "obj\Release\monoandroid10.0\stamp\_CleanIntermediateIfNeeded.stamp".
_ResolveXamarinAndroidTools:
Found Xamarin.Android 13.2.2.0
PrepareForBuild:
Creating directory "bin\Release\monoandroid10.0\".
Project "D:\a\1\s\src\App.Droid\App.Droid.csproj" (1) is building "D:\a\1\s\src\App.Core.Shell\App.Core.Shell.csproj" (2:2) on node 1 (default targets).
PrepareForBuild:
Creating directory "bin\Release\netstandard2.0\".
Creating directory "obj\Release\netstandard2.0\".
Project "D:\a\1\s\src\App.Core.Shell\App.Core.Shell.csproj" (2:2) is building "D:\a\1\s\src\App.Core.Message\App.Core.Message.csproj" (4:3) on node 1 (default targets).
PrepareForBuild:
Creating directory "bin\Release\netstandard2.0\".
Creating directory "obj\Release\netstandard2.0\".
Project "D:\a\1\s\src\App.Core.Message\App.Core.Message.csproj" (4:3) is building "D:\a\1\s\src\App.Forms.UI\App.Forms.UI.csproj" (7:4) on node 1 (default targets).
PrepareForBuild:
Creating directory "bin\Release\netstandard2.0\".
Creating directory "obj\Release\netstandard2.0\".
*

I'm kind of new in CI/CD and still exploring around, I tried the following so far:

  • changing the version of vmImage
  • adding restore packages tasks
  • Using XamarinAndroid@1 task

Your help would be much appreciated, thanks!


Solution

  • Refer to this doc about Microsoft-hosted agent software.

    Currently, the pre-installed Android version of microsoft-hosted agent does not include android 29.

    The oldest version is Android 31 when using windows-latest agent.

    The oldest version is Android 30 when using windows-2019.

    To solve this issue, we can add additional commands to install the Android 29 before the build step.

    Here is the sample:

    steps:
    - script: 'C:\Android\android-sdk\cmdline-tools\latest\bin\sdkmanager "platforms;android-29" '
      displayName: 'Install Android 29 platform'
    
    - script: 'C:\Android\android-sdk\cmdline-tools\latest\bin\sdkmanager "build-tools;29.0.0" '
      displayName: 'Install Android 29 build tool'
    
    - script: 'C:\Android\android-sdk\cmdline-tools\latest\bin\sdkmanager --list_installed'
      displayName: 'Check sdk list'
    
    - task: vsbuild
    ....