【问题标题】:Android Studio with Google Play: Google Play services is missing带有 Google Play 的 Android Studio:缺少 Google Play 服务
【发布时间】:2014-10-31 10:14:07
【问题描述】:

我使用的是 Ubuntu 14、Android Studio 0.8.6。我正在使用 Genymotion 运行应用程序,我得到的响应是:

W/GooglePlayServicesUtil﹕ Google Play services is missing.

尝试了Import Google Play Services library in Android Studio的解决方案,同样来自Android Studio with Google Play Services。从 Android SDK Manager 安装了以下软件包:Android Support Repository、Android Support Library、Google Play services、Google Repository。

我正在尝试运行 Android Studio 默认活动(地图活动)。这是清单文件:

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

来自 build.gradle 的依赖:

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

默认 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"));
    }
}

我错过了什么,可能是什么问题?非常感谢任何帮助。

谢谢。

【问题讨论】:

    标签: android android-studio google-play google-maps-android-api-2 genymotion


    【解决方案1】:

    找到了解决办法。必须做两件事 - 将 Play Services 版本设置为更低:5.0.89。上一个版本无法从我测试的任何(虚拟)设备下载,需要更新。

    其次,要将 Google Play 服务安装到 Genymotion VM,请按照以下链接中的说明进行操作:How to install Google Play Services in a Genymotion VM (with no drag and drop support)?

    干杯。

    【讨论】:

      【解决方案2】:

      另一种解决方案是将模拟器的目标更改为 Google API

      要在使用 Google Play 服务 SDK 时测试您的应用,您必须使用带有 AVD 的 Android 模拟器,该 AVD 运行基于 Android 4.2.2 或更高版本的 Google API 平台。 Source

      【讨论】:

        【解决方案3】:

        Ojonugwa 的解决方案很好,但另外一个问题是最新版本的 Google Play 服务在模拟器上不可用。但是,在运行 API 版本 21 或 19 的模拟器上可以使用适当版本的 Google Play 服务。

        当前的解决方案是创建一个 API 版本为 21 或 19 的新 AVD,并针对 Google API(不是 Andriod x.x.x)。 如果您使用具有 API 版本 21 或 19 的 Google API AVD,它应该可以正常工作。

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

        【讨论】:

          猜你喜欢
          • 2013-05-13
          • 2016-09-22
          • 1970-01-01
          • 1970-01-01
          • 2012-11-26
          • 1970-01-01
          • 2013-05-31
          • 2016-12-13
          相关资源
          最近更新 更多