【问题标题】:App is having trouble with Google Play Services. Please try again应用程序在使用 Google Play 服务时遇到问题。请再试一次
【发布时间】:2019-07-13 06:13:40
【问题描述】:

我已经多次编写此代码。但是从今天早上我看到这个问题发生了。这是显示地图布局的基本代码。并向我显示此错误。而且我也正确输入了 API 密钥。Screen Shot of Emulator我搜索了其他 StackOverflow 帖子,但对我没有任何帮助。

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"/>

应用级分级:-

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
}

【问题讨论】:

标签: android google-maps kotlin google-play-services


【解决方案1】:

我解决了这个问题。

通过更改应用级别的 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'

【讨论】:

  • 对我来说也是一样,尽管这并没有告诉我们为什么或如何为 16.1.0 修复它。谷歌可能会修复它。也许我们需要等待新的模拟器更新。我将 Nexus Api 27+28 x86 与 google 服务一起使用,这些服务在 google-services 16.1.0 上均失败并在 16.0.0 上工作
  • 谢谢!你为我节省了很多时间。
  • 我在 API 19 模拟器上试过这个。对于 16.1.0,它显示了这个错误,但对于 16.0.0,它写道:“Google Play 服务正在更新”永远。在 Nox App Player(也是 API 19)上尝试过,它显示了一张地图。谢谢。
  • 警告,降级会使您的应用在 Android 9 上崩溃,请参阅 stackoverflow.com/questions/52139199/…!真丢脸,谷歌!
  • 嘿@Co​​olMind 这个问题发生在那个时候,这就是我发布这个解决方案的原因。现在这个问题已经被谷歌解决了。
【解决方案2】:

我也遇到了这个问题,当我将依赖项更改为 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'

【讨论】:

  • 这个解决方案非常适合模拟器
  • 如果您没有Google Play 设置,则意味着您没有使用Google Play 图像。
  • 我必须启动 Google Play 并使用 Google 帐户登录。然后从 Google 商店更新 Google Play 服务。
【解决方案3】:

有点晚了,但我也遇到了这个问题。按照这里的建议更改依赖项对我不起作用。真正起作用的是在模拟器上进入 chrome 并搜索 Google Play 服务。单击指向应用商店的建议链接,它应该会将您带到浏览器中的 Play 商店。点击底部的按钮在模拟器上的应用商店中打开它(因为在play store中搜索它实际上并没有打开它,你必须通过浏览器),希望它能给你提供选项更新 Google Play 服务。之后它对我来说很完美!

【讨论】:

  • 你用的是什么模拟器版本?在 API 19 上,它不包含 Chrome。我尝试用浏览器安装,它说GPS已经存在于模拟器上。之后尝试显示谷歌地图(在我的应用程序中),但它再次显示未安装 GPS 的错误。
【解决方案4】:

检查您正在构建的变体(release/debug)是否已正确签名...

右击模块 => 打开模块设置
Build Types 下检查 Signing Config

api 'com.google.android.gms:play-services-maps:16.1.0'

以上在现实世界中对我来说效果很好 - 但我不使用模拟器。

AS 3.3.2 / Plugin 3.3.2 / Gradle 4.10.2 / compileSdkVersion 28 / buildToolsVersion "28.0.3"

【讨论】:

  • 使用这个 --- implementation 'com.google.android.gms:play-services-maps:16.1.0' ----别忘了在模拟器上更新 google play services。您需要登录才能更新 google play 服务。我有 17.4.55 播放服务及其与 16.1.0 一起使用。
猜你喜欢
  • 1970-01-01
  • 2015-10-30
  • 2017-02-13
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2022-12-06
  • 2017-10-25
  • 2016-09-25
相关资源
最近更新 更多