0

I have this mistake when I try to run my application: "this app won't run unless you update google play services"

I have tried many things that are here, but nothing. I've generated the application with the assistance of Android Studio. I have download the rev 22 to Google Play Services and rev 12 of Google Play services for Froyo My proyect is Api 17 and when I run the project in the phone, it's display ok.

Manifest

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.googlemaps.googlemaps" >

    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />


    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <meta-data
            android:name="com.google.android.gms.version"
            android:value="@integer/google_play_services_version" />
        <meta-data
            android:name="com.google.android.maps.v2.API_KEY"
            android:value="@string/google_maps_key" />

        <activity
            android:name=".MapsActivity"
            android:label="@string/title_activity_maps" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>

MainActivity

package com.example.googlemaps.googlemaps;

import android.app.Dialog;
import android.location.Location;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;


import com.google.android.gms.common.ConnectionResult;
import com.google.android.gms.common.GooglePlayServicesUtil;
import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.GoogleMap.OnMyLocationChangeListener;
import com.google.android.gms.maps.SupportMapFragment;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.MarkerOptions;

public class MapsActivity extends FragmentActivity implements OnMyLocationChangeListener {

    private GoogleMap mMap; // Might be null if Google Play services APK is not available.

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_maps);
        int status = GooglePlayServicesUtil.isGooglePlayServicesAvailable(getBaseContext());
        if(status!=ConnectionResult.SUCCESS){
            int requestCode=10;
            Dialog dialog=GooglePlayServicesUtil.getErrorDialog(status, this, requestCode);
                 dialog.show();
             }
             else{
                 SupportMapFragment fm=(SupportMapFragment)getSupportFragmentManager().findFragmentById(R.id.map);
                 mMap=fm.getMap();
                 mMap.setMyLocationEnabled(true);
                 mMap.setOnMyLocationChangeListener(this);
             }


    }

    @Override
    public void onMyLocationChange(Location location) {
        // TODO Auto-generated method stub
        // TextView tvLocation=(TextView)findViewById(R.id.textView1);
        double latitude=location.getLatitude();
        double longitude=location.getLongitude();
        LatLng latLng=new LatLng(latitude,longitude);
        mMap.moveCamera(CameraUpdateFactory.newLatLng(latLng));
        mMap.animateCamera(CameraUpdateFactory.zoomTo(15));
        // tvLocation.setText("Latitude:"+latitude+", Longitude:"+longitude);
    }
}
Simpson
  • 593
  • 5
  • 20
  • So what is the problem? You mentioned that if you run the application on your phone, it displays okay. Google play services are not supported by some older apis and android emulators, please check the requirements first. See if that helps. – so_jin_ee Jan 28 '15 at 17:23
  • Hi, Because I want to display in the emulator too. The API version is 17 (4.4.2) – Simpson Jan 28 '15 at 17:57
  • Try the answers written here: [**Link**](http://stackoverflow.com/questions/22141043/google-play-services-missing-in-emulator-android-4-4-2) – so_jin_ee Jan 28 '15 at 18:07

2 Answers2

2

The error you are getting is because you are not running the updated version of Google Play Services that is 6.5. Make sure you have added that in your build.gradle file as dependencies. Add the following lines.

dependencies {
    compile 'com.android.support:appcompat-v7:21.0.3'
    compile 'com.google.android.gms:play-services:6.5.87'
}

If you are using your app just for maps you can selectively add:

com.google.android.gms:play-services-maps:6.5.87

Please refer to this documentation for more details.

Assuming that you have replaced the API_KEY in your manifest file with your actual API key, you should be able to see the maps running on your app without getting any error.

For more details read official documentation on Google Play Services 6.5.

AniV
  • 3,997
  • 1
  • 12
  • 17
0

Good news for you. Google now provides a standalone library for maps which, at the time of writing this post, is in beta

The Maps SDK for Android is now distributed via a standalone static library. Previously, the Maps SDK for Android was made available as part of Google Play services

https://developers.google.com/maps/documentation/android-sdk/v3-client-migration

Peter Chaula
  • 3,456
  • 2
  • 28
  • 32
  • sorry I am a beginner in Android Development, so what is the benefit of using this standalone static library ? so I don't need to check if user has google play services or not ? and to make it faster when launching mapview ? like the problem in here: https://stackoverflow.com/questions/26178212/first-launch-of-activity-with-google-maps-is-very-slow ? – Alexa289 Apr 20 '20 at 06:09