fivenine-zurich / UnifiedMaps

A platform independent map implementation for Xamarin.Forms
MIT License
35 stars 12 forks source link

Not able to run my project #59

Closed davbaron closed 6 years ago

davbaron commented 6 years ago

Hello,

I had contacted the guys about the following issue I was having in trying to get UM to work in my app. Here is the initial note:

I am using Visual Studio 2017 on my Win 10 machine with Xamarin Forms 2.4x and Prism 7.x. I have a very small 'sample' app of my own that I use to test things with before tampering with my main project. I used Nuget to get your package and installed it in my Android app. I then copied some of the code from your own Sample project into a page of my own, just to see if I could get it working. It does not. While it does build, it does not run, failing at the UnifiedMap.Init(this, bundle) line in the OnCreate method in the Android MainActivity.cs file.

The specific error is: Unhandled Exception: System.MissingMethodException: Method 'Android.Gms.Common.Zze.IsGooglePlayServicesAvailable' not found.

I have already added my api key and permissions as specified. I have not installed any other packages. Do I need to download and install something else?

I also tried Nuget-ing several packages that I saw in your own Sample's Android csproj file: Xamarin.GooglePlayServices.Base, Xamarin.GooglePlayServices.Basement, Xamarin.GooglePlayServices.Maps and Xamarin.GooglePlayServices..Tasks. All of them were 'rejected' by the installer. It appears that those packages need MonoAndroid, Version 8.0, and I 'only' have Version 7.1. I am not sure what to do at this point (only been developing in Xamarin for a couple of months...

Thanks!

-David

EDIT: Jan answered within hours. He pointed out that I mistakenly tried installing the 'latest' versions of the GooglePlay service packages, instead of the ones I found referenced in his sample app: 42.1021.1. I did as Jan instructed and boom, I got past the init() call. Unfortunately though, I cannot get any further.

The app crashes with no 'output' other than: An unhandled exception occured.

I even tried removing all attributes from the UnifiedMap element except its 'name', so, really just the element opening and closing tags. I also commented out all the code in the viewmodel, just in case. Still crashes. Here are the final lines from the Output window, just in case they mean something: 01-26 01:11:05.155 D/Mono (30394): Assembly Ref addref UnifiedMap[0xa35b9be0] -> System.ObjectModel[0xb327bb60]: 3 01-26 01:11:05.226 W/System (30394): ClassLoader referenced unknown path: /data/data/com.google.android.gms/app_chimera/m/00000012/n/armeabi 01-26 01:11:05.275 I/Google Maps Android API(30394): Google Play services client version: 10298000 An unhandled exception occured.

01-26 01:11:05.284 I/Google Maps Android API(30394): Google Play services package version: 11951430

The only way I can run the app is to comment out the UnifiedMap element altogether.

I am testing on a LG G3, running Android 6.0.

Thank you for your help.

veryhumble commented 6 years ago

Thanks for creating the Issue.

Just to clarify, you did call UnifiedMap.Init (this, bundle); in your MainActivity's onCreate?

I don't really know whats causing that error, can't reproduce it. But some general things you could try:

Did you also try with the sample app?

davbaron commented 6 years ago

Hello,

Yes, I do call the UnifiedMap.Init (this, bundle); in my MainActivity's onCreate.

I cannot seem to run an emulator at all, for any project. I understand that is my issue, but for whatever reason I am unable to run Android emulators. That is why I use an old phone of mine, the LG G3 (Android 6.0).

I removed the 3 items you specified from my LG phone and re-built/run. That did not help.

I have not tried the Sample app - I am sure that would work. But I need to be able to run an app similar to my test app - which is a 'master-detail' app based on Prism. I have zipped up my test app and included it with this note. You will see that my app is mostly empty. I cut-pasted the 'map element' from 'child page 0' to 'child page 1'. You will see. I can open the app find since it opens on 'child 0'. However trying to navigate to 'child 1' then crashes the app. For some reason the page cannot load if there is a map object on it. I am sure that if you ran this with your source you would immediately see the issue. It is 100% reproducible. I am hoping it is something stupid by me, that I have missed. If so, it might be something that others miss as well, and so this could help them. If it is a real but, well then I'm sure others would be affected.

Either way, thank you - I really look forward to using the tool.

-David Test.zip

veryhumble commented 6 years ago

Hi David,

Tried it out. But could not get it to run with target framework 8.0 on the android project, maybe it's an issue with visual studio for mac. I set it to 7.1 and removed all bin and obj folder manually. After that it started on my device (Nexus 5X 8.1). It should not matter for this issue.

One thing I could find is that you put the API key outside of the application in the XML. It should be like this:

<application android:label="AppMapProject1.Android">
    <meta-data android:name="com.google.android.maps.v2.API_KEY" android:value="--- API KEY HERE ---" />
</application>

Hope it helps.

davbaron commented 6 years ago

Hi Jan,

Well, I am getting much closer now. Yes, I failed to notice the application's open and close tags on the same line in the manifest... I changed it and now the app does not crash. However, the maps still come up as gray rects (with the Google logo inside it). The key value I am using is the exact same value that I have working correctly in a web project I am also developing. I should be able to use the same key value in different 'types' of apps/sites, right?

Just as a test, I have 'filled up' the Pins collection within the viewmodel constructor, so that I have pins at the start. I have debugged the app (code-behind .cs file) and seen that there are items in the Pins collection. The 'AddPin' command also seems to work great, but the map is always gray. I will try to see I can find out about whether I need a separate api key for apps versus web sites.

Thanks again!

veryhumble commented 6 years ago

You will need a Google Maps Android API key not for Javascript/iOS.

https://console.developers.google.com/apis/library/maps-android-backend.googleapis.com

davbaron commented 6 years ago

Good news! I learned that the API Key I had previously created was only good for the Javascript web site I'm also building. Once I created a new Android key, the map shows up just fine! I do have another issue or two but I will open a new case for those.

Thank you again!

davbaron commented 6 years ago

Yes Jan, sorry - we were typing at almost the same think at the same moment!

Thank you for your patience in working with a new Xamarin developer... I am on my way!

-David