Alexey Strakh Alexey Strakh - 22 days ago 10
Android Question

Unable to register for pushes "was expected to be of type virtual" in my Xamarin MvvmCross Android app

I have a Xamarin MvvmCross Android app API 4.1+ which uses pushes and mapping abilities of the platform. After recent update of packages I no longer able to register for pushed. In my

PushRegistrationListener
(intent handler service) I'm handling registration event and getting error on
var instanceID = InstanceID.GetInstance(this);
:


The method 'java.io.File
android.support.v4.content.ContextCompat.getNoBackupFilesDir(android.content.Context)'
was expected to be of type virtual but instead was found to be of type
direct (declaration of 'java.lang.reflect.ArtMethod' appears in
/system/framework/core-libart.jar)


I found lots of references about known goodle issue and outdated support library version but all of them are half year old and not applicable as long as I have higher version of referenced packages. These are my packages:

<package id="Xamarin.Android.Support.Animated.Vector.Drawable" version="24.2.1" targetFramework="monoandroid70" />
<package id="Xamarin.Android.Support.Compat" version="24.2.1" targetFramework="monoandroid70" />
<package id="Xamarin.Android.Support.Core.UI" version="24.2.1" targetFramework="monoandroid70" />
<package id="Xamarin.Android.Support.Core.Utils" version="24.2.1" targetFramework="monoandroid70" />
<package id="Xamarin.Android.Support.Fragment" version="24.2.1" targetFramework="monoandroid70" />
<package id="Xamarin.Android.Support.Media.Compat" version="24.2.1" targetFramework="monoandroid70" />
<package id="Xamarin.Android.Support.v4" version="24.2.1" targetFramework="monoandroid70" />
<package id="Xamarin.Android.Support.v7.AppCompat" version="24.2.1" targetFramework="monoandroid70" />
<package id="Xamarin.Android.Support.Vector.Drawable" version="24.2.1" targetFramework="monoandroid70" />
<package id="Xamarin.GooglePlayServices.Analytics" version="29.0.0.2" targetFramework="MonoAndroid60" />
<package id="Xamarin.GooglePlayServices.Base" version="29.0.0.2" targetFramework="MonoAndroid60" />
<package id="Xamarin.GooglePlayServices.Basement" version="29.0.0.2" targetFramework="MonoAndroid60" />
<package id="Xamarin.GooglePlayServices.Gcm" version="29.0.0.2" targetFramework="MonoAndroid60" />
<package id="Xamarin.GooglePlayServices.Location" version="29.0.0.2" targetFramework="MonoAndroid60" />
<package id="Xamarin.GooglePlayServices.Maps" version="29.0.0.2" targetFramework="MonoAndroid60" />
<package id="Xamarin.GooglePlayServices.Measurement" version="29.0.0.2" targetFramework="MonoAndroid60" />


Please advise how can I debug this issue.

Answer

The issue is that you are using an old version of the Google Play Services SDK. Even though it is the latest stable version currently (14 November 2016) offered by Xamarin, it does not include the fix that Google implemented in version 9.0.1.

Fixes a class change compilation error with ContextCompat.getNoBackupFilesDir().

Xamarin's mapping of version numbers for the Google Play Services Nuget packages are not nicely mapped to that of the official Google Play Services version numbers. It has been logged as an issue on GitHub and they have started to address this by providing a table of the mappings:

Nuget mappings to Google Play Services

So in order to get a working version of the Google Play Service SDK you will have to use a version of Xamarin.GooglePlayServices greater than 30.0.1.alpha4.

There is also an issue logged on xamarin/GooglePlayServicesComponents which was resolved via updating to the latest Beta Nuget packages.