Google地图v2授权失败。不同的SHA1 [英] Google Maps v2 Authorization failure. Different SHA1

查看:186
本文介绍了Google地图v2授权失败。不同的SHA1的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已阅读所有类似问题,并完成了其中描述的所有内容,但无济于事。

Google地图API v2已启用,
API key是正确的


我只是在New project中选择了GoogleMapsActivity,然后创建了一个key.jks,通过keytool创建了sha1,创建了public API访问键,键清单。

我试过了:
clean-rebuild-unistall app-install

更新了api键许多次

使用新的key.jks创建一个新项目(并且重新开始)

删除并创建api项

这是我的清单:

 < manifest xmlns:android =http://schemas.android.com/apk/res/android
package =com.dandewine.user.thinkmobiletest>

<使用权限android:name =android.permission.INTERNET/>
< uses-permission android:name =android.permission.ACCESS_NETWORK_STATE/>
< uses-permission android:name =android.permission.WRITE_EXTERNAL_STORAGE/>
<使用权限android:name =com.google.android.providers.gsf.permission.READ_GSERVICES/>
<! -

ACCESS_COARSE / FINE_LOCATION权限不需要使用
Google Maps Android API v2,但建议使用。
- >

 < application 
android:allowBackup = true
android:icon =@ mipmap / ic_launcher
android:label =@ string / app_name
android:theme =@ style / AppTheme>
< meta-data
android:name =com.google.android.gms.version
android:value =@ integer / google_play_services_version/>
< meta-data
android:name =com.google.android.maps.v2.API_KEY
android:value =AIza ********** ****************/>

< activity
android:name =。ActivityMain
android:label =@ string / title_activity_activity_main>
< intent-filter>

< category android:name =android.intent.category.LAUNCHER/>
< / intent-filter>
< / activity>
< / application>



这是我的活动:

  public class ActivityMain extends FragmentActivity implements OnMapReadyCallback {


@Override
protected void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.fragment_map);

SupportMapFragment mapFragment =(SupportMapFragment)getSupportFragmentManager()。findFragmentById(R.id.map);
mapFragment.getMapAsync(this);

$ b @Override
public void onMapReady(GoogleMap googleMap){
googleMap.addMarker(new MarkerOptions()
.position(new LatLng(0 ,0))
.title(Marker));

Logcat:

  E / Google Maps Android API:授权失败。有关如何正确设置地图的信息,请参阅https://developers.google.com/maps/documentation/android/start。 
07-27 14:52:37.551 25002-25035 / com.dandewine.user.thinkmobiletest E / Google Maps Android API:在Google Developer Console(https://console.developers.google.com)中,
确保已启用Google Maps Android API v2。
确保存在以下Android密钥:
API密钥:AIza ****************************
Android应用程序(< cert_fingerprint> ;;< package_name>):8C:2B:4C:F7:CF:FB:EC:D5:DC:D7:D0:5D:6E:30:49:74:97: 18:57:88; com.dandewine.user.thinkmobiletest

更新 :我在谷歌开发中有不同的SHA1指纹。控制台和日志中,如何处理该问题?



任何人都可以提供建议帮助。

解决方案



对于调试/运行来说,这听起来像是使用密钥库中的SHA1指纹来生成签名的apk。从Android Studio开始,您需要使用Android Studio用来签署apk的SHA1指纹。



请注意,您可以使用命令行获取此SHA1指纹:



对于Mac或Linux:

  keytool -list -v -keystore〜 /.android/debug.keystore 

对于Windows:

  keytool -list -v -keystore C:\User\YourUser\.android\debug.keystore 

带密码android。然而,由于您的日志中已经有了正确的值,
只是从你的日志中复制这个(我在这里修改它,不要从这里复制):

  8C:2B:4C:F7:CF:FB:EC:D5:DC:D7:D0:5D:6E:30:49:XX:XX:XX:XX: xx; com.dandewine.user.thinkmobiletest 

并将其粘贴到开发人员控制台中的API密钥中。

您可以为每个API密钥添加多个指纹/包值,每行一个(您在编辑API密钥时也可以在说明中看到)。



您也可以为调试和发布配置不同的API密钥,如果您这样做看看这个答案


I have read all the similar questions and did everything that was described in them, but did not help.

Google Maps API v2 is Enabled and API key is correct

I just chose GoogleMapsActivity in "New project", then created a key.jks, created sha1 by keytool, created public api access key, put my API key in manifest.

I tried: clean-rebuild-unistall app-install
updated api key many times
create a new project with the new key.jks (and all over again)
delete and create api key

Here is my manifest:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.dandewine.user.thinkmobiletest" >

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
<!--

The ACCESS_COARSE/FINE_LOCATION permissions are not required to use Google Maps Android API v2, but are recommended. -->

<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
    <meta-data
        android:name="com.google.android.gms.version"
        android:value="@integer/google_play_services_version" />
    <meta-data
        android:name="com.google.android.maps.v2.API_KEY"
        android:value="AIza**************************" />

    <activity
        android:name=".ActivityMain"
        android:label="@string/title_activity_activity_main" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
</application>

Here is my activity:

public class ActivityMain extends FragmentActivity implements OnMapReadyCallback {


@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.fragment_map);

    SupportMapFragment mapFragment = (SupportMapFragment)getSupportFragmentManager().findFragmentById(R.id.map);
    mapFragment.getMapAsync(this);
}

@Override
public void onMapReady(GoogleMap googleMap) {
    googleMap.addMarker(new MarkerOptions()
            .position(new LatLng(0, 0))
            .title("Marker"));
}

Logcat:

E/Google Maps Android API﹕ Authorization failure.  Please see            https://developers.google.com/maps/documentation/android/start for how to correctly set up the map.
07-27 14:52:37.551  25002-25035/com.dandewine.user.thinkmobiletest E/Google Maps Android API﹕ In the Google Developer Console (https://console.developers.google.com)
Ensure that the "Google Maps Android API v2" is enabled.
Ensure that the following Android Key exists:
API Key: AIza****************************
Android Application (<cert_fingerprint>;<package_name>): 8C:2B:4C:F7:CF:FB:EC:D5:DC:D7:D0:5D:6E:30:49:74:97:18:57:88;com.dandewine.user.thinkmobiletest

UPDATE: I have different SHA1 fingerprints in google dev. console and in logs, how to deal with that?

Can anyone help with advice.

解决方案

It sounds like you're using the SHA1 fingerprint from the keystore that you will be using to generate a signed apk.

For debugging/running from Android Studio, you need to use the SHA1 fingerprint that Android Studio uses to sign the apk.

Note that you can get this SHA1 fingerprint by using command line:

For Mac or Linux:

keytool -list -v -keystore ~/.android/debug.keystore

For Windows:

keytool -list -v -keystore C:\User\YourUser\.android\debug.keystore

with password "android".

However, since you already have the correct value in your logs, just copy this from your logs (I modified it here, don't copy from here):

8C:2B:4C:F7:CF:FB:EC:D5:DC:D7:D0:5D:6E:30:49:xx:xx:xx:xx:xx;com.dandewine.user.thinkmobiletest

And paste that into your API Key in the developer console.

You can add multiple fingerprint/package values to each API key, one per line (you can also see that in the instructions when you are editing an API key).

You can also configure a different API key for debug and release, if you do that take a look at this answer.

这篇关于Google地图v2授权失败。不同的SHA1的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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