Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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
}
like image 581
Debashis Nandy Avatar asked Feb 19 '19 16:02

Debashis Nandy


People also ask

Why does Google Play keep saying try again?

You are either signed in with multiple accounts, and one of those is causing the error. Or, you recently changed the password to your Google account and need to relogin with the new credentials. The Play Store error is also caused due to data storage and cache issues on your Android device.

When I try to update Google Play Services it says try again?

All you need to do is a clear the cache for Play Services and Play Store. If the problem continues, then try clearing data for them as well. Rest assured, clearing cache or data will not remove apps or delete data from your phone. However, clearing Play Store data will reset its settings to default.

How do I restart Google Play Services?

Restart Your Device Turning your device off and back on again really can fix most Play Store problems. To restart your Android device: Hold down the power button until the shutdown menu appears. Choose the power down icon.


2 Answers

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:

enter image description here

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'

like image 86
csk Avatar answered Oct 14 '22 14:10

csk


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'
like image 38
Debashis Nandy Avatar answered Oct 14 '22 15:10

Debashis Nandy