Android - API密钥只能指定一次< meta-data>重复 [英] Android - The API key can only be specified once <meta-data> duplicates

查看:190
本文介绍了Android - API密钥只能指定一次< meta-data>重复的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将Google地图添加到may应用中,因此我使用了API密钥。不幸的是,当我通过元数据标签将API密钥插入到manifest.xml中时,它会在编译时自动插入另一个元数据标签,如下所示。现在它会产生下面提到的错误。最糟糕的情况是,即使我删除它们中的每一个或两者,它也会在编译时自动生成两个标记并引发错误。

任何帮助?

错误

  java.lang.RuntimeException:无法启动活动ComponentInfo {com.exampl.t_collect / com.exampl.t_collect.activity.MapActivity}:android.view.InflateException:在android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2389)
在android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2441)
在二进制XML文件行#6: b $ b at android.app.ActivityThread.access $ 900(ActivityThread.java:151)
at android.app.ActivityThread $ H.handleMessage(ActivityThread.java:1354)
...... ...
导致:android.view.InflateException:二进制XML文件行#6:错误膨胀类片段
在android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:713)
在android.view.LayoutInflater.rInflate(LayoutInflater.java:755)
在android.view.LayoutInflater.inflate(Layo utInflater.java:492)
at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
..........
引起:java.lang。 RuntimeException:API密钥只能被指定一次。建议您在< application>中使用名称为com.google.android.geo.API_KEY的元数据标记。 AndroidManifest.xml的元素
位于com.google.maps.api.android.lib6.c.ad.a(未知来源)
位于com.google.maps.api.android.lib6.aea(未知来源)
在com.google.android.gms.maps.internal.CreatorImpl.b(未知来源)

Manifast.xml元标记

 < manifest xmlns:android = http://schemas.android.com/apk/res/android
package =com.exampl.t_collect
android:versionCode =1
android:versionName =1.0 >

< uses-sdk
android:minSdkVersion =14
android:targetSdkVersion =21/>

<使用权限android:name =android.permission.INTERNET/>
< uses-permission android:name =android.permission.CALL_PHONE/>
< uses-permission android:name =android.permission.ACCESS_FINE_LOCATION/>
< uses-permission android:name =com.android.alarm.permission.SET_ALARM/>

<! - -
检索OAuth 2.0令牌或无效标记以断开用户连接。此断开连接
选项必须符合Google+登录开发者政策
- >
< uses-permission android:name =android.permission.USE_CREDENTIALS/>







 < android:uses-permission 
android:name =android.permission.WRITE_EXTERNAL_STORAGE
android:maxSdkVersion = 18/>
< android:使用权限android:name =android.permission.READ_PHONE_STATE/>
< android:uses-permission
android:name =android.permission.READ_EXTERNAL_STORAGE
android:maxSdkVersion =18/>
< android:uses-permission android:name =android.permission.READ_CALL_LOG/>

<使用权限android:name =android.permission.ACCESS_NETWORK_STATE/>
< uses-permission android:name =android.permission.WRITE_EXTERNAL_STORAGE/>
<使用权限android:name =com.google.android.providers.gsf.permission.READ_GSERVICES/>
<! -
使用
Google Maps Android API v2时不需要ACCESS_COARSE / FINE_LOCATION权限,但建议您使用。
- >
< uses-permission android:name =android.permission.ACCESS_COARSE_LOCATION/>

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

< application
android:allowBackup =true
android:debuggable =true
android:icon =@ drawable / ic_launcher
android:label =@ string / app_name
android:theme =@ style / AppTheme>
android:name =com.exampl.t_collect.activity.Login
android:label =@ string / app_name
android:launchMode =singleTask >
< intent-filter>

