Pregunta

I'm developing a class library for Android using Xamarin Studio. How do I add a reference to Mono.Android in my library project? Mono.Android is not in the list of available assemblies.

¿Fue útil?

Solución

Assuming that you have X.Android installed, right click your solution. Then Add -> Add new Project -> Android -> Android Library Project.

There is no reference you would have to add.

enter image description here

Otros consejos

If you want to support more than simply Xamarin.Android in your Library project, you have the possibility of using a Portable Class Library (PCL). I find the profiles 78 and 158 to work very well and both provide await/async support.

However you should not that the PCL's only support the minimum subset of the targets in the profile. Hence, not everything in .NET 4.5 is available, and you won't be able to do platform specific things inside of it, unless you abstract it away. This could be achieved by creating Interfaces and injecting the implementations using IoC.

IoC can be provided by TinyIoC and the IoC inside of MvvmCross.

If for any reason your Xamarin Android project is missing Mono.Android reference, it can be manually added in the project's .csproj, by adding this line:

    <Reference Include="Mono.Android" />

This goes in the first "ItemGroup". Look for <Reference Include="mscorlib" />, and put it before that. (Order doesn't matter, it just needs to be inside an ItemGroup, but that is alphabetic order, so I put it there).

In my case, I had deleted obsolete references from an old Xamarin Android, and I thought that Mono.Android was out-of-date and would be reinstalled when I updated Xamarin Forms, so I deleted it. Mistake.

C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\Common7\IDE\ReferenceAssemblies\Microsoft\Framework\MonoAndroid\v8.1\Mono.Android.dll

For VS2017, the libarary can be found at above location.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top