我正在尝试发布我的应用程序,但谷歌地图出现问题。 该应用程序包含一个显示 map 的 Activity (MapActivity)。在 Debug模式下运行时, map 工作正常。 我在 Release模式下签署了我的应用程序,并获得了 SHA1。 我根据需要在 Google 控制台上创建了一个新的 android key (SHA1;packageName)。获得 API key
在我的应用程序中,我根据需要引用了 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" />
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 上。因此,当您更改 APIkey 值时,它仅在调试文件夹文件中完成。
因此只需将 google_maps_api.xml 文件复制到 release 文件夹并确保两者具有相同的 APIKey。
在所有其他尝试之后,这对我有用。
关于android - 谷歌地图在 Release模式下未在 Android 上显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15219501/