带有 Google Play 的 Android Studio:缺少 Google Play 服务
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/25703145/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Android Studio with Google Play: Google Play services is missing
提问by stubgo
I am using Ubuntu 14, Android Studio 0.8.6. I am using Genymotion for running the app, the response I get, is:
我使用的是 Ubuntu 14,Android Studio 0.8.6。我正在使用 Genymotion 运行应用程序,我得到的响应是:
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.
尝试了在 Android Studio中导入 Google Play 服务库的解决方案,也从带有 Google Play 服务的 Android Studio 中尝试。从 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:
我正在尝试运行 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" />
Dependencies from build.gradle:
来自 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:
默认的 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.
谢谢你。
采纳答案by stubgo
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.
得到了解决方案。必须做两件事 - 将播放服务版本设置为较低:5.0.89。无法从我测试的任何(虚拟)设备下载最新版本,需要更新。
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)?.
其次,要将 Google Play 服务安装到 Genymotion VM,请按照此链接下的说明进行操作:如何在 Genymotion VM 中安装 Google Play 服务(不支持拖放)?.
Cheers.
干杯。
回答by Ojonugwa Jude Ochalifu
Another solution is to change the target of your emulator to the Google API
另一种解决方案是将模拟器的目标更改为 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
要在使用 Google Play 服务 SDK 时测试您的应用程序,您必须使用带有 AVD 的 Android 模拟器,该 AVD 运行基于 Android 4.2.2 或更高版本的 Google API 平台。 来源
回答by KeithP
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.
Ojonugwa 的解决方案很好,但此外还有一个问题是最新版本的 Google Play 服务在模拟器上不可用。但是,在运行 API 版本 21 或 19 的模拟器上可以使用适当版本的 Google Play 服务。
The current solution then is to create a new AVD with an API version of 21 or 19, and target Google APIs ( not Andriod x.x.x ). If you use a Google API AVD with API version 21 or 19 it should work as expected.
当前的解决方案是创建一个 API 版本为 21 或 19 的新 AVD,并针对 Google API(而不是 Andriod xxx)。如果您使用带有 API 版本 21 或 19 的 Google API AVD,它应该可以按预期工作。