检查 <meta-data android:name="com.google.android.geo.API_KEY" android:value="your AP

Posted

技术标签:

【中文标题】检查 <meta-data android:name="com.google.android.geo.API_KEY" android:value="your API key"/> 是不是在 AndroidManifest.xml 的 <application> 中【英文标题】:Check <meta-data android:name="com.google.android.geo.API_KEY" android:value="your API key"/> is in the <application> of AndroidManifest.xml检查 <meta-data android:name="com.google.android.geo.API_KEY" android:value="your API key"/> 是否在 AndroidManifest.xml 的 <application> 中 【发布时间】:2019-07-20 22:14:54 【问题描述】:

我的 api 密钥在正确的位置,但出现上述错误。我已经清理了我的项目并重新安装了。下面是我的安卓清单。我收到“错误膨胀类片段,原因是:android.view.InflationException:找不到 API 密钥...检查 ^(上图)。”任何人都知道为什么或也遇到过这个?另一个堆栈溢出问题没有帮助,因为我的位置正确:(

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

    <uses-permission android:name="android.permission.INTERNET"/>
    <uses-permission android:name="com.google.maps.android.utils.permission.MAPS_RECEIVE"/>
    <uses-permission android:name="android.permission.ACCESS_GPS" />
    <uses-permission android:name="android.permission.ACCESS_ASSISTED_GPS" />
    <uses-permission android:name="android.permission.ACCESS_LOCATION" />
    <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="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">

        <activity android:name=".OnBoardingActivity"></activity>
        <activity android:name=".HomeActivity" />
        <activity android:name=".SignUpActivity" />
        <activity android:name=".MainActivity">
            <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="@integer/google_play_services_version" />

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

    </application>

</manifest>

Also my fragment_map.xml where error happening (at inflating fragment)...

<fragment
        android:id="@+id/map"
        android:layout_
        android:layout_
        android:layout_weight="1"
        android:name="com.google.android.gms.maps.SupportMapFragment" />

...my Map.xml...

<?xml version="1.0" encoding="utf-8"?>
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:map="http://schemas.android.com/apk/res-auto"
    android:id="@+id/map"
    android:layout_
    android:layout_
    android:name="com.google.android.gms.maps.SupportMapFragment"/>

如果有帮助,也是我的 BUILD GRADLE

apply plugin: 'com.android.application'
apply plugin: 'com.google.gms.google-services'

android 
    compileSdkVersion 29
    buildToolsVersion "29.0.0"
    defaultConfig 
        applicationId "com.example.water"
        minSdkVersion 16
        targetSdkVersion 29
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
        multiDexEnabled true
    
    buildTypes 
        release 
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        
    
    packagingOptions 
        exclude 'META-INF/DEPENDENCIES'
        exclude 'META-INF/LICENSE'
        exclude 'META-INF/LICENSE.txt'
        exclude 'META-INF/license.txt'
        exclude 'META-INF/NOTICE'
        exclude 'META-INF/NOTICE.txt'
        exclude 'META-INF/notice.txt'
        exclude 'META-INF/ASL2.0'
    


repositories 
    mavenCentral()


dependencies 
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'androidx.appcompat:appcompat:1.0.2'
    implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
    implementation 'com.google.firebase:firebase-auth:18.1.0'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'androidx.test:runner:1.2.0'
    implementation "com.airbnb.android:lottie:3.0.7"
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
    implementation 'com.google.android.material:material:1.0.0'
    implementation 'com.jjoe64:graphview:4.2.2'
    implementation 'com.google.firebase:firebase-database:18.0.0'
    implementation 'com.google.firebase:firebase-firestore:20.1.0'
    implementation 'com.android.support:multidex:1.0.3'
    implementation 'com.google.api-client:google-api-client:1.25.0'
    implementation 'com.google.api:api-common:1.8.1'
    implementation 'com.google.android.libraries.places:places:1.0.0'
    implementation 'com.google.android.gms:play-services-maps:16.1.0'
    implementation 'com.google.maps.android:android-maps-utils:0.5+'

【问题讨论】:

【参考方案1】:

我是编程新手,但对我有用的是将元数据放在使用权限之上,就像这样

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" 
android:versionCode="1" android:versionName="1.0" 
package="com.companyname.travelrecordapp" android:installLocation="auto">
<application android:label="TravelRecordApp.Android">
<meta-data android:name="com.google.android.maps.v2.API_KEY" 
android:value="AIzaSyDXPYQlj1g15DeT7DvG9qeg1IFjRYRsrM0"/>
</application>
<uses-sdk android:minSdkVersion="21" android:targetSdkVersion="28" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<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_LOCATION_EXTRA_COMMANDS" />
<uses-permission android:name="android.permission.ACCESS_NOTIFICATION_POLICY" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.ACCESS_MOCK_LOCATION" />
<uses-permission android:name="android.permission.INJECT_EVENTS" />
<uses-permission android:name="android.permission.READ_CALENDAR" />
<uses-permission android:name="android.permission.INTERNET" />
</manifest>

【讨论】:

以上是关于检查 <meta-data android:name="com.google.android.geo.API_KEY" android:value="your AP的主要内容,如果未能解决你的问题,请参考以下文章

将 'tools:replace="Android:value"' 添加到 AndroidManifest 中的 <meta-data> 元素

“建议:将 'tools:replace="android:value"' 添加到 AndroidManifest.xml:12:9-14:91 中的 <meta-data&

Missing android.support.FILE_PROVIDER_PATHS meta-data 报错原因分析

使用 gradle 在编译时动态设置 Android resValue / BuildConfig / Manifes中&lt;meta-data&gt;变量的值

Manifest中meta-data扩展元素数据的配置与获取

not found for signing config ‘debug‘Android中meta-data的作用xmlns:tools=“http://schemas.android.com/