Google地图未在发布模式下显示在Android上

use*_*212 7 android google-maps keytool android-keystore android-maps-v2

我试图发布我的应用程序,但谷歌地图有问题.该应用程序包含一个显示地图的活动(MapActivity).在调试模式下运行时,地图工作正常.我在发布模式下签署了我的应用程序,并获得了SHA1.我根据需要在Google控制台上创建了一个新的Android密钥(SHA1; packageName).获得了API密钥

在我的应用程序中,我根据需要引用了google-play-services-lib的副本.我正在使用ADT.

map.xml

<?xml version="1.0" encoding="utf-8"?>
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:name="com.google.android.gms.maps.SupportMapFragment" />
Run Code Online (Sandbox Code Playgroud)

MapActivity.java

public class MapActivity extends FragmentActivity {

private GoogleMap map;

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

    map = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map))
                        .getMap();
  }
Run Code Online (Sandbox Code Playgroud)

AndroidManifest.xml中

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



<uses-sdk
    android:minSdkVersion="8"
    android:targetSdkVersion="16" />
<uses-permission android:name="android.permission.INTERNET"></uses-permission>

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

<uses-feature
android:glEsVersion="0x00020000"
android:required="true"/>

<permission
      android:name="com.example.rentalcar.permission.MAPS_RECEIVE"
      android:protectionLevel="signature"/>
    <uses-permission android:name="com.example.rentalcar.permission.MAPS_RECEIVE"/>


<application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme"
     >

    <activity
        android:name="com.example.rentalcar.MainActivity"
        android:label="@string/app_name"
        android:screenOrientation="portrait" >
         <intent-filter>
            <action android:name="android.intent.action.MAIN" />

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

    <activity
        android:name="com.example.rentalcar.MapActivity"
        android:label="@string/title_activity_map"
        android:screenOrientation="portrait" >
    </activity>

    <meta-data
        android:name="com.google.android.maps.v2.API_KEY"
        android:value="My_Key"/>

</application>

</manifest>
Run Code Online (Sandbox Code Playgroud)

唯一奇怪的是,当我使用keytool获取SHA1时,我得到"签名算法名称:SHA256withRSA.这可能是问题吗?如果是,我该如何更改它?

使用keytool获取证书指纹

我有点被困在这里!感谢您的任何帮助!

Tar*_*ior 12

如果你已经尝试@Budius回答并仍然面临此错误,则可能是由以下情况引起的:

当您添加MapFragment时,Android Studio会创建2个文件google_maps_api.xml:一个位于src/debug/res/values文件夹中,另一个位于src/release/res/values中.

但由于某些原因,只有调试文件夹文件显示在Android Studio上.因此,当您更改APIkey值时,它仅在调试文件夹文件中完成.

因此,只需将google_maps_api.xml文件复制到release文件夹,并确保两者都使用相同的APIKey.

在所有其他尝试之后,这对我有用.


Bud*_*ius 10

在地图API V2中,发布版本和调试版本之间唯一的变化是您在此处注册的密钥https://code.google.com/apis/console/

如果调试正在运行而最终版本没有,那么这是唯一必要的更改.

因此,我建议您仔细检查发布密钥库的哈希码,并确保在Google API控制台上正确输入.