Building APKs / AABs with Xamarin

I was wondering whether anyone had a working example or template for building Xamarin/Android apps in GitLab CI/CD? As you might guess, most examples I could find were for Azure! TIA

Hi @snim2 :wave: :slightly_smiling_face: Since I’m on your same boat, did you get an answer from anywhere else? :slightly_smiling_face:

Little side note: I was able to pretty much set everything up, but the commands that I tested locally do not work on the runner so I’m stuck there :sweat_smile:

Hi @zillemarco

Yes, I did find a solution, although it isn’t ideal, and full disclosure: I’m no longer working on this particular project, so I won’t be adding more updates, sorry!

So, the solution was that there are a number of Docker images, like this one, which package up the Android SDK, with Xamarin and the various dotnet tools you need. If you look around GitHub and Docker Hub you will find a whole bunch of similar repos.

The repo in the link above shows how to build an app, and has a brief example of how you can add it to a GitLab pipeline.

There are two major issues with this:

  1. NONE of the images I found have the latest API level, which is required for the Play Store. You (or someone) would have to make a PR to add that, and I’d guess it’s quite fiddly.
  2. If you have built your app using Visual Studio before, then the build configurations in VS do not map neatly to command-line options in msbuild. I don’t use VS generally, so I was expecting that a debug version of the build log would contain a call to msbuild and I could just copy that into the pipeline config. Not so lucky! You will want to have a good look through the build properties documentation for Android which contains everything you may need. You say you have some command line options working locally, so hopefully you’re a step further on than I was when I started.

Also, if you want to build for the Play Store in the pipeline, GitLab have released their secret files feature just in time for you.

After I posted here I actually kept tinkering and got to work mostly everything :partying_face:

To answer the points you made:

  1. I don’t really have problems with using existing images to build the app since I’m running the jobs on Mac using the shell executor, so I have everything available from the system. (I had to do it this way so I could also build our iOS apps)
  2. msbuild actually worked out of the box, what I found was missing is that it does not restore the Nuget packages by itself. Once I added a command to restore the packages the build went well.

To deploy the app to the store I combined everything with Fastlane. I still need to finish the whole setup, but once solved the first few problems I got pretty much everything going.

Once I get the whole process sorted, I thinkg I’ll write a blogpost documenting what I did so others will benefit from my struggles :sweat_smile:

Thanks a lot for sharing your experience!! :slightly_smiling_face:

PS: that secret files feature looks sweet!! I think I’ll wait until it’s more stable and generally available (not behind a FF), but as of now I don’t have problems since I’m using protected variables for the files and the passwords :slightly_smiling_face:

1 Like

Hi,
I am having the same issues, but with Ubuntu.
Any chance you could point me to a sample on how do you build Xamarin/Maui with GitLab CI/CD?