缺少 Google Api 密钥 [英] Google Api Key Missing

查看:31
本文介绍了缺少 Google Api 密钥的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用模拟器启动 Android 可穿戴设备,但它在启动时崩溃并出现以下错误:

I am trying to launch an android wearable with an emulator, but it crashes on startup and getting the following error:  

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

但奇怪的是我确实在我的清单中像这样定义了它:

But the weird part is i did defined it in my manifest like this:

有效"的新编辑

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

    <!-- Mark this app as an Android Wear app. -->
    <uses-feature android:name="android.hardware.type.watch" />

    <!-- Permission required for ambient mode to keep the application running. -->
    <uses-permission android:name="android.permission.WAKE_LOCK" />

    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>

    <application

        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:theme="@android:style/Theme.DeviceDefault" >

        <!-- API key for the Android Maps API v2. The value is defined as a string resource. -->
        <meta-data android:name="com.google.android.geo.API_KEY"
            android:value="xxxxxxxxxxxxxxx"/>

        <!-- Reference the wearable shared library required to support ambient mode. -->
        <uses-library android:name="com.google.android.wearable" android:required="false" />

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

</manifest>

编辑 2

我得到以下信息:

10-07 10:04:43.972    1614-1614/com.wearfare.wearapp.gpswear W/ResourcesManager﹕ Asset path '/system/framework/com.google.android.wearable.jar' does not exist or contains no resources.
10-07 10:04:43.993    1614-1631/com.wearfare.wearapp.gpswear I/GMPM﹕ App measurement is starting up
    10-07 10:04:43.995    1614-1631/com.wearfare.wearapp.gpswear E/GMPM﹕ getGoogleAppId failed with status: 10
    10-07 10:04:43.995    1614-1631/com.wearfare.wearapp.gpswear E/GMPM﹕ Uploading is not possible. App measurement disabled

编辑 build.gradle

EDIT build.gradle

apply plugin: 'com.android.application'android {
        signingConfigs {
        }
        compileSdkVersion 22
        buildToolsVersion "23.0.1"
        defaultConfig {
            applicationId "com.wearfare.wearapp.gpswear"
            minSdkVersion 22
            targetSdkVersion 23
            versionCode 1
            versionName "1.0"
        }
        buildTypes {
            release {
                minifyEnabled false
                proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            }
        }
    }

    dependencies {
        compile fileTree(dir: 'libs', include: ['*.jar'])
        compile 'com.google.android.support:wearable:1.3.0'
        provided 'com.google.android.wearable:wearable:1.0.0'
        compile 'com.google.android.gms:play-services-wearable:8.1.0'
        compile 'com.google.android.gms:play-services:8.1.0'
        compile 'com.android.support:support-v4:23.0.1'
        compile 'com.google.android.gms:play-services-maps:8.1.0'
    }

xxx 是我输入的 api 密钥,但在运行项目时仍然收到相同的错误消息.我在这里缺少什么建议?

xxx is the api key i put in, but still getting the same error message when running the project. any suggestions what i am missing here?

提前致谢.

快到了

好的,伙计们,看起来它确实有效,但它没有显示我的地图,它是一个灰色区域.我发现当我长按它时我可以关闭它.

Ok Guys, it looks like it does work, but it doesnt show my map, it's a grey field. I figured out i can dismiss the app when i longpress it.

那么也许是其他原因导致它不显示我的地图?

So maybe it could be something else why it isnt showing my map?

推荐答案

我觉得灰屏的问题是你没有正确获取API key.请确保您已正确获取密钥.当我的密钥是为发布而不是调试模式生成时,我遇到了这个确切的问题.

I think the problem of the grey screen is that you didn't obtain the API key correctly. Please ensure that you have obtained the key correctly. I've had this exact problem when my key was generated for release instead of debug mode.

https://developers.google.com/maps/documentation/android-api/start#obtaining_an_api_key

这篇关于缺少 Google Api 密钥的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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