amay077 / Xamarin.Forms.GoogleMaps

Map library for Xamarin.Forms using Google maps API
https://www.nuget.org/packages/Xamarin.Forms.GoogleMaps/
MIT License
545 stars 346 forks source link

Map crashes on Android 9, 10, 11 (Simulator, Xamarin Shell) #755

Closed PaoloLeva closed 3 years ago

PaoloLeva commented 3 years ago

VERSIONS

PLATFORMS

ACTUAL BEHAVIOR

I have taken a sample Shell Xamarin Forms App and added GoogleMaps. On Android it works on Android 7 and 8, but if I use Android 9, 10 or 11 as soon as the map appears the app crashes. It works well on iOS. I only tested on Emulators. I set the Minimum Android version to 7.0 and I tried setting different values for Target version but without any change

ACTUAL SCREENSHOTS/STACKTRACE

When I click on the Tab in my test app on containing the map on Android 9 ,10, or 11, I see the map for a split second and then the app crashes/closes down. It does not crash in the code is just the app on the device that closes down. In Android 7 and 8 the map is shown correctly.

In the Application Output window I see the following:

[AndroidRuntime] FATAL EXCEPTION: Thread-14
[AndroidRuntime] Process: com.paololeva.geoquizapp, PID: 5691
[AndroidRuntime] java.lang.NoClassDefFoundError: Failed resolution of: Lorg/apache/http/ProtocolVersion;
[AndroidRuntime]    at cz.b(:com.google.android.gms.dynamite_mapsdynamite@204215068@20.42.15 (100700-0):2)
[AndroidRuntime]    at cy.a(:com.google.android.gms.dynamite_mapsdynamite@204215068@20.42.15 (100700-0):1)
[AndroidRuntime]    at cf.a(:com.google.android.gms.dynamite_mapsdynamite@204215068@20.42.15 (100700-0):16)
[AndroidRuntime]    at cf.run(:com.google.android.gms.dynamite_mapsdynamite@204215068@20.42.15 (100700-0):2)
[AndroidRuntime] Caused by: java.lang.ClassNotFoundException: Didn't find class "org.apache.http.ProtocolVersion" on path: DexPathList[[zip file "/data/user_de/0/com.google.android.gms/app_chimera/m/0000000e/MapsDynamite.apk"],nativeLibraryDirectories=[/data/user_de/0/com.google.android.gms/app_chimera/m/0000000e/MapsDynamite.apk!/lib/x86, /data/user_de/0/com.google.android.gms/app_chimera/m/0000000e/MapsDynamite.apk!/lib/armeabi-v7a, /data/user_de/0/com.google.android.gms/app_chimera/m/0000000e/MapsDynamite.apk!/lib/armeabi, /system/lib]]
[AndroidRuntime]    at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:134)
[AndroidRuntime]    at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
[AndroidRuntime]    at az.loadClass(:com.google.android.gms.dynamite_dynamiteloader@204215068@20.42.15 (100700-0):3)
[AndroidRuntime]    at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
[AndroidRuntime]    ... 4 more
[] Thread 0xcb3ef970 may have been prematurely finalized
[] * Assertion at /Users/builder/jenkins/workspace/archive-mono/2020-02/android/release/mono/utils/mono-threads.c:650, condition `info' not met, function:mono_thread_info_current, 
[libc] Fatal signal 6 (SIGABRT), code -6 (SI_TKILL) in tid 5792 (Thread-14), pid 5691 (leva.geoquizapp)

EXPECTED BEHAVIOR

The tab with the Map should be shown as in Android 7 and 8 and in iOS.

HOW TO REPRODUCE

I use the standard code for Shell Xamarin Forms Apps with only the changes required to include GoogleMaps package.

here is my page (the one that crashes)

<?xml version="1.0" encoding="utf-8"?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             x:Class="GeoQuizApp.Views.AboutPage"
             xmlns:vm="clr-namespace:GeoQuizApp.ViewModels"
             xmlns:maps="clr-namespace:Xamarin.Forms.GoogleMaps;assembly=Xamarin.Forms.GoogleMaps"
             Title="{Binding Title}">
    <ContentPage.BindingContext>
        <vm:AboutViewModel />
    </ContentPage.BindingContext>
    <ContentPage.Content>
        <maps:Map />
    </ContentPage.Content>
</ContentPage>

the code behind is just standard it only calls InitializeComponent() and also the ViewModel contains only standard code.

Here is my "MainActivity.cs"

using System;
using Android.App;
using Android.Content.PM;
using Android.Runtime;
using Android.Views;
using Android.Widget;
using Android.OS;

namespace GeoQuizApp.Droid
{
    [Activity(Label = "GeoQuizApp", Icon = "@mipmap/icon", Theme = "@style/MainTheme", MainLauncher = true, ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation | ConfigChanges.UiMode | ConfigChanges.ScreenLayout | ConfigChanges.SmallestScreenSize)]
    public class MainActivity : global::Xamarin.Forms.Platform.Android.FormsAppCompatActivity
    {
        protected override void OnCreate(Bundle savedInstanceState)
        {
            TabLayoutResource = Resource.Layout.Tabbar;
            ToolbarResource = Resource.Layout.Toolbar;

            base.OnCreate(savedInstanceState);

            Xamarin.Essentials.Platform.Init(this, savedInstanceState);
            global::Xamarin.Forms.Forms.Init(this, savedInstanceState);
            Xamarin.FormsGoogleMaps.Init(this, savedInstanceState); //Initialize GoogleMaps here
            LoadApplication(new App());
        }
        public override void OnRequestPermissionsResult(int requestCode, string[] permissions, [GeneratedEnum] Android.Content.PM.Permission[] grantResults)
        {
            Xamarin.Essentials.Platform.OnRequestPermissionsResult(requestCode, permissions, grantResults);

            base.OnRequestPermissionsResult(requestCode, permissions, grantResults);
        }
    }
}

I added the API key in the manifest, and this is correct as I can test in Android 7 and 8

PaoloLeva commented 3 years ago

I tested the same on a Xamarin Forms "Blank App" (instead of Shell) and I get the same behavior. It works on Android 7 and 8, but it crashes on Android 9, 10 ,11

PaoloLeva commented 3 years ago

I saw this in the Application Output window, maybe it helps?

[AndroidRuntime] FATAL EXCEPTION: Thread-14
[AndroidRuntime] Process: com.paololeva.geoquizapp, PID: 5691
[AndroidRuntime] java.lang.NoClassDefFoundError: Failed resolution of: Lorg/apache/http/ProtocolVersion;
[AndroidRuntime]    at cz.b(:com.google.android.gms.dynamite_mapsdynamite@204215068@20.42.15 (100700-0):2)
[AndroidRuntime]    at cy.a(:com.google.android.gms.dynamite_mapsdynamite@204215068@20.42.15 (100700-0):1)
[AndroidRuntime]    at cf.a(:com.google.android.gms.dynamite_mapsdynamite@204215068@20.42.15 (100700-0):16)
[AndroidRuntime]    at cf.run(:com.google.android.gms.dynamite_mapsdynamite@204215068@20.42.15 (100700-0):2)
[AndroidRuntime] Caused by: java.lang.ClassNotFoundException: Didn't find class "org.apache.http.ProtocolVersion" on path: DexPathList[[zip file "/data/user_de/0/com.google.android.gms/app_chimera/m/0000000e/MapsDynamite.apk"],nativeLibraryDirectories=[/data/user_de/0/com.google.android.gms/app_chimera/m/0000000e/MapsDynamite.apk!/lib/x86, /data/user_de/0/com.google.android.gms/app_chimera/m/0000000e/MapsDynamite.apk!/lib/armeabi-v7a, /data/user_de/0/com.google.android.gms/app_chimera/m/0000000e/MapsDynamite.apk!/lib/armeabi, /system/lib]]
[AndroidRuntime]    at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:134)
[AndroidRuntime]    at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
[AndroidRuntime]    at az.loadClass(:com.google.android.gms.dynamite_dynamiteloader@204215068@20.42.15 (100700-0):3)
[AndroidRuntime]    at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
[AndroidRuntime]    ... 4 more
[] Thread 0xcb3ef970 may have been prematurely finalized
[] * Assertion at /Users/builder/jenkins/workspace/archive-mono/2020-02/android/release/mono/utils/mono-threads.c:650, condition `info' not met, function:mono_thread_info_current, 
[libc] Fatal signal 6 (SIGABRT), code -6 (SI_TKILL) in tid 5792 (Thread-14), pid 5691 (leva.geoquizapp)
PaoloLeva commented 3 years ago

I found a solution here: https://developers.google.com/maps/documentation/android-sdk/config#specify_requirement_for_apache_http_legacy_library If you have the same problem please follow the instructions above