0

I am trying to add google maps support to my android app. As I create whole application layout in code, I would like to create also the map object in code. This is class that should handle OnMapReady callback function.

public class MapReader : Java.Lang.Object, IOnMapReadyCallback
{
    private LayoutBuilder layoutBuilder;
    public MapReader(LayoutBuilder lb)
    {
        layoutBuilder = lb;
    }
    public void OnMapReady(GoogleMap googleMap)
    {
        layoutBuilder.OnMapLoaded(googleMap);
    }
}

This is critical part of code creating the layout.

MapView mapView=new MapView(context);
mapView.LayoutParameters = layoutParams;
linearLayout.AddView(mapView);

mapReader = new MapReader(this);
mapView.GetMapAsync(mapReader);

The problem is that I get no error/exception. The OnMapReady function is never called and the screen is just empty. What can be wrong or how can I get additional info about such a behavior? I tried to follow steps from this video. In output window I tried to find lines that could help:

Loaded assembly: /storage/emulated/0/Android/data/AlienChessAndroid.AlienChessAndroid/files/.__override__/Xamarin.GooglePlayServices.Base.dll [External]
Loaded assembly: /storage/emulated/0/Android/data/AlienChessAndroid.AlienChessAndroid/files/.__override__/Xamarin.GooglePlayServices.Basement.dll [External]
Loaded assembly: /storage/emulated/0/Android/data/AlienChessAndroid.AlienChessAndroid/files/.__override__/Xamarin.GooglePlayServices.Maps.dll [External]

There are a few lines in output window that don't look good but the application runs.

AOT module 'Mono.Android.dll.so' not found: dlopen failed: library "/data/app/AlienChessAndroid.AlienChessAndroid-1/lib/arm/libaot-Mono.Android.dll.so" not found
AOT module '/storage/emulated/0/Android/data/AlienChessAndroid.AlienChessAndroid/files/.__override__/Xamarin.Android.Support.v4.dll.so' not found: dlopen failed: library "/data/app/AlienChessAndroid.AlienChessAndroid-1/lib/arm/libaot-Xamarin.Android.Support.v4.dll.so" not found
AOT module '/Users/builder/data/lanes/4009/3a62f1ea/source/monodroid/builds/install/mono-armv7/lib/mono/aot-cache/arm/Xamarin.Android.Support.v4.dll.so' not found: dlopen failed: library "/data/app/AlienChessAndroid.AlienChessAndroid-1/lib/arm/libaot-Xamarin.Android.Support.v4.dll.so" not found

This is my manifest file

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="AlienChessAndroid.AlienChessAndroid" android:versionCode="1" android:versionName="1.0" android:installLocation="preferExternal">
<uses-sdk android:minSdkVersion="22" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<application android:label="Alien Chess" android:icon="@drawable/Alien" android:largeHeap="true">
    <meta-data android:name="com.google.android.gms.version" android:value="2" />
    <meta-data android:name="com.google.android.maps.v2.API_KEY" android:value="AIzaSyAmxxxxxxxxxxxxxxxxxxxxxxxxx" />
</application>

UPDATE:

I added checking for google services availability as is shown here and it returns ConnectionResult.Success.

GoogleApiAvailability gaa=GoogleApiAvailability.Instance;
int resultCode=gaa.IsGooglePlayServicesAvailable(context);
if (resultCode ==ConnectionResult.Success)
{
    ...
}

After reading this question I changed the line

<meta-data android:name="com.google.android.gms.version" android:value="2" />

for

<meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version" />

Nothing changed.

hoacin
  • 340
  • 1
  • 2
  • 19

1 Answers1

1

In you I would try to create LinearLayout and MapView inside your layout axml (if you can) to be sure that it's as it should be, getting the map when it's time to call the GetMapAsync using FindViewById<MapView> on it's resource id.

Setup of the map and the call of GetMapAsync should be done inside OnStart and OnResume.

After you created your IOnMapReadyCallback you could also try to add directly an event handler like this to see if it's called:

mapReader.MapReady += (sender, args) => { };

Try also your code both on a device with one of the latest Android version but also on a Android 5.x so you are sure that you haven't problem with requesting of permissions at runtime introduced with Android 6.0.

Mauro Piccotti
  • 1,807
  • 2
  • 23
  • 34