检查< meta-data android:name="com.google.android.geo.API_KEY" android:value="your API key"/> AndroidManifest.xml中的< application>

oxosxuxt  于 2023-04-04  发布在  Android
关注(0)|答案(2)|浏览(191)

我在正确的地方有API密钥,但我得到了上述错误。我已经清理了我的项目并重新安装。下面是我的android清单。我得到了一个“错误膨胀类片段造成的:android.view.InflationException:API key not found ... check that ^(above).”有人知道为什么或者也遇到过这个问题吗?其他堆栈溢出问题没有帮助,因为我的在正确的位置:(

<?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_width="match_parent"
        android:layout_height="0dp"
        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_width="match_parent"
    android:layout_height="match_parent"
    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+'
}
dwthyt8l

dwthyt8l1#

我是编程新手,但对我有用的是将元数据放置在uses权限之上,如下所示

<?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>
qnakjoqk

qnakjoqk2#

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

1.获取密钥:
1.转到Google Cloud Console并创建一个新项目或选择一个现有项目。
2.点击左侧的“API & Services”菜单,然后选择“Credentials”。
3.点击“Create credentials”按钮,然后从下拉菜单中选择“API key”。
4.按照提示创建API密钥。您可以选择将密钥限制为特定Android应用和/或特定API。
5.创建API密钥后,将其复制并粘贴到Android应用程序中(例如android:value=“XXXXXXXXXXXXXXXXXXXXXXXXXXXX”)

  • 别忘了启用服务,例如Android版MapSDK

相关问题