NumenorForLife
NumenorForLife

Reputation: 1746

Missing Google API Key in Manifest (Android)

I am having trouble getting past the following error, which suggests that I am missing a tag in my manifest:

05-04 17:05:16.517: E/AndroidRuntime(26717): 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

Having read Google Maps Android API V2 problems with android 4.3, and Android google Map Api V2 Crashes on runtime, I still have not had any luck in fixing my issue.

My manifest can be found below:

 <?xml version="1.0" encoding="utf-8"?>

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

<uses-permission android:name="com.mapgenius.googlemaps.permission.MAPS_RECEIVE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<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_GPS" />
<uses-permission android:name="android.permission.ACCESS_LOCATION" />
<uses-permission android:name="android.permission.INTERNET" />

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

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

<application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/Theme.Sherlock" >
    <activity
        android:name="com.mapgenius.MainActivity"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>

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

Update:

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

should have read:

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

Upvotes: 1

Views: 15296

Answers (4)

dkhawk
dkhawk

Reputation: 36

Please install the secrets-gradle-plugin as described here.

The reason for this syntax in the AndroidManifest.xml file:

<meta-data
android:name="com.google.android.geo.API_KEY"
android:value="${MAPS_API_KEY}" />

is to prevent you from checking your API key into version control. Your key should instead be saved in a file that is not checked in, for example, in secrets.properties.

This codelab also walks you through the process.

Upvotes: 0

Will Buffington
Will Buffington

Reputation: 1670

As of Jan 1, 2024, the Google Maps SDK documentation page states: enter image description here

Which is kind of confusing. The entry:

<meta-data
android:name="com.google.android.geo.API_KEY"
android:value="${MAPS_API_KEY}" />

Only needs to be:

<meta-data
    android:name="com.google.android.geo.API_KEY"
    android:value="YOUR_API_KEY" />

The $ in the 'value' section doesn't need to be there. In fact, when I tested my app with the $ preceding the API key the map activity showed up blank. Removing the $ allowed the map to render correctly.

Upvotes: 0

thilemann
thilemann

Reputation: 397

You need to obtain a Google Maps API key and put it in your manifest by adding:

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

It is described in detail on the Google Developers page.

Upvotes: 7

Henry
Henry

Reputation: 43738

You specified the key with com.google.android.gms.version, that needs to be com.google.android.maps.v2.API_KEY instead.

Upvotes: 1

Related Questions