maui android app build in pipeline failing with error 'The Android SDK directory could not be found'

337 Views Asked by At

Without any code changes the pipeline build for android failing with following errors.

/opt/hostedtoolcache/dotnet/packs/Microsoft.Android.Sdk.Linux/33.0.95/tools/Xamarin.Android.Tooling.targets(70,5): error XA5300: The Android SDK directory could not be found. Install the Android SDK by following the instructions at: https://aka.ms/dotnet-android-install-sdk [/home/vsts/work/1/s/App/App.csproj::TargetFramework=net7.0-android]

/opt/hostedtoolcache/dotnet/packs/Microsoft.Android.Sdk.Linux/33.0.95/tools/Xamarin.Android.Tooling.targets(70,5): error XA5300: To use a custom SDK path for a command line build, set the 'AndroidSdkDirectory' MSBuild property to the custom path. [/home/vsts/work/1/s/App/App.csproj::TargetFramework=net7.0-android]

##[error]Error: The process '/opt/hostedtoolcache/dotnet/dotnet' failed with exit code 1
    - task: DotNetCoreCLI@2
      displayName: 'Install MAUI workload'
      inputs:
        command: 'custom'
        custom: 'workload'
        arguments: 'install maui-android'
  
    - task: DotNetCoreCLI@2
      displayName: 'Build Solution'
      inputs:
        command: 'publish'
        publishWebProjects: false
        projects: '**/*.sln'
        arguments: '-f:net7.0-android -c:Release /p:BuildAndroidOnly=true'
1

There are 1 best solutions below

0
Tomy On

As presented in this github post: https://github.com/actions/runner-images/issues/8952#issuecomment-1886985216

This installs the SDK manually - this should be a temporary solution until Microsoft fixes the builder image.

- name: Set Up Android tools
  run: |
    ${ANDROID_SDK_ROOT}/cmdline-tools/latest/bin/sdkmanager \
    --sdk_root=$ANDROID_SDK_ROOT \
    "platform-tools"

- name: Build
  run: |
    dotnet build <project> \
    -f:net8.0-android