Azure Dev Ops pipeline failing for Xamarin Native android app when installing SDK platforms
Hi,
I have a Xamarin Native android project which is held in Azure Dev Ops. I have a pipeline which builds the app. The last time it ran in April it worked fine, but now after making only a few small code changes (UI changes) of which none were related to changing anything like the minSdkVersion or the targetSdkVersion the pipeline no longer works. I suspect something behind the scenes for the pipeline or something like that may have changed.
Here's my pipeline:
# Xamarin.Android
# Build a Xamarin.Android project.
# Add steps that test, sign, and distribute an app, save build artifacts, and more:
# https://docs.microsoft.com/azure/devops/pipelines/languages/xamarin
trigger:
- master
variables:
- group: 'variables'
jobs:
- job: 'BuildAndroidProject'
pool:
vmImage: 'macos-latest'
variables:
buildConfiguration: 'Release'
outputDirectory: '$(build.binariesDirectory)/$(buildConfiguration)'
steps:
- script: |
echo "##vso[task.prependpath]/usr/local/share/android-sdk/tools"
echo "##vso[task.prependpath]/usr/local/share/android-sdk/tools/bin"
echo "##vso[task.prependpath]/usr/local/share/android-sdk/platform-tools"
# Define the full path to sdkmanager
SDKMANAGER_PATH="/Users/runner/Library/Android/sdk/tools/bin/sdkmanager"
# Install Android SDK platforms for API level 27 and 28
echo "y" | $SDKMANAGER_PATH "platforms;android-27" "platforms;android-28"
displayName: 'Install Android SDK Platforms'
condition: ne(variables['Agent.OS'], 'Windows_NT')
- task: NuGetToolInstaller@1
displayName: "Install NuGet"
- task: CmdLine@2
displayName: "Update submodule"
inputs:
script: |
echo 'Updating submodule'
git submodule init
git submodule update
- task: NuGetCommand@2
displayName: "Restore NuGet packages"
inputs:
restoreSolution: '**/*.sln'
- task: XamarinAndroid@1
displayName: "Build Android project"
inputs:
projectFile: '**/project.Droid.csproj'
outputDirectory: '$(build.binariesDirectory)'
configuration: '$(buildConfiguration)'
msbuildVersionOption: latest
It's failing at the "Install Android SDK Platforms" step with error message: "Exception in thread "main" java.lang.NoClassDefFoundError: javax/xml/bind/annotation/XmlSchema".
After doing some research and talking to chat GPT it was suggested that there may be a compatibility issue with the Java SDK version used in the pipeline and to try setting up JDK 8 like so (this is the first task that runs) :
-
inputs:
versionSpec:
displayName:
However, this shows a validation error: "A task is missing. The pipeline references a task called 'UseJavaVersion'. This usually indicates the task isn't installed, and you may be able to install it from the Marketplace". But I couldn't find anything on the marketplace, so I added the following instead from another suggestion:
-
# Download and install JDK 8
brew tap AdoptOpenJDK/openjdk
brew install --cask adoptopenjdk8
# Set JAVA_HOME to use JDK 8
export JAVA_HOME=$(/usr/libexec/java_home -v 1.8)
echo "JAVA_HOME set to $JAVA_HOME"
displayName:
After re-running the pipeline it still failed with the same error and it was suggested that:
"The NoClassDefFoundError
is occurring because Java 11 (or later) lacks the javax.xml.bind
module, which sdkmanager
still expects. To resolve this, let’s install the Android SDK command-line tools and platform tools using a workaround that directly adds the necessary Android SDK components without relying on sdkmanager
."
So I updated the "Install Android SDK Platforms" (also updating the API levels in case that was an issue) step as follows:
# Install Android SDK platforms manually using the SDK Manager in the newer Android command-line tools
-
echo "Setting up Android SDK platforms and tools"
ANDROID_SDK_ROOT=$HOME/Library/Android/sdk
mkdir -p $ANDROID_SDK_ROOT
# Download and install the command-line tools
commandlinetools.zip
unzip
mv
# Update PATH
export
export
# Install the required SDK platforms (API levels 29 and 33)
yes
displayName:
After this the "Install Android SDK Platforms" step was successful. But the build failed on the "Build Android project" step with error:
error MSB4226: The imported project "/Library/Frameworks/Mono.framework/Versions/6.12.0/lib/mono/xbuild/Xamarin/Android/Xamarin.Android.CSharp.targets" was not found. Also, tried to find "Xamarin/Android/Xamarin.Android.CSharp.targets" in the fallback search path(s) for $(MSBuildExtensionsPath) - "/Library/Frameworks/Mono.framework/External/xbuild/" . These search paths are defined in "/Library/Frameworks/Mono.framework/Versions/6.12.0/lib/mono/msbuild/Current/bin/MSBuild.dll.config". Confirm that the path in the <Import> declaration is correct, and that the file exists on disk in one of the search paths."
I've tried lots of different suggestions and keep going in circles with different steps failing. Any help would be much appreciated.
Thanks.