'Add mono.android reference Xamarin.Forms

Im working on a Xamarin.Forms project and I need to work with mono.android things. The problem is that in a project before, I do have the reference, but in the new one, I Cannot add it. Is there a way to do it ? or while creating the project ? or something ?

This is the project where I have Mono.Android

I dont have it in this one



Solution 1:[1]

In solution explorer, right click on References. Click on Add Reference. Click on Browse on the left panel. Verify the mono.android has a check mark on it. Click on Browse in the bottom.

Enter this path: C:\Program Files (x86)\Microsoft VisualStudio\2017\Community\Common7\IDE\ReferenceAssemblies\Microsoft\Framework\MonoAndroid\v8.1

Select Mono.Android.dll. This should add the reference to mono.android!

Solution 2:[2]

I've read that you have to remove your references in a PCL project or use DependencyService but I didn't understand very well how to do it, so I came with a (not very orthodox) solution:

I copied from VS Windows in a Windows machine the Mono.Android.dll, Java.Interop.dll and the Xamarin.iOS.dll to the root folder on my project on VS Mac, then make the following references on the project's file:

<ItemGroup>
  <Reference Include="Mono.Android">
    <HintPath>Mono.Android.dll</HintPath>
  </Reference>
  <Reference Include="Java.Interop">
    <HintPath>Java.Interop.dll</HintPath>
  </Reference>
  <Reference Include="Xamarin.iOS">
    <HintPath>Xamarin.iOS.dll</HintPath>
  </Reference>
</ItemGroup>

Then I added the assembly reference on Android's folder

enter image description here

And in the .NET Assembly tab, I browsed for the dll's (Mono.Android + Java.Interop for Android and Xamarin.iOS + Java.Interop for iOS)

enter image description here

And my project compiled on VS Mac.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Jay
Solution 2 benjamingranados