Home > database >  Caused by: java.lang.RuntimeException: API key not found. Check that <meta-data android:name=&quo
Caused by: java.lang.RuntimeException: API key not found. Check that <meta-data android:name=&quo

Time:07-19

I am trying to compile a simple map display on in my activity, but the app keeps closing. This is my first time working with an API in Android Studio. Here is my complete manifest code. because when I debug the code it shows API key not found.
Check that is in the element of AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="org.tensorflow.lite.examples.detection">

    <uses-sdk />
    <uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
    <uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
   
    <application
        android:allowBackup="true"
        android:icon="@drawable/blind"
        android:label="@string/app_name"
         android:roundIcon="@drawable/blind"
        android:supportsRtl="true"
        android:theme="@style/AppTheme.ObjectDetection">
        <activity android:name=".Navigation.MapsActivity"
            android:exported="true"/>
        <activity android:name=".Navigation.GestureDetect"
            android:exported="true"/>
        <activity android:name=".Navigation.Navigation"
            android:exported="true"/>
        <activity
            android:name=".Reminder.NotificationMessage"
            android:exported="true" /> 
        <activity
            android:name=".Home"
            android:exported="true">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
              <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
  <receiver
            android:name=".Navigation.RebootReceiver"
            android:enabled="true"
            android:exported="true">
            <intent-filter>
                <action android:name="android.intent.action.BOOT_COMPLETED" />
                <action android:name="android.intent.action.QUICKBOOT_POWERON" />
            </intent-filter>
        </receiver>
    </application>

</manifest>

Here is the complete error after debugging the code:-

E/AndroidRuntime: FATAL EXCEPTION: main
    Process: org.tensorflow.lite.examples.detection, PID: 11755
    java.lang.RuntimeException: Unable to start activity ComponentInfo{org.tensorflow.lite.examples.detection/org.tensorflow.lite.examples.detection.Navigation.MapsActivity}: android.view.InflateException: Binary XML file line #75: Binary XML file line #75: Error inflating class fragment
         at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:528)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:910)
     Caused by: android.view.InflateException: Binary XML file line #75: Binary XML file line #75: Error inflating class fragment
     Caused by: android.view.InflateException: Binary XML file line #75: Error inflating class fragment
     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 com.google.maps.api.android.lib6.drd.p.a(:com.google.android.gms.dynamite_mapsdynamite@[email protected] (040406-0):6)
        at com.google.maps.api.android.lib6.auth.f.i(:com.google.android.gms.dynamite_mapsdynamite@[email protected] (040406-0):1)
        at com.google.maps.api.android.lib6.impl.l.a(:com.google.android.gms.dynamite_mapsdynamite@[email protected] (040406-0):24)
        at com.google.android.gms.maps.internal.CreatorImpl.b(:com.google.android.gms.dynamite_mapsdynamite@[email protected] (040406-0):7)
        at com.google.android.gms.maps.internal.CreatorImpl.logInitialization(:com.google.android.gms.dynamite_mapsdynamite@[email protected] (040406-0):3)
        at com.google.android.gms.maps.internal.g.ba(:com.google.android.gms.dynamite_mapsdynamite@[email protected] (040406-0):5)
        at eu.onTransact(:com.google.android.gms.dynamite_mapsdynamite@[email protected] (040406-0):4)
        at android.os.Binder.transact(Binder.java:627)
        at com.google.android.gms.internal.maps.zza.zzc(com.google.android.gms:play-services-maps@@18.1.0:2)
        at com.google.android.gms.maps.internal.zze.zzl(com.google.android.gms:play-services-maps@@18.1.0:4)
        at com.google.android.gms.maps.MapsInitializer.initialize(com.google.android.gms:play-services-maps@@18.1.0:12)
        at com.google.android.gms.maps.MapsInitializer.initialize(com.google.android.gms:play-services-maps@@18.1.0:1)
        at com.google.android.gms.maps.zzav.zzc(com.google.android.gms:play-services-maps@@ 
        at com.google.android.gms.dynamic.DeferredLifecycleHelper.onInflate(com.google.android.gms:play-services-base@@18.0.1:1)
        at com.google.android.gms.maps.SupportMapFragment.onInflate(com.google.android.gms:play-services-maps@@18.1.0:9)
        at androidx.fragment.app.Fragment.onInflate(Fragment.java:1561)
        at androidx.fragment.app.FragmentLayoutInflaterFactory.onCreateView(FragmentLayoutInflaterFactory.java:106)
        at androidx.fragment.app.FragmentController.onCreateView(FragmentController.java:135)
        at androidx.fragment.app.FragmentActivity.dispatchFragmentsOnCreateView(FragmentActivity.java:356)
        at androidx.fragment.app.FragmentActivity.onCreateView(FragmentActivity.java:335)
        at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:787)
        at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:737)
E/AndroidRuntime:     at android.view.LayoutInflater.rInflate(LayoutInflater.java:870)
         at android.app.Activity.setContentView(Activity.java:2758)
        at org.tensorflow.lite.examples.detection.Navigation.MapsActivity.onCreate(MapsActivity.java:273)
        at android.app.Activity.performCreate(Activity.java:7227)
        at android.app.Activity.performCreate(Activity.java:7218)
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1214)
  

CodePudding user response:

You have to get api_key and declare in AndroidManifest.xml just like shown on the error.

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="org.tensorflow.lite.examples.detection">

    <uses-sdk />
    <uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
    <uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
   
    <application
        android:allowBackup="true"
        android:icon="@drawable/blind"
        android:label="@string/app_name"
         android:roundIcon="@drawable/blind"
        android:supportsRtl="true"
        android:theme="@style/AppTheme.ObjectDetection">
        <activity android:name=".Navigation.MapsActivity"
            android:exported="true"/>
        <activity android:name=".Navigation.GestureDetect"
            android:exported="true"/>
        <activity android:name=".Navigation.Navigation"
            android:exported="true"/>
        <activity
            android:name=".Reminder.NotificationMessage"
            android:exported="true" /> 
        <activity
            android:name=".Home"
            android:exported="true">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
              <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
  <receiver
            android:name=".Navigation.RebootReceiver"
            android:enabled="true"
            android:exported="true">
            <intent-filter>
                <action android:name="android.intent.action.BOOT_COMPLETED" />
                <action android:name="android.intent.action.QUICKBOOT_POWERON" />
            </intent-filter>
        </receiver>
        <meta-data android:name="com.google.android.geo.API_KEY" android:value="YOUR_API_KEY"/>
    </application>

</manifest>
 

CodePudding user response:

generate google api key

  1. import the code your AndroidManifest.xml file.
  2. Create google api key enter link description here
  3. Enter the Key you got in the value field
<meta-data
    android:name="com.google.android.geo.API_KEY"
    android:value="@string/api_key" />
  • Related