android: Xamarin.Android task cannot find NDK with latest Azure image(s)

Android application type

Classic Xamarin.Android (MonoAndroid12.0, etc.)

Affected platform version

Azure pipeline

Description

Making use of the Xamarin.Android task we have been able to build and deploy Xamarin.Android applications. New images were released which seems to have affected this task; the NDK path is no longer found when executing the “_ResolveMonoAndroidSdks” step resulting in a build failure.

Reviewing the latest releases for these images, I see there was work around NDK paths, symlinks, and environment variable changes. https://github.com/actions/virtual-environments/issues/5879 https://github.com/actions/virtual-environments/issues/5930

The image we’re using is macOS-latest, here are the old and new logs showing the “_ResolveMonoAndroidSdks” step resolving the NDK path: Old working image (20220724.1) Screenshot 2022-08-04 at 12 37 45

New broken image (20220801.1) Screenshot 2022-08-04 at 12 38 40

Do we know if the Xamarin.Android task needs to be updated to reflect this?

Steps to Reproduce

  1. Make use of the Azure Pipeline Xamarin.Android task for a Xamarin.Android application using the macOS-latest image.
  2. See the task eventually fails with error XA5104: Could not locate the Android NDK. Please make sure the Android NDK is installed in the Android SDK Manager, or if using a custom NDK path, please ensure the $(AndroidNdkDirectory) MSBuild property is set to the custom path.

Did you find any workaround?

No response

Relevant log output

No response

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Reactions: 3
  • Comments: 85 (27 by maintainers)

Commits related to this issue

Most upvoted comments

There is definitely something up with the AzDO image. I downloaded the suspect .dll and it is ancient:

image

After I install my own .pkg I get:

image

I filed an issue here: https://github.com/actions/runner-images/issues/6038

Looking to find the right person to message at Microsoft internally.

Hey there, following the mitigation proposed in this thread, I’ve added this task prior to my Android build task and at least the NDK is now present.

    - task: CmdLine@2
      displayName: "XA5104 Workaround"
      inputs:
        script: '${ANDROID_HOME}/tools/bin/sdkmanager --install "ndk;21.4.7075529"'

This might not be an elegant permanent solution, since as @GreatBarrier86 stated, I also don’t understand why 21.4.7075529 is not found automatically. However, this could help unblock those failing pipelines in the meantime at least.

@Maxgamerboy1, I’m leaving this here for anyone else that happens to run across this same question. You can pass in MSBuild arguments to sign the APK file, regardless of whether its your key or not. Maybe it will help someone in the future because i did need to research how to do this.

/p:OutputPath=$(build.binariesdirectory)/$(BuildConfiguration)/$(TestOutputFolder) /t:SignAndroidPackage /p:AndroidKeyStore=true /p:AndroidSigningKeyAlias=$(KeystoreAlias) /p:AndroidSigningKeyPass=$(CertificatePassword) /p:AndroidSigningKeyStore=$(Build.SourcesDirectory)/MyKeystore.file /p:AndroidSigningStorePass=$(CertificatePassword)

Taken from here: https://www.jenx.si/2020/04/05/xamarin-forms-developers-how-to-sign-android-apk/

Ok, so I think we’ve solved this one – the macos-12 image has Xamarin.Android 13.x, which supports up to Android NDK 24.

Let me know if I missed anything outstanding here, thanks!

@salgiza sure! Although, see my response here https://github.com/xamarin/xamarin-android/issues/7233#issuecomment-1234315475 the issue is relating more to the build image itself rather than the task used to build.

to switch over, in your case, it should look something like this;

  - task: MSBuild@1
    inputs:
      solution: '**/*Droid*.csproj'
      configuration: '$(buildConfiguration)'
      msbuildArguments: '-p:OutDir="$(outputDirectory)" -t:SignAndroidPackage'

@jtorvald you can email at the address on my GitHub profile, thanks.

@Maxgamerboy1, one thing I noticed, and I’m not sure what I should be using here, but the Xamarin.Android step’s msbuild line shows /t:PackageForAndroid instead of /t:SignAndroidPackage. My next step after this is the Android signing task, so I’m not sure which to use. For now, i’m going with `/t:PackageForAndroid’ to mimic what the original task had.

image

@Maxgamerboy1, i’m not sure i agree that is unsupported, but i have no inside knowledge. According to GitHub, the Xamarin.Android task was just updated 2 months ago. I’m not sure if it’s really “unsupported”. Read what i wrote up here: https://github.com/xamarin/xamarin-android/issues/7233#issuecomment-1233474937

@Maxgamerboy1, any reason you’re using the MSBuild task over the XamarinAndroid one? just curious myself. I’d like to use whichever one is recommended.

@Maxgamerboy1 can you use this to get a .binlog of your build:

msbuildArguments: -bl:$(Build.ArtifactStagingDirectory)msbuild.binlog

Then save this file as an artifact, and share it?

You might consider using the plain MSBuild yaml task instead of XamarinAndroid. I’m not sure who created it, or if it is maintained. It seems like the MSBuild task would do everything and you just need to use the -t:SignAndroidPackage target?

@rubeonline if they dropped an Android NDK from the image, and then there isn’t an NDK that this old version of Xamarin.Android supports – you’ll probably have an issue. In that case you may need to install an older NDK yourself, or newer Xamarin.Android.

Ok, this log message is a bit different than what I’m seeing!

Skipping NDK in '/Users/runner/Library/Android/sdk/ndk/24.0.8215888': version 24.0.8215888 is out of the accepted range (major version must be between 16 and 21
Skipping NDK in '/Users/runner/Library/Android/sdk/ndk/23.2.8568313': version 23.2.8568313 is out of the accepted range (major version must be between 16 and 21
Skipping NDK in '/Users/runner/Library/Android/sdk/ndk/25.0.8775105': version 25.0.8775105 is out of the accepted range (major version must be between 16 and 21

Mine is also using XamarinAndroidVersion: 13.0.0-0, which it downloaded and installed.

It seems like the bots should still have r23 and r24, can you add some ls commands to a build to find out if they are there?