< category android:name =android.intent.category.LAUNCHER/>
< / intent-filter>
< / activity>
< activity
android:name =com.exampl.t_collect.activity.Dash
android:label =@ string / app_name>
< / activity>
android:name =com.exampl.t_collect.activity.Collection
android:label =@ string / title_activity_collection>
< / activity>
< activity
android:name =com.exampl.t_collect.activity.Collection1
android:label =@ string / title_activity_collection>
< / activity>
< activity
android:name =com.exampl.t_collect.activity.Collection2
android:label =@ string / title_activity_collection>
< / activity>
< activity
android:name =com.exampl.t_collect.activity.Advance
android:label =@ string / title_activity_advance>
< / activity>
< activity
android:name =com.exampl.t_collect.activity.Customer
android:label =@ string / title_activity_customer>
< / activity>
< activity
android:name =com.exampl.t_collect.activity.Data_store
android:label =@ string / title_activity_data_store>
< / activity>
< activity
android:name =com.exampl.t_collect.activity.DataRqeuset
android:label =@ string / title_activity_data_rqeuset>
< / activity>
< activity
android:name =com.exampl.t_collect.activity.Settings
android:label =@ string / title_activity_settings>
< / activity>
< activity
android:name =com.exampl.t_collect.activity.PastData_activity
android:label =@ string / title_activity_past_data>
< / activity>

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

< receiver android:name =com.exampl.t_collect.util.UploadGPS/>

< activity
android:name =com.exampl.t_collect.activity.findTrucks
android:label =@ string / title_activity_find_trucks>
< / activity>

<元数据
android:name =com.google.android.geo.API_KEY
android:value =AIzaSy ******** *************************/>
< meta-data
android:name =com.google.android.maps.v2.API_KEY
android:value =@ string / google_maps_key/>

< activity
android:name =com.exampl.t_collect.activity.MapsActivity
android:label =@ string / title_activity_maps>
< / activity>
< activity
android:name =com.exampl.t_collect.activity.MapActivity
android:label =@ string / title_activity_map>
< / activity>
<! - 包含AdActivity和InAppPurchaseActivity configChanges和主题。 - >
< activity
android:name =com.google.android.gms.ads.AdActivity
android:configChanges =keyboard | keyboardHidden | orientation | screenLayout | uiMode | screenSize | smallestScreenSize
android:theme =@ android:style / Theme.Translucent/>
< activity
android:name =com.google.android.gms.ads.purchase.InAppPurchaseActivity
android:theme =@ style / Theme.IAPTheme/>

< meta-data
android:name =com.google.android.gms.wallet.api.enabled
android:value =true/>

< receiver
android:name =com.google.android.gms.wallet.EnableWalletOptimizationReceiver
android:exported =false>
< intent-filter>
< / intent-filter>
< / receiver>
< / application>


解决方案

删除您的com.google.android.maps.v2.API_KEY元数据项。
$ b com.google.android.geo.API_KEY条目足够用于地图和地方信息服务。



来源: https://code.google.com/p/gmaps-api-issues/issues/detail?id=7824






编辑 - Google更新了他们的文档,明确地表明了这一点:


  1. https://developers.google.com/places/android-api/start#api- key

  2. https://developers.google.com/maps/documentation/android-sdk/signup#use-key


I’m trying to add Google map in to may app, so I have taken the API key. Unfortunately when I inserted the API key in manifest.xml through a meta-data tag, it automatically inserted another meta-data tag at compile time as shown below. Now it generates below mentioned error. The worst case is, even I delete each of them or both, it automatically generates both tags at compile time again and throws the error.

Any help?

Error

java.lang.RuntimeException: Unable to start activity ComponentInfo{com.exampl.t_collect/com.exampl.t_collect.activity.MapActivity}: android.view.InflateException: Binary XML file line #6: Error inflating class fragment
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2389)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2441)
        at android.app.ActivityThread.access$900(ActivityThread.java:151)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1354)
.........
Caused by: android.view.InflateException: Binary XML file line #6: Error inflating class fragment
        at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:713)
        at android.view.LayoutInflater.rInflate(LayoutInflater.java:755)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
..........
Caused by: java.lang.RuntimeException: The API key can only be specified once. It is recommended that you use the meta-data tag with the name: com.google.android.geo.API_KEY in the <application> element of AndroidManifest.xml
        at com.google.maps.api.android.lib6.c.ad.a(Unknown Source)
        at com.google.maps.api.android.lib6.a.e.a(Unknown Source)
        at com.google.android.gms.maps.internal.CreatorImpl.b(Unknown Source)

Manifast.xml meta tags

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.exampl.t_collect"
android:versionCode="1"
android:versionName="1.0" >

<uses-sdk
    android:minSdkVersion="14"
    android:targetSdkVersion="21" />

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.CALL_PHONE" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="com.android.alarm.permission.SET_ALARM" />

<!--
 To retrieve OAuth 2.0 tokens or invalidate tokens to disconnect a user. This disconnect
 option is required to comply with the Google+ Sign-In developer policies
