应用在 Google Play 服务方面遇到问题。请再试一遍
App is having trouble with Google Play Services. Please try again
这段代码我已经做过好几次了。但是从今天早上开始我看到这个问题发生了。这是显示地图布局的基本代码。并向我显示此错误。而且我还正确输入了 API 键。Screen Shot of Emulator我搜索了其他 Whosebug 帖子,但对我没有任何帮助。
package com.example.maptest
import android.support.v7.app.AppCompatActivity
import android.os.Bundle
import com.google.android.gms.maps.CameraUpdateFactory
import com.google.android.gms.maps.GoogleMap
import com.google.android.gms.maps.OnMapReadyCallback
import com.google.android.gms.maps.SupportMapFragment
import com.google.android.gms.maps.model.LatLng
import com.google.android.gms.maps.model.MarkerOptions
class MapsActivity : AppCompatActivity(), OnMapReadyCallback {
private lateinit var mMap: GoogleMap
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_maps)
// Obtain the SupportMapFragment and get notified when the map is ready to be used.
val mapFragment = supportFragmentManager
.findFragmentById(R.id.map) as SupportMapFragment
mapFragment.getMapAsync(this)
}
/**
* Manipulates the map once available.
* This callback is triggered when the map is ready to be used.
* This is where we can add markers or lines, add listeners or move the camera. In this case,
* we just add a marker near Sydney, Australia.
* If Google Play services is not installed on the device, the user will be prompted to install
* it inside the SupportMapFragment. This method will only be triggered once the user has
* installed Google Play services and returned to the app.
*/
override fun onMapReady(googleMap: GoogleMap) {
mMap = googleMap
// Add a marker in Sydney and move the camera
val sydney = LatLng(-34.0, 151.0)
mMap.addMarker(MarkerOptions().position(sydney).title("Marker in Sydney"))
mMap.moveCamera(CameraUpdateFactory.newLatLng(sydney))
}
}
Xml 文件:-
<?xml version="1.0" encoding="utf-8"?>
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:map="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/map"
tools:context=".MapsActivity"
android:name="com.google.android.gms.maps.SupportMapFragment"/>
应用级别gradle:-
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
android {
compileSdkVersion 28
defaultConfig {
applicationId "com.example.maptest"
minSdkVersion 21
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation"org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.google.android.gms:play-services-maps:16.1.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}
项目级别gradle:-
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
ext.kotlin_version = '1.3.21'
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.3.1'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
我解决了这个问题。
通过更改应用级别 gradle 依赖项
由此
implementation 'com.google.android.gms:play-services-maps:16.1.0'
至此
implementation 'com.google.android.gms:play-services-maps:16.0.0'
更新:
现在我可以使用这个最新的 gradle 依赖项。它对我来说很好用。
implementation 'com.google.android.gms:play-services-maps:16.1.0'
检查您正在构建的变体 (release/debug) 是否已正确签名...
右击模块 => 打开模块设置
在 Build Types 下检查 Signing Config
api 'com.google.android.gms:play-services-maps:16.1.0'
以上在现实世界中对我来说工作正常 - 但我不使用模拟器。
AS 3.3.2/插件 3.3.2/Gradle4.10.2/compileSdkVersion 28/buildToolsVersion“28.0.3”
我也遇到了这个问题,当我将依赖项更改为 implementation 'com.google.android.gms:play-services-maps:16.0.0'
时,地图没有加载。
所以我在我的模拟器上更新了 Google Play 服务:
之后,我必须登录才能访问 Play 商店,然后才能更新 Google Play 服务。
最后,我让依赖为implementation 'com.google.android.gms:play-services-maps:16.1.0'
有点晚了,但我也遇到了这个问题。按照此处的建议更改依赖项对我没有用。真正起作用的是在模拟器上进入 chrome 并搜索 Google Play 服务。单击建议的 link 到应用程序商店,它应该会带您到浏览器中的 Play 商店。单击底部的按钮可在模拟器上的应用商店中打开它(因为在 Play 商店中搜索它实际上并不能调出它,您必须通过浏览器),希望它能为您提供选项更新 Google Play 服务。之后它对我来说非常有用!
这段代码我已经做过好几次了。但是从今天早上开始我看到这个问题发生了。这是显示地图布局的基本代码。并向我显示此错误。而且我还正确输入了 API 键。Screen Shot of Emulator我搜索了其他 Whosebug 帖子,但对我没有任何帮助。
package com.example.maptest
import android.support.v7.app.AppCompatActivity
import android.os.Bundle
import com.google.android.gms.maps.CameraUpdateFactory
import com.google.android.gms.maps.GoogleMap
import com.google.android.gms.maps.OnMapReadyCallback
import com.google.android.gms.maps.SupportMapFragment
import com.google.android.gms.maps.model.LatLng
import com.google.android.gms.maps.model.MarkerOptions
class MapsActivity : AppCompatActivity(), OnMapReadyCallback {
private lateinit var mMap: GoogleMap
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_maps)
// Obtain the SupportMapFragment and get notified when the map is ready to be used.
val mapFragment = supportFragmentManager
.findFragmentById(R.id.map) as SupportMapFragment
mapFragment.getMapAsync(this)
}
/**
* Manipulates the map once available.
* This callback is triggered when the map is ready to be used.
* This is where we can add markers or lines, add listeners or move the camera. In this case,
* we just add a marker near Sydney, Australia.
* If Google Play services is not installed on the device, the user will be prompted to install
* it inside the SupportMapFragment. This method will only be triggered once the user has
* installed Google Play services and returned to the app.
*/
override fun onMapReady(googleMap: GoogleMap) {
mMap = googleMap
// Add a marker in Sydney and move the camera
val sydney = LatLng(-34.0, 151.0)
mMap.addMarker(MarkerOptions().position(sydney).title("Marker in Sydney"))
mMap.moveCamera(CameraUpdateFactory.newLatLng(sydney))
}
}
Xml 文件:-
<?xml version="1.0" encoding="utf-8"?>
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:map="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/map"
tools:context=".MapsActivity"
android:name="com.google.android.gms.maps.SupportMapFragment"/>
应用级别gradle:-
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
android {
compileSdkVersion 28
defaultConfig {
applicationId "com.example.maptest"
minSdkVersion 21
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation"org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.google.android.gms:play-services-maps:16.1.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}
项目级别gradle:-
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
ext.kotlin_version = '1.3.21'
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.3.1'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
我解决了这个问题。
通过更改应用级别 gradle 依赖项
由此
implementation 'com.google.android.gms:play-services-maps:16.1.0'
至此
implementation 'com.google.android.gms:play-services-maps:16.0.0'
更新:
现在我可以使用这个最新的 gradle 依赖项。它对我来说很好用。
implementation 'com.google.android.gms:play-services-maps:16.1.0'
检查您正在构建的变体 (release/debug) 是否已正确签名...
右击模块 => 打开模块设置
在 Build Types 下检查 Signing Config
api 'com.google.android.gms:play-services-maps:16.1.0'
以上在现实世界中对我来说工作正常 - 但我不使用模拟器。
AS 3.3.2/插件 3.3.2/Gradle4.10.2/compileSdkVersion 28/buildToolsVersion“28.0.3”
我也遇到了这个问题,当我将依赖项更改为 implementation 'com.google.android.gms:play-services-maps:16.0.0'
时,地图没有加载。
所以我在我的模拟器上更新了 Google Play 服务:
之后,我必须登录才能访问 Play 商店,然后才能更新 Google Play 服务。
最后,我让依赖为implementation 'com.google.android.gms:play-services-maps:16.1.0'
有点晚了,但我也遇到了这个问题。按照此处的建议更改依赖项对我没有用。真正起作用的是在模拟器上进入 chrome 并搜索 Google Play 服务。单击建议的 link 到应用程序商店,它应该会带您到浏览器中的 Play 商店。单击底部的按钮可在模拟器上的应用商店中打开它(因为在 Play 商店中搜索它实际上并不能调出它,您必须通过浏览器),希望它能为您提供选项更新 Google Play 服务。之后它对我来说非常有用!