13

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
}
Debashis Nandy
  • 545
  • 1
  • 7
  • 17
  • Possible duplicate of [ is having trouble with Google Play services.Please try again. Only on 4.4.X OS devices](https://stackoverflow.com/questions/48579993/your-app-is-having-trouble-with-google-play-services-please-try-again-only-on) – pRaNaY Feb 19 '19 at 17:22
  • I saw that post before posting this question. It's not working for me. – Debashis Nandy Feb 19 '19 at 17:31

4 Answers4

24

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'
Debashis Nandy
  • 545
  • 1
  • 7
  • 17
  • 2
    Yeah same for me, though that doesn't tell us why or how to fix it for 16.1.0. Probably Google will fix it. Maybe we need to wait for new emulator updates. I used Nexus Api 27+28 x86 with google services which both failed on google-services 16.1.0 and worked on 16.0.0 – arberg Feb 21 '19 at 09:56
  • 1
    Thank you! You saved me a lot of time. – maddog Feb 23 '19 at 20:42
  • I tried this on API 19 emulator. With 16.1.0 it showed this error, but with 16.0.0 it wrote: "Google Play Services are updating" forever. Tried on Nox App Player (also API 19), it showed a map. Thanks. – CoolMind May 08 '19 at 07:38
  • Warning, downgrading will crash your app on Android 9, see https://stackoverflow.com/questions/52139199/google-maps-crashing-on-android-pie/52139307! Shame on you, Google! – CoolMind May 08 '19 at 11:22
  • Hey @CoolMind this problem occurred at that time, That's why I posted this solution. Now this problem is fixed by Google. – Debashis Nandy May 08 '19 at 13:17
  • @DebashisNandy, what problem do you mean? "App is having trouble with Google Play Services. Please try again" or Android 9 compatibility? What was fixed? – CoolMind May 08 '19 at 13:20
  • when I was trying to use google map in my app I saw this error https://i.stack.imgur.com/XB5rp.png in my emulator and device that runs in naught. But now using the 16.1.0 it's working fine and it's also working on android pie. – Debashis Nandy May 08 '19 at 13:26
  • @DebashisNandy, 16.1.0 works on Android Pie. But doesn't work on KitKat (4.4). I tested it with AS emulator and Nox emulator. There works 16.0.0. I will test more, and if something changes, will write here. – CoolMind May 08 '19 at 13:29
  • Yea I also noticed this problem. And thank you for informing me about this problem. I will also try to find a solution to this problem. – Debashis Nandy May 08 '19 at 13:58
  • Currently I use 16.0.0 and `` in AndroidManifest as said in that topic. – CoolMind May 08 '19 at 14:34
  • hey I tried this 16.1.0 in all emulator from KitKat(4.4) to pie it works absolutely fine. – Debashis Nandy May 08 '19 at 14:52
  • `Now Google fixes the issue you can use this latest gradle dependency.` Are you sure? Nowadays I had the same issue with `v16.1.0`; downgraded to `v16.0.0` and it solved the problem... – SebasSBM Jun 28 '19 at 09:06
  • In My current project, I have used this dependency and my app works absolutely fine. – Debashis Nandy Jul 02 '19 at 01:49
  • Thank you for sharing your experience with this awesome programming community. I have edited my post. – Debashis Nandy Jul 04 '19 at 01:07
11

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'

csk
  • 188
  • 1
  • 10
0

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!

pianoman102
  • 541
  • 8
  • 22
  • What emulator version did you use? On API 19 it doesn't contain Chrome. I tried to install with a browser, it said that GPS had already existed on the emulator. After that tried to show Google Maps (in my appllication), but it again showed an error that GPS were not installed. – CoolMind May 07 '19 at 13:53
-1

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"

Bad Loser
  • 3,065
  • 1
  • 19
  • 31
  • use this one --- implementation 'com.google.android.gms:play-services-maps:16.1.0' ----Don't forget to update google play services on emulator. You need to login to update google play services. I have 17.4.55 play services and its working with 16.1.0. – Sharad Jun 17 '19 at 01:55