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

Project is failed to start on IOS, breaks in UpdateIsShowingUser #753

Open DanielLavrushin opened 3 years ago

DanielLavrushin commented 3 years ago

Hi, I have the following issue in an almost default project (including the example one from the repository). It is failing when deploying to IOS (in my case iPhone phisical device). The app is trying to start but then crashes to the OS. Visual Studio does not catch the break point.

In the output window I get this:

Loaded assembly: /private/var/mobile/Containers/Data/Application/BE8F87C7-8FB5-4F76-9674-03D160780B77/Documents/XFGoogleMapSampleiOS.content/Xamarin.Forms.Xaml.dll [External] Loaded assembly: /private/var/containers/Bundle/Application/F4979BA1-4F02-476D-BB93-7A84EE654A10/XFGoogleMapSampleiOS.app/System.Xml.dll [External] Thread started: #4 Thread started: #5 Thread started: #6 Thread started: #7 Resolved pending breakpoint at 'BasicMapPage.xaml.cs:139,1' to void XFGoogleMapSample.BasicMapPage.<.ctor>b0_15 (object sender, Xamarin.Forms.GoogleMaps.CameraChangedEventArgs args) [0x00008]. Loaded assembly: /private/var/containers/Bundle/Application/F4979BA1-4F02-476D-BB93-7A84EE654A10/XFGoogleMapSampleiOS.app/System.Net.Http.dll [External] Loaded assembly: /private/var/containers/Bundle/Application/F4979BA1-4F02-476D-BB93-7A84EE654A10/XFGoogleMapSampleiOS.app/System.Drawing.Common.dll [External] [0:] An error occurred: 'Object reference not set to an instance of an object.'. Callstack: ' at Xamarin.Forms.GoogleMaps.iOS.MapRenderer.UpdateIsShowingUser (System.Nullable1[T] initialMyLocationButtonEnabled) <0x119727660 + 0x0007a> in :0 at Xamarin.Forms.GoogleMaps.iOS.MapRenderer.OnElementChanged (Xamarin.Forms.Platform.iOS.ElementChangedEventArgs1[TElement] e) <0x118649e28 + 0x002d0> in :0 at Xamarin.Forms.Platform.iOS.VisualElementRenderer1[TElement].SetElement (TElement element) [0x00134] in D:\a\1\s\Xamarin.Forms.Platform.iOS\VisualElementRenderer.cs:193 at Xamarin.Forms.Platform.iOS.VisualElementRenderer1[TElement].Xamarin.Forms.Platform.iOS.IVisualElementRenderer.SetElement (Xamarin.Forms.VisualElement element) [0x00000] in D:\a\1\s\Xamarin.Forms.Platform.iOS\VisualElementRenderer.cs:141 at Xamarin.Forms.Platform.iOS.Platform.CreateRenderer (Xamarin.Forms.VisualElement element) [0x00014] in D:\a\1\s\Xamarin.Forms.Platform.iOS\Platform.cs:199 at Xamarin.Forms.Platform.iOS.VisualElementPackager.OnChildAdded (Xamarin.Forms.VisualElement view) [0x0004f] in D:\a\1\s\Xamarin.Forms.Platform.iOS\VisualElementPackager.cs:79 at Xamarin.Forms.Platform.iOS.VisualElementPackager.Load () [0x0001e] in D:\a\1\s\Xamarin.Forms.Platform.iOS\VisualElementPackager.cs:46 at Xamarin.Forms.Platform.iOS.VisualElementRenderer1[TElement].SetElement (TElement element) [0x000f0] in D:\a\1\s\Xamarin.Forms.Platform.iOS\VisualElementRenderer.cs:180 at Xamarin.Forms.Platform.iOS.VisualElementRenderer1[TElement].Xamarin.Forms.Platform.iOS.IVisualElementRenderer.SetElement (Xamarin.Forms.VisualElement element) [0x00000] in D:\a\1\s\Xamarin.Forms.Platform.iOS\VisualElementRenderer.cs:141 at Xamarin.Forms.Platform.iOS.Platform.CreateRenderer (Xamarin.Forms.VisualElement element) [0x00014] in D:\a\1\s\Xamarin.Forms.Platform.iOS\Platform.cs:199 at Xamarin.Forms.Platform.iOS.VisualElementPackager.OnChildAdded (Xamarin.Forms.VisualElement view) [0x0004f] in D:\a\1\s\Xamarin.Forms.Platform.iOS\VisualElementPackager.cs:79 at Xamarin.Forms.Platform.iOS.VisualElementPackager.Load () [0x0001e] in D:\a\1\s\Xamarin.Forms.Platform.iOS\VisualElementPackager.cs:46 at Xamarin.Forms.Platform.iOS.PageRenderer.ViewDidLoad () [0x00086] in D:\a\1\s\Xamarin.Forms.Platform.iOS\Renderers\PageRenderer.cs:123 at (wrapper managed-to-native) ObjCRuntime.Messaging.IntPtr_objc_msgSendSuper(intptr,intptr) at UIKit.UIViewController.get_View () [0x0002a] in /Library/Frameworks/Xamarin.iOS.framework/Versions/14.2.0.12/src/Xamarin.iOS/UIKit/UIViewController.g.cs:3267 at Xamarin.Forms.Platform.iOS.PageRenderer.get_NativeView () [0x00000] in D:\a\1\s\Xamarin.Forms.Platform.iOS\Renderers\PageRenderer.cs:41 at Xamarin.Forms.Platform.iOS.PageRenderer.SetElement (Xamarin.Forms.VisualElement element) [0x0004f] in D:\a\1\s\Xamarin.Forms.Platform.iOS\Renderers\PageRenderer.cs:56 at Xamarin.Forms.Platform.iOS.Platform.CreateRenderer (Xamarin.Forms.VisualElement element) [0x00014] in D:\a\1\s\Xamarin.Forms.Platform.iOS\Platform.cs:199 at Xamarin.Forms.Platform.iOS.NavigationRenderer.CreateViewControllerForPage (Xamarin.Forms.Page page) [0x00008] in D:\a\1\s\Xamarin.Forms.Platform.iOS\Renderers\NavigationRenderer.cs:357 at Xamarin.Forms.Platform.iOS.NavigationRenderer.OnPushAsync (Xamarin.Forms.Page page, System.Boolean animated) [0x0001d] in D:\a\1\s\Xamarin.Forms.Platform.iOS\Renderers\NavigationRenderer.cs:344 at Xamarin.Forms.Platform.iOS.NavigationRenderer.b__42_0 (Xamarin.Forms.Page p) [0x00024] in D:\a\1\s\Xamarin.Forms.Platform.iOS\Renderers\NavigationRenderer.cs:228 at System.Runtime.CompilerServices.AsyncMethodBuilderCore+<>c.b7_0 (System.Object state) [0x00000] in /Library/Frameworks/Xamarin.iOS.framework/Versions/Current/src/Xamarin.iOS/mcs/class/referencesource/mscorlib/system/runtime/compilerservices/AsyncMethodBuilder.cs:1021 at (wrapper delegate-invoke) .invoke_void_object(object) at Foundation.NSAsyncSynchronizationContextDispatcher.Apply () [0x00000] in /Library/Frameworks/Xamarin.iOS.framework/Versions/14.2.0.12/src/Xamarin.iOS/Foundation/NSAction.cs:178

