runner-images icon indicating copy to clipboard operation
runner-images copied to clipboard

Android build is crashing with NDK r24

Open akrol95 opened this issue 3 years ago • 5 comments

Description

For the past few days we have been experiencing problems building our Xamarin Android application using Azure Pipeline.

We use AOT compilation, we need Android NDK installed on building machine. We passing its path to MSBuild by ANDROID_NDK_LATEST_HOME environment variable, which on used image version points to NDK version 24.0.8215888.

With this configuration build is crashing after several minutes with this enigmatic reason:

C:\Program Files\Microsoft Visual Studio\2022\Enterprise\MSBuild\Xamarin\Android\Xamarin.Android.Legacy.targets(729,5): error : The system cannot find the file specified [D:\a\1\s\<project-folder>\<project-name>.csproj]

After deeper investigation, I noticed that moments before the build is interrupted, the following command is executed:

[CC] "C:\Android\android-sdk\ndk\24.0.8215888\toolchains\llvm\prebuilt\windows-x86_64\bin\armv7a-linux-androideabi16-clang" -c -D__ANDROID_API__=16 -DANDROID -o obj\Release\120\bundles\armeabi-v7a\temp.o -I C:\Android\android-sdk\ndk\24.0.8215888\toolchains\llvm\prebuilt\windows-x86_64\sysroot\usr\include\arm-linux-androideabi -I C:\Android\android-sdk\ndk\24.0.8215888\toolchains\llvm\prebuilt\windows-x86_64\sysroot\usr\include obj\Release\120\bundles\armeabi-v7a\temp.c (TaskId:587)

It looks, that for some reason when we build on Azure, something sets ANDROID_API (which apparently should be the lowest supported version by NDK) to version 16. Then it is searching for "armv7a-linux-androideabi16-clang", which does not exists with this version of NDK, because Google has dropped it in NDK r24: https://github.com/android/ndk/wiki/Changelog-r24

Our Android projects has these parameters:

  • TargetFrameworkVersion: v12.0
  • android:minSdkVersion="21"
  • android:targetSdkVersion="32"

When I try to build the project locally with the same parameters as used on pipeline, everything works well, and Android API is set properly by build process. Here is the command from local build (NDK used here is in r25 version, but the result is the same on r24):

[CC] "/Users/<username>/Library/Developer/Xamarin/android-sdk-macosx/ndk/25.0.8528842/toolchains/llvm/prebuilt/darwin-x86_64/bin/armv7a-linux-androideabi19-clang" -c -D__ANDROID_API__=19 -DANDROID -o obj/Release/bundles/armeabi-v7a/temp.o -I /Users/<username>/Library/Developer/Xamarin/android-sdk-macosx/ndk/25.0.8528842/toolchains/llvm/prebuilt/darwin-x86_64/sysroot/usr/include/arm-linux-androideabi -I /Users/<username>/Library/Developer/Xamarin/android-sdk-macosx/ndk/25.0.8528842/toolchains/llvm/prebuilt/darwin-x86_64/sysroot/usr/include obj/Release/bundles/armeabi-v7a/temp.c

I was also trying to manually install NDK r25 in one of pipeline running stage and pass it to MSBuild, but the result is the same. It still search for Android API 16 files.

The only solution for now it to force use NDK v21. Building process is successful in this case. Unfortunately r21 will be dropped soon (1st August?) from images, so then we would need to install it manually and use outdated NDK, so it's not the real solution for us.

The problem is the same for windows-2022 and macOS-12 images. I can provide more details if needed.

Platforms affected

  • [X] Azure DevOps
  • [ ] GitHub Actions

Virtual environments affected

  • [ ] Ubuntu 18.04
  • [ ] Ubuntu 20.04
  • [ ] Ubuntu 22.04
  • [ ] macOS 10.15
  • [ ] macOS 11
  • [X] macOS 12
  • [ ] Windows Server 2019
  • [X] Windows Server 2022

Image version and build link

Windows 2022 -> 20220724.1 macOS 12 -> 20220724.1

Is it regression?

Expected behavior

Build process should be successful using Android NDK version r24 or higher.

Actual behavior

Build crashes when using Android NDK r24.

Repro steps

akrol95 avatar Jul 29 '22 11:07 akrol95

Hello @akrol95. Please provide a test repo with minimal steps to reproduce the issue.

al-cheb avatar Jul 29 '22 11:07 al-cheb

@al-cheb As we are open source, I can share entire project with you:

https://github.com/bcc-code/bmm-app I prepared branch named 'build-problems' there, which have exactly the same configuration as described in this ticket.

Azure build for Android is defined in azure-pipelines-android.yaml file.

I can also prepare separate, smaller project with similiar configuration if needed.

akrol95 avatar Jul 29 '22 14:07 akrol95

Hello @akrol95. Could you please provide smaller project I've tried to reproduce the issue on bmm-app but I could not properly configure it.

dmitry-shibanov avatar Aug 02 '22 11:08 dmitry-shibanov

@dmitry-shibanov Here you are: https://github.com/bcc-code/bmm-app/tree/minimal-projects-to-fail-on-pipeline

I removed all not needed projects, files and configuration from the project and YAML and it still fails on pipeline.

akrol95 avatar Aug 02 '22 12:08 akrol95

Hello @akrol95. Sorry for the late response. I've tried to reproduce the issue again after updating the image on 24 and 25 ndk versions but I've got different error related to Error MSB4044: The "AndroidSignPackage". After setting AndroidKeyStore option to false it worked as expected. Could you please try to run your build one more time ? I think it was resolved with updating visual studio and its dependencies.

dmitry-shibanov avatar Aug 15 '22 18:08 dmitry-shibanov

@akrol95, Any updates?

al-cheb avatar Aug 19 '22 08:08 al-cheb

I successfully built the project on 20220816.1 image.

akrol95 avatar Aug 22 '22 13:08 akrol95

Hello @akrol95. Thank you for your response. In this case I'm going to close the issue.

dmitry-shibanov avatar Aug 23 '22 21:08 dmitry-shibanov