14

Alright, here is what I did using the example

  1. Got the debug key via keytool (made sure it is the the debug key is used by eclipse in Preferences -> Android -> Build)
  2. Generated the key by the command

    $ keytool -list -v -keystore debug.keystore -alias androiddebugkey -storepass android -keypass android

  3. Copy pasted the SHA1 sum in the Google API Console + my packagename:

    sum;com.my.package

  4. Enabled Google Map API v2 in the same project in Google API Console

  5. Copied it to the Manifest application in meta-data.

  6. Downloaded via SDK manager and Imported the google-play-services_lib project and referenced it as the library project. As well as the ActionBarSherlock.

  7. Before launching I make sure the GooglePlayServices are available.

Manifest:

<uses-feature
    android:glEsVersion="0x00020000"
    android:required="true"/>

<permission
    android:name="com.my.package.permission.MAPS_RECEIVE"
    android:protectionLevel="signature"/>

<uses-permission android:name="com.my.package.permission.MAPS_RECEIVE"/>
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>

Application:

<meta-data
    android:name="com.google.android.maps.v2.API_KEY"
    android:value="debug_key"/>

The proguard stuff are added too, but I don't obfuscate right now.

DrugstoresMapActivity extends SherlockFragmentActivity

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <fragment
        android:id="@+id/map_fragment"
        class="com.google.android.gms.maps.SupportMapFragment"
        android:layout_width="match_parent"
        android:layout_height="match_parent"/>

</RelativeLayout>

project.properties

target=android-17
android.library.reference.1=../google-play-services_lib
android.library.reference.2=../ActionBarSherlock

The ActionBarSherlock has android-support-v4 in libs, not the main project if that matters.

The StartupActivity makes sure that DrugstoresMapActivity will be launched only if the services available

private void attempt() {
    int result = GooglePlayServicesUtil.isGooglePlayServicesAvailable(getBaseContext());

    switch (result) {
        case ConnectionResult.SUCCESS:
            startActivity(new Intent(this, DrugstoresMapActivity.class));
            finish();
            break;

        default:
            GooglePlayServicesUtil.getErrorDialog(result, this, REQUEST_DIALOG)
                .show();
            break;
    }
}

Double-checked the keys are fine. No clue what I missed here.

Yaroslav Mytkalyk
  • 16,950
  • 10
  • 72
  • 99
  • just curious, how did you find out about this? I'm on tech blogs everyday, and on the android developer documents everyday, and I only happened to find out about this from trying to solve an impossible problem with android maps v1 in my existing code. – CQM Dec 18 '12 at 23:29
  • Find out about what. About Wrong service enabled? If yes, you should have asked that in the answer comment, not the question to make it clearer. I found the suggestion somewhere in StackOverflow here after hours browsing different problems regarding this issue. – Yaroslav Mytkalyk Dec 19 '12 at 14:38
  • no, how did you find out about android maps v2, I realize I'm *only* two weeks late, but I think its kind of a big deal – CQM Dec 19 '12 at 15:10
  • I was looking for docs (API Reference) in google. – Yaroslav Mytkalyk Dec 19 '12 at 16:47

1 Answers1

46

Wrong service was enabled. Make sure the "Google Maps Android API v2", not "Google Maps API v2" is enabled and re-generate the API key.

Yaroslav Mytkalyk
  • 16,950
  • 10
  • 72
  • 99
  • 2
    +1 Bingo.. :) I stucked with the API key, deleting keystores, rename app package.. – Mahendran Dec 13 '12 at 13:12
  • 1
    After enabling Google Maps Android API v2 it was still not working for me. So I tried changing the target sdk in my manifest to 17 from 16 and that fixed it. Note switching back to 16 also still worked. – Ryan R Jan 12 '13 at 20:02
  • 1
    Oh my word - this was my problem as well and I was pulling my hair out. Thank you!! – SNyamathi Jan 27 '13 at 07:19
  • THANK YOU A MILLION! I was stuck on this issue for 2 days! – Lian Feb 19 '13 at 13:03
  • Bazinga!!! Damn! I can't thank you more!! I will cross share your answer with others. I am sure they will appreciate it! :-D :-D – Hari Krishna Ganji Mar 25 '13 at 14:18
  • +1000000000 for you! I'm taking you out to wherever you want to go. I've been stuck on this issue for days and I didn't realize there was a separate maps service for Android. – YoungDinosaur May 08 '13 at 23:04
  • if you come from API v1 with the same app packages names, it does not work with debug key, you need to change the package name. – Hpsaturn Oct 23 '13 at 04:11