--- End of stack trace from previous location where exception was thrown ---

at (wrapper managed-to-native) UIKit.UIApplication.UIApplicationMain(int,string[],intptr,intptr) at UIKit.UIApplication.Main (System.String[] args, System.IntPtr principal, System.IntPtr delegate) [0x00005] in /Library/Frameworks/Xamarin.iOS.framework/Versions/14.2.0.12/src/Xamarin.iOS/UIKit/UIApplication.cs:86 at UIKit.UIApplication.Main (System.String[] args, System.String principalClassName, System.String delegateClassName) [0x0000e] in /Library/Frameworks/Xamarin.iOS.framework/Versions/14.2.0.12/src/Xamarin.iOS/UIKit/UIApplication.cs:65 at XFGoogleMapSample.iOS.Application.Main (System.String[] args) [0x00001] in C:\Projects\Xamarin.Forms.GoogleMaps-master\XFGoogleMapSample\iOS\Main.cs:17 at (wrapper managed-to-native) System.Reflection.RuntimeMethodInfo.InternalInvoke(System.Reflection.RuntimeMethodInfo,object,object[],System.Exception&) at System.Reflection.RuntimeMethodInfo.Invoke (System.Object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x0006a] in /Library/Frameworks/Xamarin.iOS.framework/Versions/Current/src/Xamarin.iOS/mcs/class/corlib/System.Reflection/RuntimeMethodInfo.cs:395 ' The app has been terminated.

