2015-10-07 78 views
2

我想推出一個Android穿戴有一個模擬器,但它崩潰上啓動和得到以下錯誤: 谷歌API金鑰缺少

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 

但奇怪的是我並在我的清單中定義它像這樣:

新editted說, 「作品」

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

EDIT 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密鑰我把,但仍然得到同樣的錯誤信息運行該項目時。任何建議我在這裏失蹤?

在此先感謝。

幾乎沒有

玉傢伙,它看起來像它的工作,但它不顯示我的地圖,這是一個灰色區域。我想我可以解僱的應用程序,當我長按它。

所以也許它可能是別的東西,爲什麼它不顯示我的地圖?

+0

我做了清潔和重建項目順便說一句。 –

+1

在開發者控制檯中的應用中驗證了這個密鑰嗎? – AndroidEnthusiast

+0

我製作了Google Maps Android API密鑰。用我的包名稱輸入sha-1。然後它爲我使用的API生成了一個API密鑰。所以我需要做其他事情才能使用特定的密鑰? –

回答

1

我認爲灰屏的問題是您沒有正確獲取API密鑰。請確保您已正確獲得密鑰。當我的密鑰生成發佈而不是調試模式時,我遇到了這個確切的問題。

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

+0

嗯,我創建了一個調試密鑰庫,並從那個創建的API密鑰,仍然沒有運氣..我會嘗試在今天晚些時候在我的實際設備上運行它。 –

+0

您是否添加了<使用權限android:name =「android.permission.INTERNET」/>''' – caesiium

+0

我做到了,無論如何,當我在我的設備上而不是仿真器上調試它時,我已經使用它了。 –

0

我檢查了你的清單並發現它存在問題。

請在文件末尾添加</manifest>標籤。

+0

不知何故,stackoverflow不會將其添加到我的代碼中,但它在那裏。但我要更新xml文件。我改變了一下,並得到它「工作」,但得到另一個「錯誤」 –

+0

張貼您的錯誤。 – KishuDroid

+0

請參閱原文中的編輯2。 –