我想在我的Android应用程序中实现谷歌地图,我只是按照谷歌地图平台的说明操作,但没有成功。我不知道为什么元数据不存在,而我已经在清单中声明了它:
AndroidManifest.xml
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:usesCleartextTraffic="true"
tools:ignore="AllowBackup"
tools:targetApi="m">
<activity android:name="some.Activity"></activity>
<meta-data
tools:replace="android:value"
android:name="com.google.android.gms.version"
android:value="${MAPS_API_KEY}" />
</application>
local.properties
MAPS_API_KEY=HereIsTheSecretAPIstored
build.gradle(:app(
plugins {
id 'com.google.secrets_gradle_plugin' version '0.5'
}
服务地图版本:
implementation "com.google.android.gms:play-services-maps:17.0.1"
堆栈跟踪:
Caused by: com.google.android.gms.common.GooglePlayServicesMissingManifestValueException: A required meta-data tag in your app's AndroidManifest.xml does not exist. You must have the following declaration within the <application> element: <meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version" />
at com.google.android.gms.common.GooglePlayServicesUtilLight.isGooglePlayServicesAvailable(com.google.android.gms:play-services-basement@@17.5.0:17)
有人能帮我吗?
经过一番努力,我终于用这个解决方案解决了问题:
- 更改元数据并移动到活动标记的顶部
来自
<meta-data
tools:replace="android:value"
android:name="com.google.android.gms.version"
android:value="${MAPS_API_KEY}" />
至
<meta-data
android:name="com.google.android.geo.API_KEY"
android:value="${MAPS_API_KEY}" />
2此外,我忘记在谷歌控制台中为Android启用地图SDK,所以我启用了它。