-->
<uses-permission android:name="android.permission.USE_CREDENTIALS" />

<android:uses-permission
    android:name="android.permission.WRITE_EXTERNAL_STORAGE"
    android:maxSdkVersion="18" />
<android:uses-permission android:name="android.permission.READ_PHONE_STATE" />
<android:uses-permission
    android:name="android.permission.READ_EXTERNAL_STORAGE"
    android:maxSdkVersion="18" />
<android:uses-permission android:name="android.permission.READ_CALL_LOG" />

<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" />
<!--
 The ACCESS_COARSE/FINE_LOCATION permissions are not required to use
         Google Maps Android API v2, but are recommended.
    -->
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />

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

<application
    android:allowBackup="true"
    android:debuggable="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
    <activity
        android:name="com.exampl.t_collect.activity.Login"
        android:label="@string/app_name"
        android:launchMode="singleTask" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <activity
        android:name="com.exampl.t_collect.activity.Dash"
        android:label="@string/app_name" >
    </activity>
    <activity
        android:name="com.exampl.t_collect.activity.Collection"
        android:label="@string/title_activity_collection" >
    </activity>
    <activity
        android:name="com.exampl.t_collect.activity.Collection1"
        android:label="@string/title_activity_collection" >
    </activity>
    <activity
        android:name="com.exampl.t_collect.activity.Collection2"
        android:label="@string/title_activity_collection" >
    </activity>
    <activity
        android:name="com.exampl.t_collect.activity.Advance"
        android:label="@string/title_activity_advance" >
    </activity>
    <activity
        android:name="com.exampl.t_collect.activity.Customer"
        android:label="@string/title_activity_customer" >
    </activity>
    <activity
        android:name="com.exampl.t_collect.activity.Data_store"
        android:label="@string/title_activity_data_store" >
    </activity>
    <activity
        android:name="com.exampl.t_collect.activity.DataRqeuset"
        android:label="@string/title_activity_data_rqeuset" >
    </activity>
    <activity
        android:name="com.exampl.t_collect.activity.Settings"
        android:label="@string/title_activity_settings" >
    </activity>
    <activity
        android:name="com.exampl.t_collect.activity.PastData_activity"
        android:label="@string/title_activity_past_data" >
    </activity>

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

    <receiver android:name="com.exampl.t_collect.util.UploadGPS" />

    <activity
        android:name="com.exampl.t_collect.activity.findTrucks"
        android:label="@string/title_activity_find_trucks" >
    </activity>

    <meta-data
        android:name="com.google.android.geo.API_KEY"
        android:value="AIzaSy*********************************" />
    <meta-data
        android:name="com.google.android.maps.v2.API_KEY"
        android:value="@string/google_maps_key" />

    <activity
        android:name="com.exampl.t_collect.activity.MapsActivity"
        android:label="@string/title_activity_maps" >
    </activity>
    <activity
        android:name="com.exampl.t_collect.activity.MapActivity"
        android:label="@string/title_activity_map" >
    </activity>
    <!-- Include the AdActivity and InAppPurchaseActivity configChanges and themes. -->
    <activity
        android:name="com.google.android.gms.ads.AdActivity"
        android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"
        android:theme="@android:style/Theme.Translucent" />
    <activity
        android:name="com.google.android.gms.ads.purchase.InAppPurchaseActivity"
        android:theme="@style/Theme.IAPTheme" />

    <meta-data
        android:name="com.google.android.gms.wallet.api.enabled"
        android:value="true" />

    <receiver
        android:name="com.google.android.gms.wallet.EnableWalletOptimizationReceiver"
        android:exported="false" >
        <intent-filter>
            <action android:name="com.google.android.gms.wallet.ENABLE_WALLET_OPTIMIZATION" />
        </intent-filter>
    </receiver>
</application>

解决方案

Delete your "com.google.android.maps.v2.API_KEY" meta-data entry.

The "com.google.android.geo.API_KEY" entry is sufficient for both the Maps and Places services.

Source: https://code.google.com/p/gmaps-api-issues/issues/detail?id=7824


EDIT - Google updated their documents to explicitly call this out now:

  1. https://developers.google.com/places/android-api/start#api-key
  2. https://developers.google.com/maps/documentation/android-sdk/signup#use-key

这篇关于Android - API密钥只能指定一次&lt; meta-data&gt;重复的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