哪些Android平台/ API与Google Play服务版本兼容?

时间:2015-08-19 04:11:43

标签: android admob google-play-games

我是Android开发的新手(但不是一般的开发)。在iOS中,文档清楚地说明了特定API可用于哪些版本的iOS SDK。

在Android中我很困惑。 我使用android-10平台,我的minimumSDK和targetSDK都是10.我使用的是Google Play Services 7.5.0。

据我所知,我在android-10中使用的api仍可用于更高版本的android(4.4.4,5.0等)。但我如何知道Google Play Services 7.5.0能否正常运行,Lollipop的所有操作系统版本都能恢复到2.3.3?我没有足够的设备进行测试。

在我的build.grade文件中,我指定了:

dependencies{
....
compile 'com.google.android.gms:play-services:+'
compile 'com.google.android.gms:play-services-ads:7.5.0'
....
}

我不完全理解这些行的含义(我从一些教程中了解了它们)。我如何知道哪些Android OS版本兼容? Build.gradle中的这些行是否正常?

2 个答案:

答案 0 :(得分:6)

compile 'com.google.android.gms:play-services:+'

当您使用加号而不是指定版本时,gradle将自动下载并使用它找到的最新版本的库。建议不要这样做,因为当gradle开始使用新版本时,库版本之间的潜在更改可能会破坏您的代码。最好自己指定一下。例如

compile 'com.google.android.gms:play-services:7.8.0'

这会导入整个playservices库,因此您实际上并不需要第二条play-services-ads:7.5.0行作为其全部就绪导入。

同样由于playservices库如此之大,使用整个东西并不是一个好主意。最好只使用您的应用程序所需的模块。每个部分都可以使用compile '<module>'指定。它将为您节省空间和建立时间。

Google+ com.google.android.gms:play-services-plus:7.5.0
Google Account Login    com.google.android.gms:play-services-identity:7.5.0
Google Actions, Base Client Library com.google.android.gms:play-services-base:7.5.0
Google App Indexing com.google.android.gms:play-services-appindexing:7.5.0
Google App Invites  com.google.android.gms:play-services-appinvite:7.5.0
Google Analytics    com.google.android.gms:play-services-analytics:7.5.0
Google Cast com.google.android.gms:play-services-cast:7.5.0
Google Cloud Messaging  com.google.android.gms:play-services-gcm:7.5.0
Google Drive    com.google.android.gms:play-services-drive:7.5.0
Google Fit  com.google.android.gms:play-services-fitness:7.5.0
Google Location, Activity Recognition, and Places   com.google.android.gms:play-services-location:7.5.0
Google Maps com.google.android.gms:play-services-maps:7.5.0
Google Mobile Ads   com.google.android.gms:play-services-ads:7.5.0
Google Nearby   com.google.android.gms:play-services-nearby:7.5.0
Google Panorama Viewer  com.google.android.gms:play-services-panorama:7.5.0
Google Play Game services   com.google.android.gms:play-services-games:7.5.0
SafetyNet   com.google.android.gms:play-services-safetynet:7.5.0
Google Wallet   com.google.android.gms:play-services-wallet:7.5.0
Android Wear    com.google.android.gms:play-services-wearable:7.5.0

最后要了解哪些级别的playservices兼容,请查看开发人员指南

Overview of Google Play Services

它说这个

  

Google Play服务APK通过Google Play商店提供,因此服务更新不依赖于运营商或OEM系统映像更新。通常,运行Android 2.3(API级别9)或更高版本且安装了Google Play服务应用的设备会在几天内收到更新。这使您可以使用Google Play服务中的最新API并访问Android生态系统中的大多数设备。不支持早于Android 2.3的设备或不支持Google Play服务应用的设备。

答案 1 :(得分:0)

最好在运行时检查设备上Google Play服务的可用性/版本。

根据https://developers.google.com/android/guides/setup

“因为很难预测每台设备的状态,所以在访问Google Play服务功能之前,您必须始终检查兼容的Google Play服务。”

“强烈建议您使用GoogleApiClient课程来访问Google Play服务功能。此方法允许您将OnConnectionFailedListener对象附加到您的客户端。要检测设备是否具有相应版本的Google Play服务APK,请执行onConnectionFailed()回调方法。如果由于Google Play APK的缺失或过时版本导致连接失败,则回调会收到错误代码,例如SERVICE_MISSING,SERVICE_VERSION_UPDATE_REQUIRED或SERVICE_DISABLED。“