Search code examples
androidactionbarsherlockgoogle-maps-api-2

Google Maps API v2 API key can't be found; using ABS


I have been trying to convert an app over from the old Google Maps API to the new Google Maps API v2 and have been running into several frustrating roadblocks. The error that I currently trying to figure out is this:

01-16 14:59:38.414: E/AndroidRuntime(29059): Caused by: java.lang.RuntimeException: API key not found.  Check that <meta-data android:name="com.google.android.maps.v2.API_KEY" android:value="your API key"/> is in the <application> element of AndroidManifest.xml
01-16 14:59:38.414: E/AndroidRuntime(29059):    at maps.y.z.a(Unknown Source)
01-16 14:59:38.414: E/AndroidRuntime(29059):    at maps.y.z.a(Unknown Source)
01-16 14:59:38.414: E/AndroidRuntime(29059):    at maps.y.z.a(Unknown Source)
01-16 14:59:38.414: E/AndroidRuntime(29059):    at maps.y.ae.a(Unknown Source)
01-16 14:59:38.414: E/AndroidRuntime(29059):    at maps.y.bu.a(Unknown Source)
01-16 14:59:38.414: E/AndroidRuntime(29059):    at maps.y.p.onCreateView(Unknown Source)
01-16 14:59:38.414: E/AndroidRuntime(29059):    at com.google.android.gms.maps.internal.IMapFragmentDelegate$Stub.onTransact(IMapFragmentDelegate.java:107)
01-16 14:59:38.414: E/AndroidRuntime(29059):    at android.os.Binder.transact(Binder.java:279)
01-16 14:59:38.414: E/AndroidRuntime(29059):    at com.google.android.gms.maps.internal.IMapFragmentDelegate$a$a.onCreateView(Unknown Source)
01-16 14:59:38.414: E/AndroidRuntime(29059):    at com.google.android.gms.maps.SupportMapFragment$a.onCreateView(Unknown Source)
01-16 14:59:38.414: E/AndroidRuntime(29059):    at com.google.android.gms.internal.d$4.a(Unknown Source)
01-16 14:59:38.414: E/AndroidRuntime(29059):    at com.google.android.gms.internal.d.a(Unknown Source)
01-16 14:59:38.414: E/AndroidRuntime(29059):    at com.google.android.gms.internal.d.onCreateView(Unknown Source)
01-16 14:59:38.414: E/AndroidRuntime(29059):    at com.google.android.gms.maps.SupportMapFragment.onCreateView(Unknown Source)

This has me completed baffled because I clearly have a "meta-data" block in my manifest that is properly formatted. Here is the relevant portion of my manifest:

<uses-sdk
    android:minSdkVersion="8"
    android:targetSdkVersion="17" />

<permission
    android:name="com.example.mapdemo.permission.MAPS_RECEIVE"
    android:protectionLevel="signature" />

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

<uses-permission android:name="com.example.mapdemo.permission.MAPS_RECEIVE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

<application
    android:allowBackup="false"
    android:icon="@drawable/icon"
    android:label="@string/app_name"
    android:theme="@style/Theme.Styled" >
    <meta-data
        android:name="com.google.android.maps.API_KEY"
        android:value="my api key" />
    (activities and stuff)
</application>

I have checked and double checked that the API key that I am using is the one that has been generated in the Google Console, that I have the "Google Maps Android v2" service checked ON, and that I used the correct SHA-1 for my debug key.

This led me to think that it could possibly have something to do with ABS not playing nice with the new API v2. This does not seem likely, since I have created a test project using ABS that does not encounter this error. Here is my .xml layout file for my activity:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >

    <fragment
        android:id="@+id/map_fragment"
        android:name="(mypackage).MapFragment"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

</RelativeLayout>

The MapFragment from my package that I am referencing is a custom fragment constructed as described in this question: Using ActionBarSherlock With the New SupportMapFragment. As I mentioned previously, I have created a test project using this method that does not encounter the aforementioned error.

I am referencing the ABS 4.2.0 and google_play_services_lib as libraries in my project. I also have google_play_services.jar in my libs/ folder as well as in my Java Build Path as an external JAR.

I have been searching around for a solution, but everybody who has encountered this error has simply misplaced their "meta-data" block or used the wrong SHA-1 hash for their debug key. This does not appear to be my case. Does anybody have any clue as to what could be causing this issue?


Solution

  • Check that

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

    is in the element of AndroidManifest.xml

    Change this:

    <meta-data
            android:name="**com.google.android.maps.API_KEY**"
            android:value="my api key" />
    

    to this:

    <meta-data
            android:name="**com.google.android.maps.v2.API_KEY**"
            android:value="my api key" />
    

    Hope it helps.