我试图发布我的应用程序,但谷歌地图有问题。该应用程序包含一个显示地图的活动(MapActivity)。在调试模式下运行时,地图工作正常。我在发布模式下签署了我的应用程序,并获得了SHA1。我根据需要在Google控制台上创建了一个新的Android密钥(SHA1; packageName)。获得了API密钥
在我的应用程序中,我根据需要引用了google-play-services-lib的副本。我正在使用ADT。
map.chml
<?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" />
map activity.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();
}
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>
唯一奇怪的是,当我使用keytool获取SHA1时,我得到“签名算法名称:SHA256withRSA。这可能是问题吗?如果是,我该如何更改它?
我有点被困在这里!感谢您的任何帮助!
如果你已经尝试@Budius回答并仍然面临此错误,则可能是由以下情况引起的:
当您添加MapFragment时,Android Studio会创建2个文件google_maps_api.xml:一个位于src / debug / res / values文件夹中,另一个位于src / release / res / values中。
但由于某些原因,只有调试文件夹文件显示在Android Studio上。因此,当您更改API密钥值时,它仅在调试文件夹文件中完成。
因此,只需将google_maps_api.xml文件复制到release文件夹,并确保两者都使用相同的APIKey。
在所有其他尝试之后,这对我有用。
在地图API V2中,发布版本和调试版本之间唯一的变化是你在这里注册的密钥https://code.google.com/apis/console/
如果调试正在运行而最终版本没有,那么这是唯一必要的更改。
因此,我建议您仔细检查发布密钥库的哈希码,并确保在Google API控制台上正确输入。
只需清除数据(设置 - >应用程序 - 选择应用程序 - 清除数据 - >卸载)并尝试。这对我有用。确保程序包名称与google developer Console中的程序包名称相同。如果您是自定义密钥库中创建的SHA1代码,则在发布模式下使用相同的代码。或通过使用相同的密钥库进行签名来生成apk。
1-使用项目的“Android Manifest”文件中的“使用导出向导”创建apk文件。
2-插入键后,在完成之前,显示的MD5和SHA1键如图所示。
3-为第2点中检索到的新SHA1创建Android项目的新API密钥。
4-在清单文件中使用该API密钥,如下所示
5-清理项目并再次构建APK文件。
6-你现在可以在那个apk中看到谷歌地图。