Skip to content

Xamarin.Android task cannot find NDK with latest Azure image(s) #7233

Closed

Description

@thomasphillipsgb

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.
actions/runner-images#5879
actions/runner-images#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

Activity

  1. jonathanpeppers commented on Aug 4, 2022

    @jonathanpeppers
    Member
  2. jonathanpeppers commented on Aug 4, 2022

    @jonathanpeppers
    Member
  3. thomasphillipsgb commented on Aug 4, 2022

    @thomasphillipsgb
    Author

    Thanks for the response! Our builds started failing this morning, ones running yesterday were still using the old image, due to the staggered rollout.

    I do see your build is using MSBuild directly, whereas I'm using this badger for building my Xamarin Android project
    https://docs.microsoft.com/en-gb/azure/devops/pipelines/tasks/build/xamarin-android?view=azure-devops

  4. jonathanpeppers commented on Aug 4, 2022

    @jonathanpeppers
    Member

    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?

  5. jonathanpeppers commented on Aug 4, 2022

    @jonathanpeppers
    Member

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

  6. GreatBarrier86 commented on Aug 4, 2022

    @GreatBarrier86

    Instead of the suggested mitigation of installing r21, is there a way to change the project to just use the latest version? I'm obviously having the same problem too.

    @jonathanpeppers, there's something here i dont understand. I dont think we're specifying the required NDK version in our manifest or csproj file, so what's causing it to use r21 specifically instead of just $LatestVersion.

    _ResolveMonoAndroidSdks:
    MonoAndroid Tools: /Library/Frameworks/Xamarin.Android.framework/Libraries/xbuild/Xamarin/Android/
    Android Platform API level: 31
    TargetFrameworkVersion: v12.0
    Android NDK:
    Android SDK: /Users/runner/Library/Android/sdk/
    Android SDK Build Tools: /Users/runner/Library/Android/sdk/build-tools/30.0.2/
    Java SDK: /Library/Java/JavaVirtualMachines/Temurin-Hotspot-11.jdk/Contents/Home/
    Application Java class: android.app.Application

    "/Users/runner/work/8/s/Mobile/CPSMobile/CPSMobile.Android/CPSMobile.Android.csproj" (PackageForAndroid target) (1) ->
    (_BuildApkEmbed target) ->
    /Library/Frameworks/Mono.framework/External/xbuild/Xamarin/Android/Xamarin.Android.Common.targets(1954,3): 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. [/Users/runner/work/8/s/Mobile/CPSMobile/CPSMobile.Android/CPSMobile.Android.csproj]

  7. jonathanpeppers commented on Aug 4, 2022

    @jonathanpeppers
    Member

    I found something that prevents the selection of r25: dotnet/android-tools#190

    Versions with Android NDK r24 or lower should work, though. As long as one of those is installed.

  8. 65 remaining items

  9. GreatBarrier86 commented on Sep 1, 2022

    @GreatBarrier86

    @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: #7233 (comment)

  10. jonathanpeppers commented on Sep 1, 2022

    @jonathanpeppers
    Member

    @GreatBarrier86 no real reason, i'm seeing Pepper's builds making use of it, and with the revelation that we don't know who is maintaining that task, I think it's a smart move to hop over the MSBuild task

    I don't think I use the XamarinAndroid .yaml task, where did you see that? If someone is working on lately, it isn't the Xamarin.Android team, so I'm not sure about its status.

    Personally, I don't see what value it has over the regular MSBuild task. If there is some value, we should just put that logic in Xamarin.Android/.NET 6 instead?

  11. GreatBarrier86 commented on Sep 1, 2022

    @GreatBarrier86

    Unless i misunderstand, he's saying he saw that you do NOT use Xamarin.Android, but instead use MSBuild.

  12. thomasphillipsgb commented on Sep 1, 2022

    @thomasphillipsgb
    Author

    Unless i misunderstand, he's saying he saw that you do NOT use Xamarin.Android, but instead use MSBuild.

    Yes, that's correct. Sorry for the confusion; XamarinAndroid task- I've stopped using, MSBuild task - I've now switched over to use :D

  13. salgiza commented on Sep 2, 2022

    @salgiza

    Could someone post an example of how the MSBuild task should be configured to get the same result as this basic XamarinAndroid task?

    CleanShot 2022-09-02 at 14 36 44

    We are having the same problem and I don't really mind using one or the other as long as it works, but all the docs for Azure DevOps use the XamarinAndroid task, and I'm totally unfamiliar with the MSBuild task 😢

  14. thomasphillipsgb commented on Sep 2, 2022

    @thomasphillipsgb
    Author

    @salgiza sure! Although, see my response here #7233 (comment) 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'
  15. salgiza commented on Sep 5, 2022

    @salgiza

    Thanks a lot @Maxgamerboy1 , with all the messages in the thread, I had missed the one that said that changing the vmImage from macos-latest to macos-12 should fix the problem. Seeing the comments from @jonathanpeppers, though, I decided to do both (change the vmImage, and migrate from the XamarinAndroid task to MSBuild), and our pipeline is working again!

  16. jonathanpeppers commented on Sep 6, 2022

    @jonathanpeppers
    Member

    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!

  17. GreatBarrier86 commented on Sep 7, 2022

    @GreatBarrier86

    @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

  18. thomasphillipsgb commented on Sep 7, 2022

    @thomasphillipsgb
    Author

    Ah, sorry, didn't know you were doing signing in a separate step. Yes, you'll need to use the PackageForAndroid target in that case.

  19. GreatBarrier86 commented on Sep 7, 2022

    @GreatBarrier86

    I certainly don't have to sign in a different step. Does the msbuild task also zipalign? If so, i don't see why i can't use the msbuild task for both.

  20. thomasphillipsgb commented on Sep 7, 2022

    @thomasphillipsgb
    Author

    If using the /t:SignAndroidPackage it should zipalign, then keysign for you, here's a snippet from one of my old builds showing the _Sign step;

    2022-09-05T14:26:12.3762630Z _Sign:
    2022-09-05T14:26:12.3763980Z   /Users/runner/Library/Android/sdk/build-tools/32.0.0/zipalign -p 4 "obj/release/android/bin/com.[---].apk" "/Users/runner/work/1/b/release//com.[---]-Signed.apk" 
    2022-09-05T14:26:13.1999960Z   /Library/Java/JavaVirtualMachines/Temurin-Hotspot-11.jdk/Contents/Home/bin/java -jar /Library/Frameworks/Xamarin.Android.framework/Libraries/xbuild/Xamarin/Android/apksigner.jar sign --ks "/Users/runner/.local/share/Xamarin/Mono for Android/debug.keystore" --ks-pass pass:android --ks-key-alias androiddebugkey --key-pass pass:android --min-sdk-version 26 --max-sdk-version 30  /Users/runner/work/1/b/release/com.[---]-Signed.apk 
    

    you'll also note prior to this step, MSBuild creates a debug keystore under the _CreateAndroidDebugSigningKey step.

    essentially, if you wanna zipalign and sign using your own keys, use /t:PackageForAndroid, else let the /t:SignAndroidPackage do it for you

  21. GreatBarrier86 commented on Sep 8, 2022

    @GreatBarrier86

    @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/

  22. ghost locked as resolved and limited conversation to collaborators on Oct 8, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

Area: App+Library BuildIssues when building Library projects or Application projects.

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions