Xamarin.Android "XA5300: The Android SDK directory could not be found" in CI
Xamarin.Android builds need a path to the Android SDK. XA5300 means the build could not locate it because AndroidSdkDirectory is not set in the project or ANDROID_HOME is missing on the runner.
What this error means
A Xamarin.Android build fails with "error XA5300: The Android SDK directory could not be found. Please set its location via the 'AndroidSdkDirectory' MSBuild property."
error XA5300: The Android SDK directory could not be found. Please set its location
via the 'AndroidSdkDirectory' MSBuild property or the ANDROID_HOME environment variable.Common causes
ANDROID_HOME is not exported on the runner
The legacy Xamarin tasks read ANDROID_HOME/AndroidSdkDirectory; when neither is set, the SDK cannot be located.
The SDK is installed at a non-default path
The runner Android SDK lives somewhere the build does not expect, so it must be told the path explicitly.
How to fix it
Set the Android SDK path for the build
- Export
ANDROID_HOMEto the runner SDK location. - Or pass
AndroidSdkDirectoryto MSBuild explicitly. - Rebuild the Xamarin.Android project.
export ANDROID_HOME=$ANDROID_SDK_ROOT
msbuild MyApp.Android.csproj /p:Configuration=Release /p:AndroidSdkDirectory="$ANDROID_HOME"Install the SDK if the image lacks it
Provision the Android SDK and required platform with sdkmanager before building.
sdkmanager "platform-tools" "platforms;android-33" "build-tools;33.0.2"How to prevent it
- Export
ANDROID_HOMEin the job environment. - Pass
AndroidSdkDirectorywhen the SDK is at a custom path. - Provision the SDK platform and build-tools in CI.