简体   繁体   English

Google Play服务和Google Maps Android API版本2,授权失败

[英]Google Play Services and version 2 of the Google Maps Android API, Authorization failure

I am trying to build an Android application using the Google Play Services (revision 5) and version 2 of the Google Maps Android API. 我正在尝试使用Google Play服务(修订版5)和Google Maps Android API版本2来构建Android应用程序。

I read carefully the documents at : 我在以下位置仔细阅读了文件:

http://developer.android.com/google/play-services/maps.html https://developers.google.com/maps/documentation/android/start#installing_the_google_maps_android_v2_api http://developer.android.com/google/play-services/maps.html https://developers.google.com/maps/documentation/android/start#installing_the_google_maps_android_v2_api

In order to be sure, I just copied the sample app from : ~/android-sdk-linux/extras/google/google_play_services/samples 为了确定,我只是从以下位置复制了示例应用程序:〜/ android-sdk-linux / extras / google / google_play_services / samples

In this code, I just changed the developper key and the targetSdkVersion (16 -> 17) inside the manifest : 在这段代码中,我只是更改了清单中的开发者密钥和targetSdkVersion(16-> 17):

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

<permission
    android:name="com.example.mapdemo.permission.MAPS_RECEIVE"
    android:protectionLevel="signature" />

<uses-permission android:name="com.example.mapdemo.permission.MAPS_RECEIVE" />
<!-- Copied from Google Maps Library/AndroidManifest.xml. -->
<uses-sdk
    android:minSdkVersion="8"
    android:targetSdkVersion="17" />

<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
<!-- External storage for caching. -->
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<!-- My Location -->
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<!-- Maps API needs OpenGL ES 2.0. -->
<uses-feature
    android:glEsVersion="0x00020000"
    android:required="true" />
<!-- End of copy. -->
<application
    android:hardwareAccelerated="true"
    android:allowBackup="false"
    android:icon="@drawable/ic_launcher"
    android:label="@string/demo_title" >
    <meta-data
        android:name="com.google.android.maps.v2.API_KEY"
        android:value="XXXXXXXXXXXmyXkeyXXXXXXXXXXXXX" />

    <activity android:name=".MainActivity" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <activity
        android:name=".BasicMapActivity"
        android:label="@string/basic_map" />
    <activity
        android:name=".CameraDemoActivity"
        android:label="@string/camera_demo" />
    <activity
        android:name=".CircleDemoActivity"
        android:label="@string/circle_demo" />
    <activity
        android:name=".EventsDemoActivity"
        android:label="@string/events_demo" />
    <activity
        android:name=".GroundOverlayDemoActivity"
        android:label="@string/groundoverlay_demo" />
    <activity
        android:name=".LayersDemoActivity"
        android:label="@string/layers_demo" />
    <activity
        android:name=".LocationSourceDemoActivity"
        android:label="@string/locationsource_demo" />
    <activity
        android:name=".MarkerDemoActivity"
        android:label="@string/marker_demo" />
    <activity
        android:name=".OptionsDemoActivity"
        android:label="@string/options_demo" />
    <activity
        android:name=".PolygonDemoActivity"
        android:label="@string/polygon_demo" />
    <activity
        android:name=".PolylineDemoActivity"
        android:label="@string/polyline_demo" />
    <activity
        android:name=".ProgrammaticDemoActivity"
        android:label="@string/programmatic_demo" />
    <activity
        android:name=".TileOverlayDemoActivity"
        android:label="@string/tile_overlay_demo" />
    <activity
        android:name=".UiSettingsDemoActivity"
        android:label="@string/uisettings_demo" />
    <activity
        android:name=".RawMapViewDemoActivity"
        android:label="@string/raw_mapview_demo" />
    <activity
        android:name=".RetainMapActivity"
        android:label="@string/retain_map" />
    <activity
        android:name=".MultiMapDemoActivity"
        android:label="@string/multi_map_demo" />
</application>

The Google Play Library Project is correctly set in the project properties. 在项目属性中正确设置了Google Play库项目。

I didn't modify the proguard.cfg standard file. 我没有修改proguard.cfg标准文件。

Launching "Google Maps API Demos" on my Motorola Xoom with android 4.1.2, and clicking on "Basic Map", returns a blank screen without any map. 在装有Android 4.1.2的Motorola Xoom上启动“ Google Maps API演示”,然后单击“基本地图”,返回没有任何地图的空白屏幕。

My logcat contains : 我的logcat包含:

03-17 14:07:13.450: E/Google Maps Android API(17988): Authorization failure.

In my API Console, "Google Maps Android API v2" is on. 在我的API控制台中,“ Google Maps Android API v2”处于启用状态。

I created a key for Android apps, and my console displays : 我为Android应用创建了一个密钥,控制台显示:

Key for Android apps (with certificates)
API key:    XXXXXXXXXXXmyXkeyXXXXXXXXXXXXX
Android apps:   XXXXXXXXXXXmyXSHA1XXXXXXXXXXXXX;com.example.mapdemo
Activated on:   Mar 17, 2013 4:28 AM
Activated by:    you

Do you understand what is wrong ? 你知道错在哪里吗?

I've found the answer : if I export my app in a signed apk, push it to the tablet and install it, I'm able to see the map correctly. 我找到了答案:如果我将我的应用程序导出为已签名的apk,将其推到平板电脑上并安装,我就能正确看到地图。 Thanks for your answers. 感谢您的回答。

To debug the app, you need to generate a key with the debug certificate fingerprint, as explained in : https://developers.google.com/maps/documentation/android/start#displaying_certificate_information 要调试该应用,您需要生成带有调试证书指纹的密钥,如: https : //developers.google.com/maps/documentation/android/start#displaying_certificate_information中所述

I just had this issue, posted here . 我刚遇到这个问题,发布在这里 To be able to launch from the IDE, add the debug/development SHA1 fingerprint to the API console along with the production one you made from your own keystore. 为了能够从IDE启动,请将调试/开发SHA1指纹以及您从自己的密钥库中制作的生产指纹添加到API控制台。

Just run from command line keytool -list -v -keystore <keystoreName>.keystore for both debug.keystore (in ~/.android directory) and also <yourKeystore>.keystore (to use when you sign .apks) 只需从命令行keytool -list -v -keystore <keystoreName>.keystore ,即可同时使用debug.keystore (在~/.android目录中)和<yourKeystore>.keystore (在对.apks签名时使用)

This will give you two SHA1 fingerprints, add them both to the Google Maps Android API v2 in the Google Cloud Console, now you have one for dev and one for live. 这将为您提供两个SHA1指纹,然后将它们都添加到Google Cloud Console中的Google Maps Android API v2中,现在您可以拥有一个供开发人员使用,另一个供现场使用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM