androidxamarin.formsxamarin.forms.maps

Xamarin Forms, Android - Java.Lang.ClassNotFoundException


I'm currently updating a Xamarin Forms App and suddenly experiencing this error on Android:

Exception   {Java.Lang.ClassNotFoundException: Didn't find class "com.google.android.gms.common.GooglePlayServicesUtil" on path: DexPathList[[zip file "/data/app/com.alphacoreconsulting.tflmetrosound-Ek3U1cNyzLe9Jayp9enzXQ==/base.apk"],nativeLibraryDirectories=[/data/app/c…} Java.Lang.ClassNotFoundException

It triggers on this line:

Xamarin.FormsMaps.Init(this, bundle);

I've researched and I've ensured all packages are the same version:

enter image description here

Please would anyone be able to offer some help on this?

UPDATE:

I have since updated the proguard.cfg file and added this line:

-keep public class com.google.android.gms.common.GooglePlayServicesUtil

After adding this I am now experiencing this error:

no static method "Lcom/google/android/gms/common/GooglePlayServicesUtil;.isGooglePlayServicesAvailable(Landroid/content/Context;)I"

Solution

  • You will see this exception at runtime when code has been stripped from the executable usually by the linker or R8/Proguard. You can provide a configuration file to both tools allowing you to keep code the linker or R8/Proguard think you are not using. These tools are not able to properly detect code you use at runtime via reflection for example.

    Here is the documentation for the linker configuration file. Another approach is to use a "LinkerPleaseInclude.cs" file manually referencing the code you do not want to be linked out.

    Here is the documentation for the R8/Proguard configuration file.