Problem with Maps API v2

alberto.palberto.p ITMember ✭✭

I download and compile MapsAndLocationDemo_v2 from github.
I set my new Api Key (from debug.keystore), but when I run application I get “Failed to load map. Could not contact Google servers.” at console.
Where I’m wrong?

I tryed to build google-play-services_lib with ant with my batch file:

cd google-play-services_lib
android update project -p .
ant debug

but I get "android is not command"


  • TomOpgenorthTomOpgenorth CAXamarin Team Xamurai

    android is a command line utility provided by the Android SDK. It can be found at $ANDROID_HOME/tools. You will need to either type the fully qualified path name, i.e.

    $ANDROID_HOME/tools/android update project -p .

    or add $ANDROID_HOME/tools to your PATH.

  • alberto.palberto.p ITMember ✭✭

    @topgenorth I managed to do the build with ant, but I get "Failed to load map. Could not contact Google servers".

  • TomOpgenorthTomOpgenorth CAXamarin Team Xamurai

    Okay this is progress. There are a few things that could cause this:

    1. Invalid API key. Maybe you missed a character when pasting your API key into AndroidManifest.XML?
    2. The Google Maps for Android v2 service was not enabled in the Google API console
    3. When whitelisted your SHA1 fingerprint in the Google API console, the package name started with an uppercase letter.
    4. The SHA1 fingerprint you registered with Google API console isn't the one that Xamarin.Android is using to sign the APK.

    I'd suggest going back and double checking the first three. If you need to double check the SHA1 fingerprint, I've got some instructions in another thread on how to do so.

    Let me know if any of these work for you.

  • alberto.palberto.p ITMember ✭✭

    @topgenorth I check all.
    When I build Xamarin example MapsAndLocationDemov2 I get these warning (in attach)

  • TomOpgenorthTomOpgenorth CAXamarin Team Xamurai

    So, I'm a bit confused. You say that you're getting the Failed to load map. Could not contact Google servers message in your application logs. However, this warning:

    JARTOXML : warning J2X9001: Couldn't load class com/google/android/gms/maps/MapFragment : java.lang.NoClassDefFoundError: android/app/Fragment 

    in the log files tells me that the sample should not be working because the sample dynamically loads the MapFragment. The two messages are contradictory.

    Is there any more information you can provide me to help diagnose the issue? Did you build the Google Play Services client library using Ant? Could I trouble you to do a "Build...Clean" followed by a "Build...Rebuild All"?

  • alberto.palberto.p ITMember ✭✭

    @topgennorth So, I download your MapsAndLocationDemoV2 from github.
    I build Google Play Servicies with ant succesfuly.
    I add as link
    I get API key in debug mode
    I build all solution and I get warnings that I attached in previous post
    I deployed and start example in device (samsung galaxy tab 2). For example start MapWithMarkersActivity, I saw the blank frame and I get "Failed to load map. Could not contact Google servers" in log

  • alberto.palberto.p ITMember ✭✭

    @topgenorth I attach project

  • StephenTaylorStephenTaylor CAMember

    Did you ever figure this out? I'm having exactly the same problem.

    My only thought, it seems we build 2 APKs, is it possible we're pushing the unsigned one to the device?

  • alberto.palberto.p ITMember ✭✭

    I'm build all solution in debug mode and deployed in debug mode into device.
    I generated SHA1 from debug.keysore and get Map API Key
    I don't understand where is the problem

  • StephenTaylorStephenTaylor CAMember

    I get the same error:

    D:\Work Stuff\Mono for Android Samples\MapsAndLocationDemo_v2\GooglePlayServices\JARTOXML: Warning J2X9001: Couldn't load class com/google/android/gms/maps/SupportMapFragment : java.lang.NoClassDefFoundError: android/support/v4/app/Fragment (J2X9001) (GooglePlayServices)

    But - it builds and deploys fine, runs on the phone, it just doesn't seem to want to show location

  • alberto.palberto.p ITMember ✭✭

    I'm comforted

  • StephenTaylorStephenTaylor CAMember

    I'm not. I've been chipping away at this all night!

    There is a warning, right at the start of the debug log.

    Enabling debug mode 0
    Failed to load map. Could not contact Google servers.
    Authorization failure. // This is odd...
    Failed to load map. Could not contact Google servers.
    Failed to load map. Could not contact Google servers.
    Failed to load map. Could not contact Google servers.

    I've triple-checked the SHA cert, there doesn't seem to be an issue there, all services on and recieving.

    It is nearly 5am, that might have somehthing to do with it...

  • alberto.palberto.p ITMember ✭✭

    I have made changes to render compatible Android 2.2:

    In the GooglePlayServices binding library, change the target framework to Android 2.2.
    In the GooglePlayServices binding library, add a reference to Mono.Android.Support.v4.
    In the MapsAndLocationDemo project, change the target framework to Android 2.2.
    In the MapsAndLocationDemo, add a reference to Mono.Android.Support.v4.
    In the MapsAndLocationDemo fix the compile errors:
    Change FragmentManager to SupportFragmentManager
    Change Activity to FragmentActivity
    Change MapFragment to SupportMapFragment
    Change using Android.App; to using Android.Support.V4.App;

    Perhaps this is the problem?

  • TomOpgenorthTomOpgenorth CAXamarin Team Xamurai

    @alberto.p Okay, this makes more sense. As explained in the README, the sample out of the box states that the sample targets API 4.0 or higher. When you changed the target to Android 2.2 you lost the MapFragment (not supported in Android 2.2) hence the warning. You did the correct thing by making those changes to reference SupportFragmentManager/FragmentActivity/SupportMapFragment. In your case, the warnings you are getting are just that - warnings. You don't need MapFragment and this is NOT the cause of Failed to load map. Could not contact Google servers messages.

    One common cause of those messages is an authentication or authorization failure with the Google API. If you're 100% certain that you have the correct SHA1 fingerprint, then that leaves two possibilities.

    1. The Google Maps Android API v2 has not been turned on in the Google API console (see screenshot)
    2. You do not have the correct certificate fingerprint or package name when granting access Google Maps Android API v2. Is the package name all lower case, such as : 55:63:73:70:D8:AB:FD:FB:DA:FD:46:7B:70:BE:E8:FB:1A:02:22:0F;
  • alberto.palberto.p ITMember ✭✭

    In attached you can see API service is active (screenshot 1).
    In attached you can see API console (screenshot 2).
    This is API KEY: FE:47:1A:15:61:AB:DE:2C:74:F4:BE:65:B7:05:68:1F:5F:9D:56:6B;com.examplelse.maps
    The I get SHA1 from debug.keystore

  • TomOpgenorthTomOpgenorth CAXamarin Team Xamurai

    You're using the wrong package name. Looking at the .ZIP file you posted with your project, the package name you have is mapsandlocationdemov2. So, what you need to put in Google Console API is:

  • alberto.palberto.p ITMember ✭✭

    you're right, but I tried to change the name of the package. I thought that the problem was in the name of the package

  • rmaciasrmacias USBeta, University ✭✭✭✭✭

    Are you placing your own API key in the Android.manifest file?

         <meta-data android:name="" android:value="put_your_api_key_here" />
  • alberto.palberto.p ITMember ✭✭

    @rmacias yes

  • rmaciasrmacias USBeta, University ✭✭✭✭✭

    And just for a sanity check, make sure these permissions are set too

    <!-- Google Maps for Android v2 requires OpenGL ES v2 -->
        <uses-feature android:glEsVersion="0x00020000" android:required="true" />
        <!-- Allow the application to access Google web-based services. -->
        <uses-permission android:name="" />
        <!-- Notice here that we have the package name of our application as a prefix on the permissions. -->
        <uses-permission android:name="MY_PACKAGE_NAME.permission.MAPS_RECEIVE" />
        <permission android:name="MY_PACKAGE_NAME.permission.MAPS_RECEIVE" android:protectionLevel="signature" />
  • TomOpgenorthTomOpgenorth CAXamarin Team Xamurai

    Yes, as @rmacias points out, it will be necessary to update the <uses-permission> and <permission> elements to reflect the correct package name. So:

    <uses-permission android:name="mapsandlocationdemov2.permission.MAPS_RECEIVE" />
    <permission android:name="mapsandlocationdemov2.permission.MAPS_RECEIVE" android:protectionLevel="signature" />
  • alberto.palberto.p ITMember ✭✭

    yes, this is also ok

  • StephenTaylorStephenTaylor CAMember

    This is strange: get the message about the fragment as well:

    But I'm targetting android V4

    I'm using the fully qualified name for the app:

    For generating the map key, I used the fully qualified name as well:

    Does any of this look suspicious?

  • TomOpgenorthTomOpgenorth CAXamarin Team Xamurai

    @StephenTaylor: Because the Java Binding Library is API level 14 (Android 4.0) you loose the SupportMapFragment, hence the warning message. Assuming that you do not want/need to support the older API's this isn't a cause for concern. This is not the cause of the Could not contact Google servers. Authorization failure. messages you are getting.

    All of your other settings look correct to me. You mentioned you've triple checked the certificate fingerprint. Can I bother you to check it a fourth time using this technique:

    1. Unzip your APK file
    2. Run the following from the command line: keytool -printcert -file META-INF/ANDROIDD.RSA

    Compare the SHA1 fingerprint you get from there with the one you have entered into the Google API Console.

    Also, you do have Google Play installed on the device?

  • StephenTaylorStephenTaylor CAMember

    I have cyanogenMod on the device (I can't believe I didn't mention that), but I did install the google package, and I can install and manage applications on the phone.

    I'll test via an emulator, and see if I can't get better results there.

  • StephenTaylorStephenTaylor CAMember

    I double checked the SHA1 via the APK unzip already. This is what I get. LHS is the original keytool command, RHS is unzipping the signed APK

  • StephenTaylorStephenTaylor CAMember

    I wonder - possibly the key isn't valid yet? It says valid since 1am this morning, which should be valid everywhere by now

  • StephenTaylorStephenTaylor CAMember

    Deploying to an emulator is my next problem:

    Detecting installed packages

    Deployment failed because of an internal error: Attempted to read past the end of the stream.

    Deployment failed. Internal error.

  • StephenTaylorStephenTaylor CAMember

    Emulator doesn't run this sample, unfortunately, because it (emulator) doesn't come with google play services. I'll update if I can figure out how to get google play installed on the emulator.

  • alberto.palberto.p ITMember ✭✭

    I solved it.
    The problem was in debug.keystore.
    The path is C:\Users[USERNAME]\AppData\Local\Xamarin\Mono for Android\debug.keystore

  • MassimilianoFabbriMassimilianoFabbri USMember ✭✭

    Hello, I got your same problems. But I'm on Mac. Can you repost the sample project updated ? I'm not able to see the maps.

Sign In or Register to comment.