I recently wrote about how to build any Xamarin.iOS application inside of Visual Studio Team Services using Hosted macOS Agents for free! I have updated the guide a little bit if you are leveraging .NET Standard libraries to ensure that you build with MSBuild, which is pretty important seeing that all of the new templates will soon use these. That had me thinking "I wonder if there are any small tweaks that are needed for Xamarin.Android when building on the Hosted Agents?"... Which led me to finding a few tweaks that I figured I would blog about.
If you want to understand my passion for VSTS then make sure to listen to Merge Conflict Episode 71.
When you head into VSTS and create a new build definition you will find the Xamarin.iOS and Xamarin.Android templates. Go ahead and select that Xamarin.Android template!
For now go ahead and:
- Delete the Xamarin Test Cloud Step
- Disable the MSBuild step for Test. If you have tests go ahead and leave it on.
Select Build Host
Under Process we can fill in some additional information for the build such as what Solution to do a NuGet restore on and what build host to use. For now I will select the Hosted VS2017 agent.
Use Nuget 4.5.1
Since the templates in VS 2017 for Xamarin.Forms apps include a UWP (Fall Creators Update app) we will need to update NuGet to use the latest version, which happens to be 4.5.1. This seems necessary due to changes with .NET Standard.
Tweak Android Build Task
We recently changed how the default Android templates are generated on disk and create a csproj that is titled: .Android.csproj Previously it was .Droid.csproj. Regardless the default csproj the Android task tries to build is a regex that looks like:
I am not a fan of using a regex regardless and always pick the specific project, but you should make sure it matches your actual projects. So for me it would be:
Like I said, be sure to check your project names or pick the specific one to build, which is what I recommend.
Finally, there are multiple versions of the JDK and Java that are installed. As of today Xamarin.Android apps should be built against JDK 8 x64, which you can select under Advanced.
Queue a Build!
That is it! You can queue up a build and will have a full Android app built up. The final thing that you probably want to do is upload your keystore and ensure you Sign and do a Zip Align in that task step.
How about Hosted macOS?
I knew you would ask! The only difference is that you DO NOT need to modify the Java JDK version to use. It looks like macOS has a specific version installed and you can just leave it to default for now.
Want More VSTS?
We use VSTS for all sorts of different applciations and I recently sat down with Damian Brady on his show The DevOps Lab to talk about how we use VSTS to build the Xamarin Live Player.