简体   繁体   中英

Android Studio with Google Play: Google Play services is missing

I am using Ubuntu 14, Android Studio 0.8.6. I am using Genymotion for running the app, the response I get, is:

W/GooglePlayServicesUtil﹕ Google Play services is missing.

Tried the solution of Import Google Play Services library in Android Studio , also from Android Studio with Google Play Services . Installed the following packages from Android SDK Manager: Android Support Repository, Android Support Library, Google Play services, Google Repository.

I'm trying to run an Android Studio default activity (Map activity). Here is the manifest file:

<application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <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>

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

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

Dependencies from build.gradle:

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

The default MapsActivity.java:

import android.support.v4.app.FragmentActivity;
import android.os.Bundle;

import com.google.android.gms.maps.GoogleMap;
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 {

    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);
        setUpMapIfNeeded();
    }

    @Override
    protected void onResume() {
        super.onResume();
        setUpMapIfNeeded();
    }

    private void setUpMapIfNeeded() {
        // Do a null check to confirm that we have not already instantiated the map.
        if (mMap == null) {
            // Try to obtain the map from the SupportMapFragment.
            mMap = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map))
                    .getMap();
            // Check if we were successful in obtaining the map.
            if (mMap != null) {
                setUpMap();
            }
        }
    }

    private void setUpMap() {
        mMap.addMarker(new MarkerOptions().position(new LatLng(0, 0)).title("Marker"));
    }
}

What am I missing, what can be the problem? Any help much appreciated.

Thank you.

Got a solution. Had to do two things - set the Play Services version to lower: 5.0.89. The last version wasn't available for downloading from any (virtual) device I tested, required update.

Secondly, to install Google Play Services to Genymotion VM, followed instructions under this link: How to install Google Play Services in a Genymotion VM (with no drag and drop support)? .

Cheers.

Another solution is to change the target of your emulator to the Google API

在此输入图像描述

To test your app when using the Google Play services SDK, you must use The Android emulator with an AVD that runs the Google APIs platform based on Android 4.2.2 or higher. Source

Ojonugwa's solution is good but in addition there is an issue with the latest version of Google Play Services not being available on the emulator. However an appropriate version of Google Play Services is available on emulators running API version 21 or 19.

The current solution then is to create a new AVD with an API version of 21 or 19, and target Google APIs ( not Andriod xxx ). If you use a Google API AVD with API version 21 or 19 it should work as expected.

https://github.com/googlesamples/google-services/issues/32

For Linux Users, I solved with these 3 steps:

  1. go to "Home/"your_username"/.android/avd/[your virtual device folder]" and open "config.ini" with text editor, by double-click on it

2)change "PlayStore.enabled=false" to "PlayStore.enabled=true"

3- change "image.sysdir.1 = system-images/android-30/google_apis/x86/"

to

"image.sysdir.1 = system-images/android-30/google_apis_playstore/x86/"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM