RuntimeException: API key not found. Check that geo.API_KEY is in the AndroidManifest.xml
Asked Answered
D

7

22

I am attempting to compile a simple map display on my my phone, but the app keeps closing. It seems that all my ducks are in a row, but I'm just stumped. This is my first time working with an API in Android Studio

Here is the manifest:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.morticia.android.firstmap">

<uses-feature
    android:glEsVersion="0x00020000"
    android:required="true" />
<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:supportsRtl="true"
    android:theme="@style/AppTheme">
    <meta-data
        android:name="com.google.android.gms.version"
        android:value="@integer/google_play_services_version" />
    <meta-data
        android:name="com.morticia.android.maptest_app"
        android:value="AIzaSyBf3tEmdR18S-2v0E1i1x0oqcXJ9imntT4" />

    <activity
        android:name=".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>
</application>

<uses-permission android:name="android.permission.INTERNET"></uses-permission>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"></uses-permission>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"></uses-permission>
</manifest>

And this is my MainActivity XML:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:map="http://schemas.android.com/apk/res-auto"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity">

<fragment xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/map"
    android:layout_height="match_parent"
    android:layout_width="match_parent"
    android:name="com.google.android.gms.maps.MapFragment"
    map:cameraBearing="112.5"
    map:cameraTargetLat="40.7484"
    map:cameraTargetLng="-73.9857"
    map:cameraTilt="65"
    map:cameraZoom="17" />

</RelativeLayout>

and finally MainActivity Java code:

package com.morticia.android.firstmap;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;

import com.google.android.gms.maps.MapFragment;

public class MainActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
}
}

here are the logs as requested:

02-02 20:29:13.420 26932-26932/com.morticia.android.firstmap E/AndroidRuntime: FATAL EXCEPTION: main
                                                                           Process: com.morticia.android.firstmap, PID: 26932
                                                                           java.lang.RuntimeException: Unable to start activity ComponentInfo{com.morticia.android.firstmap/com.morticia.android.firstmap.MainActivity}: android.view.InflateException: Binary XML file line #12: Binary XML file line #12: Error inflating class fragment
                                                                               at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3253)
                                                                               at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3349)
                                                                               at android.app.ActivityThread.access$1100(ActivityThread.java:221)
                                                                               at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1794)
                                                                               at android.os.Handler.dispatchMessage(Handler.java:102)
                                                                               at android.os.Looper.loop(Looper.java:158)
                                                                               at android.app.ActivityThread.main(ActivityThread.java:7224)
                                                                               at java.lang.reflect.Method.invoke(Native Method)
                                                                               at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
                                                                               at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)
                                                                            Caused by: android.view.InflateException: Binary XML file line #12: Binary XML file line #12: Error inflating class fragment
                                                                               at android.view.LayoutInflater.inflate(LayoutInflater.java:551)
                                                                               at android.view.LayoutInflater.inflate(LayoutInflater.java:429)
                                                                               at android.view.LayoutInflater.inflate(LayoutInflater.java:380)
                                                                               at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:288)
                                                                               at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:143)
                                                                               at com.morticia.android.firstmap.MainActivity.onCreate(MainActivity.java:13)
                                                                               at android.app.Activity.performCreate(Activity.java:6876)
                                                                               at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1135)
                                                                               at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3206)
                                                                               at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3349) 
                                                                               at android.app.ActivityThread.access$1100(ActivityThread.java:221) 
                                                                               at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1794) 
                                                                               at android.os.Handler.dispatchMessage(Handler.java:102) 
                                                                               at android.os.Looper.loop(Looper.java:158) 
                                                                               at android.app.ActivityThread.main(ActivityThread.java:7224) 
                                                                               at java.lang.reflect.Method.invoke(Native Method) 
                                                                               at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230) 
                                                                               at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120) 
                                                                            Caused by: android.view.InflateException: Binary XML file line #12: Error inflating class fragment
                                                                               at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:794)
                                                                               at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:716)
                                                                               at android.view.LayoutInflater.rInflate(LayoutInflater.java:847)
                                                                               at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:810)
                                                                               at android.view.LayoutInflater.inflate(LayoutInflater.java:527)
                                                                               at android.view.LayoutInflater.inflate(LayoutInflater.java:429) 
                                                                               at android.view.LayoutInflater.inflate(LayoutInflater.java:380) 
                                                                               at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:288) 
                                                                               at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:143) 
                                                                               at com.morticia.android.firstmap.MainActivity.onCreate(MainActivity.java:13) 
                                                                               at android.app.Activity.performCreate(Activity.java:6876) 
                                                                               at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1135) 
                                                                               at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3206) 
                                                                               at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3349) 
                                                                               at android.app.ActivityThread.access$1100(ActivityThread.java:221) 
                                                                               at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1794) 
                                                                               at android.os.Handler.dispatchMessage(Handler.java:102) 
                                                                               at android.os.Looper.loop(Looper.java:158) 
                                                                               at android.app.ActivityThread.main(ActivityThread.java:7224) 
                                                                               at java.lang.reflect.Method.invoke(Native Method) 
                                                                               at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230) 
                                                                               at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120) 
                                                                            Caused by: java.lang.RuntimeException: API key not found.  Check that <meta-data android:name="com.google.android.geo.API_KEY" android:value="your API key"/> is in the <application> element of AndroidManifest.xml
                                                                               at maps.y.k.b(Unknown Source)
                                                                               at maps.v.c.a(Unknown Source)
                                                                               at com.google.android.gms.maps.internal.CreatorImpl.b(Unknown Source)
                                                                               at com.google.android.gms.maps.internal.CreatorImpl.newMapFragmentDelegate(Unknown Source)
                                                                               at xg.onTransact(:com.google.android.gms.DynamiteModulesB:62)
                                                                               at android.os.Binder.transact(Binder.java:387)
                                                                               at trn.newMapFragmentDelegate(:com.google.android.gms:179)
                                                                               at com.google.android.gms.maps.internal.CreatorImpl.newMapFragmentDelegate(:com.google.android.gms:99)
                                                                               at trm.onTransact(:com.google.android.gms:62)
                                                                               at android.os.Binder.transact(Binder.java:387)
                                                                               at com.google.android.gms.maps.internal.zzc$zza$zza.zzt(Unknown Source)
                                                                               at com.google.android.gms.maps.MapFragment$zzb.zzwP(Unknown Source)
                                                                               at com.google.android.gms.maps.MapFragment$zzb.zza(Unknown Source)
                                                                               at com.google.android.gms.dynamic.zza.zza(Unknown Source)
                                                                               at com.google.android.gms.dynamic.zza.onInflate(Unknown Source)
                                                                               at com.google.android.gms.maps.MapFragment.onInflate(Unknown Source)
                                                                               at android.app.Fragment.onInflate(Fragment.java:1373)
                                                                               at android.app.FragmentManagerImpl.onCreateView(FragmentManager.java:2217)
                                                                               at android.app.FragmentController.onCreateView(FragmentController.java:98)
                                                                               at android.app.Activity.onCreateView(Activity.java:6070)
                                                                               at android.support.v4.app.BaseFragmentActivityHoneycomb.onCreateView(BaseFragmentActivityHoneycomb.java:36)
                                                                               at android.support.v4.app.FragmentActivity.onCreateView(FragmentActivity.java:79)
                                                                               at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:766)
                                                                               at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:716) 
                                                                               at android.view.LayoutInflater.rInflate(LayoutInflater.java:847) 
                                                                               at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:810) 
                                                                               at android.view.LayoutInflater.inflate(LayoutInflater.java:527) 
                                                                               at android.view.LayoutInflater.inflate(LayoutInflater.java:429) 
                                                                               at android.view.LayoutInflater.inflate(LayoutInflater.java:380) 
                                                                               at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:288) 
                                                                               at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:143) 
                                                                               at com.morticia.android.firstmap.MainActivity.onCreate(MainActivity.java:13) 
                                                                               at android.app.Activity.performCreate(Activity.java:6876) 
                                                                               at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1135) 
                                                                               at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3206) 
                                                                               at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3349) 
                                                                               at android.app.ActivityThread.access$1100(ActivityThread.java:221) 
                                                                               at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1794) 
                                                                               at android.os.Handler.dispatchMessage(Handler.java:102) 
                                                                               at android.os.Looper.loop(Looper.java:158) 
                                                                               at android.app.ActivityThread.main(ActivityThread.java:7224) 
                                                                               at java.lang.reflect.Method.invoke(Native Method) 
                                                                               at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230) 
                                                                               at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120) 

Any professional insights would be greatly appreciated

Thank you!

Derian answered 3/2, 2017 at 4:27 Comment(3)
your fragment inside activity_main.xml is not inflating. I this you full activity code above? And post your logcat too.Herriott
Thank you! logcat is addedDerian
The logcat tells you exactly what to do. Just need to read it completelyHannon
H
28

replace this code at your AndroidManifest.xml file

  <meta-data
    android:name="com.morticia.android.maptest_app"
    android:value="YOUR_API_KEY" />

with

Google Maps Android API ENABLE

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

or

Google Maps Geolocation API ENABLE

<meta-data android:name="com.google.android.geo.API_KEY" 
android:value="YOUR_GEO_API"/>
Herriott answered 3/2, 2017 at 4:42 Comment(11)
This is progress as I am able to see an empty map with the Google logo in the bottom left corner of screen, but the map is blank.Derian
map is blank because you have not activated the google map at console.Herriott
It's telling me there is an authorization error: ' Ensure that the "Google Maps Android API v2" is enabled. Ensure that the following Android Key exists:'Derian
enable the required map api at google console to view mapHerriott
where you got that api key?Herriott
I did that and even generated a new key and replaced the old one. It is enabled and I believe it's the only Google Maps API that offeredDerian
enable google map for android and google places api's. Then check whether this works or notHerriott
Finally nailed it. That metadata correction that got it to work was: <meta-data> android:name="com.google.android.maps.v2.API_KEY"Derian
Thank you for all of your help!Derian
for this anwer you need to activate the Google Maps Geolocation API ENABLEHerriott
@Derian these both will work depending upon the api you enabled. I answered what on basis of your logcat, you can check above the logcat you have posted.Herriott
S
36

You should place

<application
   <meta-data android:name="com.google.android.geo.API_KEY" android:value="<put your api KEY here"/>  
...

and not in other position like for example under:

<application
   <activity
      <meta-data android:name="com.google.android.geo.API_KEY" android:value="<put your api KEY here"/>  
Squinteyed answered 5/3, 2019 at 19:28 Comment(2)
Sir i have tried but not worked for me after build android file is override every-time tell me any another way?Lowpressure
I was trying for solutions for many days... this is the correct point where I made mistake (above <activity ....)..fixed now! thank you .Ulterior
H
28

replace this code at your AndroidManifest.xml file

  <meta-data
    android:name="com.morticia.android.maptest_app"
    android:value="YOUR_API_KEY" />

with

Google Maps Android API ENABLE

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

or

Google Maps Geolocation API ENABLE

<meta-data android:name="com.google.android.geo.API_KEY" 
android:value="YOUR_GEO_API"/>
Herriott answered 3/2, 2017 at 4:42 Comment(11)
This is progress as I am able to see an empty map with the Google logo in the bottom left corner of screen, but the map is blank.Derian
map is blank because you have not activated the google map at console.Herriott
It's telling me there is an authorization error: ' Ensure that the "Google Maps Android API v2" is enabled. Ensure that the following Android Key exists:'Derian
enable the required map api at google console to view mapHerriott
where you got that api key?Herriott
I did that and even generated a new key and replaced the old one. It is enabled and I believe it's the only Google Maps API that offeredDerian
enable google map for android and google places api's. Then check whether this works or notHerriott
Finally nailed it. That metadata correction that got it to work was: <meta-data> android:name="com.google.android.maps.v2.API_KEY"Derian
Thank you for all of your help!Derian
for this anwer you need to activate the Google Maps Geolocation API ENABLEHerriott
@Derian these both will work depending upon the api you enabled. I answered what on basis of your logcat, you can check above the logcat you have posted.Herriott
P
3

Add meta-data to <application> card in your AndroidManifest file:

<meta-data android:name="com.google.android.geo.API_KEY"
               android:value="YOUR_API_KEY" />
Pyrogenic answered 30/9, 2021 at 8:13 Comment(0)
P
3

I have tried all above. Finally i got it fixed after pasting meta-data tag in the very next to application tag like this:

<application
    android:label="project_name"
    android:name="${applicationName}"
    android:icon="@mipmap/ic_launcher">

    <meta-data android:name="com.google.android.geo.API_KEY"
           android:value="ZiNdASyDuQFXhEdK0TDkqF7WYnb2TfS6ugJZjNEU"/>
    <activity
        android:name=".MainActivity"
        android:exported="true"
        android:launchMode="singleTop"
        android:theme="@style/LaunchTheme"
        android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
        android:hardwareAccelerated="true"
        android:windowSoftInputMode="adjustResize">
        ...

...

Penner answered 1/8, 2022 at 13:17 Comment(1)
Yes, What worked for me was to place Api key the meta-data tag in application, not activity in androidManifest.xmlAnfractuous
C
2

I came across this but have been using EXPO, so the solution is a little diff: In a nutshell, you need to add the following 'config' for Maps to your package.json:

"android": {
      "package": "com.YOUR_PROJECT_NAME",
      "versionCode": 1.0,
      "permissions": [
        "ACCESS_COARSE_LOCATION",
        "CAMERA",
      ],
      "config": {
        "googleMaps": {
          "apiKey": "YOUR API KEY GOES HERE"
        }
      }
    },

See more info here: https://docs.expo.io/versions/latest/sdk/map-view/

Cabral answered 20/1, 2020 at 10:40 Comment(1)
is app.json no package.jsonKp
D
0

Replace android:name="com.google.android.gms.maps.MapFragment" with class="com.google.android.gms.maps.SupportMapFragment" and try.

Donte answered 3/2, 2017 at 5:23 Comment(0)
R
0

Check out this code

<application
    android:name=".util.SmartBus"
    android:allowBackup="true"
    android:fullBackupContent="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:roundIcon="@mipmap/ic_launcher"
    android:supportsRtl="true"
    android:theme="@style/AppTheme.NoActionBar"
    android:usesCleartextTraffic="true">

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

    <activity
        android:name=".MainActivity"
        android:exported="false"
        android:label="@string/title_activity_main"
        android:theme="@style/AppTheme.NoActionBar.NoActionBar" />

    <activity
        android:name=".activities.SplashScreenActivity"
        android:exported="true">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

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

</application>
Recount answered 13/12, 2021 at 15:13 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.