jokeane
jokeane

Reputation: 333

MvvmCross - trying to use Fragments AND latest support lib results in linking problems

I'd like to use the SlidingPaneLayout or DrawerLayout, but these require a newer support library. Xamarin has one in the component store (Android Support Library v4 (Rev 18).

But if I try to use this AND use the Mvvm Fragments support (which requires a reference to Mono.Android.Support.v4) I get linker errors like this:

error : Duplicate managed type found! Mappings between managed types and Java types must be unique. First Type: 'Android.Support.V4.App.FragmentManager/IOnBackStackChangedListenerImplementor, Xamarin.Android.Support.v4-r18, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'; Second Type: 'Android.Support.V4.App.FragmentManager/IOnBackStackChangedListenerImplementor, Mono.Android.Support.v4, Version=0.0.0.0, Culture=neutral, PublicKeyToken=84e04ff9cfb79065'

Removing the old support library reference results in a different linker error;

error CS0012: The type Android.Support.V4.App.FragmentActivity' is defined in an assembly that is not referenced. Consider adding a reference to assemblyMono.Android.Support.v4, Version=0.0.0.0, Culture=neutral, PublicKeyToken=84e04ff9cfb79065'

Upvotes: 4

Views: 1892

Answers (1)

Stuart
Stuart

Reputation: 66882

I believe this is a general problem caused by Xamarin rebranding an assembly from 'Mono' to 'Xamarin'.

Third party assemblies like MvvmCross and others like the Google Play services component currently link against the 'Mono'-named assembly which ships with Xamarin.Android (formerly Mono for Android).

Currently, MvvmCross can't change it's linking to the 'Xamarin' named assembly without removing support for Maps v2 via the Google Play component - and we have more users currently demanding support for maps then demanding support for the navigation drawer in the latest support library.


If anyone needs to link against the 'Xamarin'-named assembly, then you need some way to redirect assemblies to work with the changed name. Ways I know of doing this are:

  • In full .Net I believe you can do this using 'binding redirects' in an app.config file, but I don't think these are available in Xamarin.Android.
  • You might instead be able to do the redirects using a dummy 'Mono.Android.Support.v4' assembly which contains only [TypeForwardedTo] declarations of types - generating this would be a bit tedious but should work. I tried to generate a TypeForwardTo assembly - https://gist.github.com/slodge/6790040 - but I think the fact that Xamarin have used assembly strong naming means I can't get this to work :/ Xamarin might be able to though?
  • You could fork and rebuild the existing MvvmCross 'Fragging' assembly - it's not large - so that it references the 'Xamarin'-named component. You would also need to do this for any other assemblies you need - e.g. the Google Play one for maps.

Upvotes: 1

Related Questions