App is having trouble with Google Play Services. Please try again

佐手、 提交于 2019-12-19 05:17:11

问题


I have done this code several times. But from today morning i see this problem occurs. This is a basic code to show a map layout. And showing this error to me. And also I entered the API key correctly.Screen Shot of EmulatorI searched for other StackOverflow posts but nothing workes for me.

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 file:-

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

App level 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'
}

Project level 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
}

回答1:


I solved this problem.

By changing app level gradle dependencies

from this

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

to this

implementation 'com.google.android.gms:play-services-maps:16.0.0'

Update:

Now i can use this latest gradle dependency. It works fine for me.

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



回答2:


I also had this problem and when I changed the dependencies to implementation 'com.google.android.gms:play-services-maps:16.0.0' the map was not loading.

So I updated Google Play Services on my emulator:

After that, I had to sign in to access the Play Store and then I could update Google Play Services.

Finally, I let the dependency as implementation 'com.google.android.gms:play-services-maps:16.1.0'




回答3:


A little late, but I have been having this issue as well. Changing the dependencies as has been suggested here hasn't worked for me. What did work was actually going into chrome on the emulator and searching for Google Play Services. Click on the suggested link to the app store for it and it should take you to the Play Store in the browser. Click on the button at the bottom to open it in the app store on the emulator (because searching for it in the play store doesn't actually bring it up, you have to go through a browser), and hopefully it gives you the option to update Google Play Services. It worked perfect for me after that!




回答4:


Check that the variant (release/debug) that you are building is properly signed...

Right-click module => Open Module settings
Under Build Types check Signing Config

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

Above works fine for me in real world - but I don't use the emulator.

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



来源:https://stackoverflow.com/questions/54771375/app-is-having-trouble-with-google-play-services-please-try-again

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!