First, I tried on my local project. After, I decided to get the source code of the googlemaps libray from git hub and debug it. It breaks in the MapRenderer.cs

  private void UpdateIsShowingUser(bool? initialMyLocationButtonEnabled = null)
        {
#pragma warning disable 618
            ((MapView)Control).MyLocationEnabled = ((Map)Element).IsShowingUser;
            ((MapView)Control).Settings.MyLocationButton = initialMyLocationButtonEnabled ?? ((Map)Element).IsShowingUser;
#pragma warning restore 618
        }

Apparently the native Google.Maps.MapView.Settings is null here. I am not sure what exacly am I doing wrong, but the same library works perfect in Andoid version. It only fails in IOS.

I have set up API keys and API on google developer console.

Visual Studio Version 16.7.7 IOS 14.1 Xamarin.iOS 14.2.0.12 I also tried the standard xamarin google maps lirary and it works fine (it just miss many features comparing to Xamarin.Forms.GoogleMaps).

Any ideas what is wrong here?

themronion commented 3 years ago

are u trying with Hot Restart?

gjhdigital commented 3 years ago

Im having same or similar issue. And from what Ive read on Xamarin.Forms.Maps, iOS 14 changed some callback methods and is causing the crash. Try this fix too. https://forums.xamarin.com/discussion/185275/xamarin-4-8-apps-crashing-with-xcode-12-and-ios14

Davidoutz commented 3 years ago

I think I am having a similar issue although I am able to start the app. No way to work it around with the proposed solution. Working great on simulator though.

When ever I am showing a map on Iphone device iOS 14+ it shows a full black screen. I was able to catch this stacktrace once:

