I am trying to set up a TFS Build agent
to build my Xamarin.Android
project automatically on every check in.
I have followed the steps outlined here: https://msdn.microsoft.com/library/vs/alm/build/apps/xamarin for setting up a Hosted build agent.
TFS Build templates also have a Xamarin.Android
template, which you would expect means they are ready to go. This is also backed up from the above link which states you can build a Xamarin.Android
solution on a Hosted pool
But I keep getting the following error on building the project:
Missing Android NDK toolchains directory '\toolchains'. Please install the Android NDK
I found a link at Xamarin https://developer.xamarin.com/guides/cross-platform/ci/configuring_tfs/tfs-and-xa/ which says I need to log onto the build machine and copy and paste the Android NDK onto my remote machine.
But obviously with a hosted pool I cannot log onto machine.
Am I missing something in my setup?
The original problem was about building a Xamarin Android App on an Azure DevOps hosted agent and having an error because the Android NDK can't be found.
Yes, the build will work if you disable options like EmbedAssembliesIntoApk
or BundleAssemblies
, but this is not a true solution, especially when you need those options to be enabled.
As the Android NDK path is not found when building on a hosted agent, the solution is to manually set the Android NDK path. In the build task, in the MSBuild Options, provide the following Additional Argument:
/p:AndroidNdkDirectory="C:\java\androidsdk\android-ndk-r13b"
/p:AndroidNdkDirectory="$(latestAndroidNDKPath)"
If you want to know more about this issue I wrote an article that will give you more details:
How to retrieve the latest Android NDK on a VS2017 hosted agent:
$ndk_root = "C:\Microsoft\AndroidNDK64\"
if(Test-Path $ndk_root) {
$androidNDKs = Get-ChildItem -Path $ndk_root | Sort-Object -Property Name -Descending | Select-Object -First 1
$latestAndroidNDK = $androidNDKs.FullName;
Write-Host "##vso[task.setvariable variable=latestAndroidNDKPath]$latestAndroidNDK"
} else {
Write-Host "NDK is not installed at path $ndk_root"
exit 1
}
Write-Host Variable '$(latestAndroidNDKPath)' is $latestAndroidNDK
Step by Step guide to solving this issue.
If you can I would advise setting up your own build Host using Visual Studio 2015 Update 2 with Xamarin and this link. After doing so you can use this Xamarin link to make sure. 1. your java SDK and NDK are in a local (non user specific area, which if you installed using visual studio they should be) and the Enviroment variables have been added (from the Xamarin link):
Adjusting Environment Variables During the automated build process Xamarin.Android will require access to the Android SDK and NDK at the paths that were adjusted above. This is best done by setting ot adjusting several server wide environment variables:
If not already, log in to the TFS machine as Administrator. Open Control Panel, type Environment in the search box, select Edit the system environment variables, and then click the Environment Variables... button to bring up the following dialog:
Under System variables select ANDROID_HOME and click Edit…, or if ANDROID_HOME doesn’t exist, click New… to create it:
Set the value to c:\android-sdk (or wherever you moved the SDK) and click OK. Under System variables select ANDROID_NDK_PATH and click Edit… (or New… if necessary):
Set the value to c:\android-ndk\android-ndk-r8d (or wherever you moved the NDK) and click OK. Note that you do need the second folder name in this value. Select the Path variable, click Edit… button, and append ;c:\android-sdk (or whatever folder you used) to the end of the path and click OK. Don’t forget to include the semi-colon (;) separator between this and previous entries.
Verify the changes by opening a command prompt, entering Set, and examining the variables. The Team Foundation Server should now be able to build Android apps in a team project.
after this you must set the following properties to False
in your project.Android.csproj file.
open the file in notepad, go to the Release configuration section and set the following to false:
<AndroidUseSharedRuntime>False</AndroidUseSharedRuntime>
<EmbedAssembliesIntoApk>False</EmbedAssembliesIntoApk>
<BundleAssemblies>False</BundleAssemblies>
Your project will now build on a hosted pool!
Although I think this hides the real issue as setting these to true will build on your local build agent.
I think the microsoft hosted pool is missing the Android NDK enviroment variable as it doesnt show up in the capabilities in TFS
There is a same issue on Xamarin Forums, and following is the solution in it:
Fixed: As an update if anyone else having this problem when building Release (that the NDK \toolchains is missing) it appears that mkbundle is broken.
The root cause is that "MakeBundleNativeCodeExternal" is true for release and false for Debug. Although this appears as a licensing issue, my build agent has an Enterprise licence installed.
Disabling "MakeBundleNativeCodeExternal" in Release build by editing the Android project in notepad, seach for 'BundleAssemblies' - and change the 'True' under Release configuration section to ' False' save, build Release, works.
Refer to this link for details: Missing Android NDK toolchains directory
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With