[FIXED] Cannot find assembly Mono.Android when attempting to archive a Xamarin app for publishing

Issue

I had to do some work on a Xamarin project I didn’t create that is currently in production. I can build the app in Debug and Release on both Android and iPhone, as can anyone else who clones the repo. However, no one on my team has been able to successfully archive the app for publishing. Everyone gets the same error: Could not resolve this reference. Could not locate the assembly "Mono.Android". Check to make sure the assembly exists on disk. If this reference is required by your code, you may get compilation errors.

Question 1: Where exactly should Mono.Android exist on disk?

Could not locate the assembly "Mono.Android". Check to make sure the assembly exists on disk

In the projects .Droid folder in the references folder Mono.Android does exist but apparently this isn’t enough. Where else should it exist if this is not the only place?

On Windows people say to look in something like C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\Common7\IDE\ReferenceAssemblies\Microsoft\Framework\MonoAndroid{VERSION NUMBER}\Mono.Android.dll but I am on Mac, so where might this be instead?

Question 2: Why exactly am I getting this error in the first place?

Whatever the problem is I don’t understand why it would trigger when trying to archive only the .IOS project. As far as I know this shouldn’t have anything to do with Mono.Android. I feel like I should only be getting this error when I try to archive the .Droid project.

Question 3: What solutions are there to this?

Requires minimum Android version: 6 (API level 23)

Target Android version: 9.0 (API level 28)

Everyone on the team is using VS for Mac.

I have confirmed that I have Android 9 Pie installed and with all it’s packages. I have attempted to archive for publishing on both Visual Studio for Mac 2019 and 2022 but got the same result for each. I have had others on the team attempt the same.

I have attempted to re-reference Mono.Android but when I try to add a reference and I scroll down to Mono.Android the version is 0.0.0.0. Why would that be?

What am I missing and how do I get it?

If you need any additional information please ask and I’ll do my best to share.

Solution

I finally successfully deployed the app. I found a hardcoded path to Mono.Android in the Droid project csproj file. I removed this and the Mono.Android error stopped, but I was still getting similar errors so this is what happened:

I believe that the app was originally developed in VS for Mac 2017 and used whatever Xamarin package versions came with whatever version of VS for Mac 2017 the app was developed in. I am using an M1 Mac and cannot install VS for Mac 2017 or a lot of the packages that I needed. So what I did was moved to VS for Mac 2022 and upgraded all Xamarin packages and then fixed the errors that arose from that.

Once all packages were upgraded the app still would not deploy properly so I downloaded Transporter and used that to deploy the app which was very easy.

I hope this helps someone in the future.

Answered By – Cole Perry

Answer Checked By – David Marino (Easybugfix Volunteer)

Leave a Reply

(*) Required, Your email will not be published