【问题标题】:Google Api Key Missing谷歌 API 密钥丢失
【发布时间】:2016-01-04 11:21:12
【问题描述】:

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

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

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

“有效”的新编辑

<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

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 密钥,但在运行项目时仍然收到相同的错误消息。有什么建议我在这里缺少什么?

提前致谢。

差不多了

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

所以也许它没有显示我的地图可能是其他原因?

【问题讨论】:

  • 我确实清理并重建了项目。
  • 此密钥是否已在开发者控制台中的应用中验证?
  • 我制作了一个 Google Maps Android API 密钥。使用我的包名输入 sha-1。然后它为我生成了一个我正在使用的 API 密钥。所以我需要做些别的事情才能使用那个特定的键?
  • 我正在关注本教程:developers.google.com/maps/documentation/android-api/… 所以我可能是。
  • 请同时发布您的 build.gradle

标签: android api maps key


【解决方案1】:

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

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

【讨论】:

  • 嗯,我创建了一个调试密钥库并从中创建了 api 密钥,但仍然没有运气。我将尝试在今天晚些时候在我的实际设备上运行它。
  • 你加了&lt;uses-permission android:name="android.permission.INTERNET" /&gt;
  • 我做到了,无论如何,当我在我的设备而不是模拟器上调试它时,我让它工作了。
【解决方案2】:

我检查了您的清单,发现其中有问题。

请在文件末尾添加&lt;/manifest&gt;标签。

【讨论】:

  • 不知何故stackoverflow没有将它添加到我的代码中,但它就在那里。但我要更新 xml 文件。我对其进行了一些更改并使其“工作”,但又遇到了另一个“错误”
猜你喜欢
  • 2016-08-25
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-09-30
相关资源
最近更新 更多