[0:] An error occurred: 'Object reference not set to an instance of an object.'. Callstack: '  at Xamarin.Forms.GoogleMaps.iOS.MapRenderer.UpdateIsShowingUser (System.Nullable`1[T] initialMyLocationButtonEnabled) <0x117b47e88 + 0x0007a> in <c613a8dd57764697aab63c2c7c8919d7>:0 
  at Xamarin.Forms.GoogleMaps.iOS.MapRenderer.OnElementChanged (Xamarin.Forms.Platform.iOS.ElementChangedEventArgs`1[TElement] e) <0x117b34818 + 0x002d0> in <c613a8dd57764697aab63c2c7c8919d7>:0 
  at Xamarin.Forms.Platform.iOS.VisualElementRenderer`1[TElement].SetElement (TElement element) [0x00172] in D:\a\1\s\Xamarin.Forms.Platform.iOS\VisualElementRenderer.cs:296 
  at Xamarin.Forms.Platform.iOS.VisualElementRenderer`1[TElement].Xamarin.Forms.Platform.iOS.IVisualElementRenderer.SetElement (Xamarin.Forms.VisualElement element) [0x00000] in D:\a\1\s\Xamarin.Forms.Platform.iOS\VisualElementRenderer.cs:158 
  at Xamarin.Forms.Platform.iOS.Platform.CreateRenderer (Xamarin.Forms.VisualElement element) [0x00014] in D:\a\1\s\Xamarin.Forms.Platform.iOS\Platform.cs:227 
  at Xamarin.Forms.Platform.iOS.VisualElementPackager.OnChildAdded (Xamarin.Forms.VisualElement view) [0x0003e] in D:\a\1\s\Xamarin.Forms.Platform.iOS\VisualElementPackager.cs:115 
  at Xamarin.Forms.Platform.iOS.VisualElementPackager.Load () [0x0001e] in D:\a\1\s\Xamarin.Forms.Platform.iOS\VisualElementPackager.cs:49 
  at Xamarin.Forms.Platform.iOS.VisualElementRenderer`1[TElement].SetElement (TElement element) [0x0012e] in D:\a\1\s\Xamarin.Forms.Platform.iOS\VisualElementRenderer.cs:283 
  at Xamarin.Forms.Platform.iOS.VisualElementRenderer`1[TElement].Xamarin.Forms.Platform.iOS.IVisualElementRenderer.SetElement (Xamarin.Forms.VisualElement element) [0x00000] in D:\a\1\s\Xamarin.Forms.Platform.iOS\VisualElementRenderer.cs:158 
  at Xamarin.Forms.Platform.iOS.Platform.CreateRenderer (Xamarin.Forms.VisualElement element) [0x00014] in D:\a\1\s\Xamarin.Forms.Platform.iOS\Platform.cs:227 
  at Xamarin.Forms.Platform.iOS.VisualElementPackager.OnChildAdded (Xamarin.Forms.VisualElement view) [0x0003e] in D:\a\1\s\Xamarin.Forms.Platform.iOS\VisualElementPackager.cs:115 
  at Xamarin.Forms.Platform.iOS.VisualElementPackager.Load () [0x0001e] in D:\a\1\s\Xamarin.Forms.Platform.iOS\VisualElementPackager.cs:49 
  at Xamarin.Forms.Platform.iOS.PageRenderer.ViewDidLoad () [0x0008f] in D:\a\1\s\Xamarin.Forms.Platform.iOS\Renderers\PageRenderer.cs:237 
  at (wrapper managed-to-native) ObjCRuntime.Messaging.IntPtr_objc_msgSendSuper(intptr,intptr)
  at UIKit.UIViewController.get_View () [0x0002a] in /Library/Frameworks/Xamarin.iOS.framework/Versions/14.4.1.3/src/Xamarin.iOS/UIKit/UIViewController.g.cs:3267 
  at Xamarin.Forms.Platform.iOS.PageRenderer.get_NativeView () [0x00000] in D:\a\1\s\Xamarin.Forms.Platform.iOS\Renderers\PageRenderer.cs:103 
  at Xamarin.Forms.Platform.iOS.PageRenderer.SetElement (Xamarin.Forms.VisualElement element) [0x0003d] in D:\a\1\s\Xamarin.Forms.Platform.iOS\Renderers\PageRenderer.cs:119 
  at Xamarin.Forms.Platform.iOS.Platform.CreateRenderer (Xamarin.Forms.VisualElement element) [0x00014] in D:\a\1\s\Xamarin.Forms.Platform.iOS\Platform.cs:227 
  at Xamarin.Forms.Platform.iOS.NavigationRenderer.CreateViewControllerForPage (Xamarin.Forms.Page page) [0x00008] in D:\a\1\s\Xamarin.Forms.Platform.iOS\Renderers\NavigationRenderer.cs:376 
  at Xamarin.Forms.Platform.iOS.NavigationRenderer.OnPushAsync (Xamarin.Forms.Page page, System.Boolean animated) [0x0001d] in D:\a\1\s\Xamarin.Forms.Platform.iOS\Renderers\NavigationRenderer.cs:352 
  at Xamarin.Forms.Platform.iOS.NavigationRenderer.<ViewDidLoad>b__47_0 (Xamarin.Forms.Page p) [0x00024] in D:\a\1\s\Xamarin.Forms.Platform.iOS\Renderers\NavigationRenderer.cs:239 
  at System.Runtime.CompilerServices.AsyncMethodBuilderCore+<>c.<ThrowAsync>b__7_0 (System.Object state) [0x00000] in /Library/Frameworks/Xamarin.iOS.framework/Versions/Current/src/Xamarin.iOS/mcs/class/referencesource/mscorlib/system/runtime/compilerservices/AsyncMethodBuilder.cs:1021 
  at (wrapper delegate-invoke) <Module>.invoke_void_object(object)
  at Foundation.NSAsyncSynchronizationContextDispatcher.Apply () [0x00000] in /Library/Frameworks/Xamarin.iOS.framework/Versions/14.4.1.3/src/Xamarin.iOS/Foundation/NSAction.cs:178 
--- End of stack trace from previous location where exception was thrown ---

Now I am still getting the black screen but I can't manage to raise this exception again. From the output window everything looks working great.. Can anyone help?

themronion commented 3 years ago

@Davidoutz are u using iOS Hot Restart?

Davidoutz commented 3 years ago

@themronion sorry I didn't see, thanks for quick reply btw. Yes I am using hot restart. Shall I disable it ? (I can try in a couple hours I don't have access to the device atm)

themronion commented 3 years ago

@Davidoutz the library won't work with hot restart, after u try building the app on a mac like before everything will be fine