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

Posted

技术标签:

【中文标题】哪些 Android 平台/API 与 Google Play 服务版本兼容?【英文标题】:Which Android platforms / API are compatible with Google Play Services versions? 【发布时间】:2015-11-12 05:13:11 【问题描述】:

我是 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 等)。但是我怎么知道从 Lollipop 到 2.3.3 的所有操作系统版本都可以使用 Google Play Services 7.5.0 吗?我没有足够的设备进行测试。

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

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

我不完全理解这些行的含义(我从一些教程中遵循了它们)。我如何知道这些将与哪些 Android 操作系统版本兼容? Build.gradle 中的这些行可以吗?

【问题讨论】:

这取决于您在项目中使用了哪个函数。 google 在每个新的 google play services 版本中添加新功能。 但是我怎么知道我使用的功能是否兼容呢? 签出:developers.google.com/android/guides/setup 【参考方案1】:
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 服务应用的设备。

【讨论】:

如果我的 targetSDk 是 android-10,并且我想与所有 android 版本 2.3.3 及更高版本兼容,我如何知道要使用哪个版本(例如 7.5.0)?跨度> 另外,如果我只使用 Admob 和 Google Play 游戏(用于排行榜),我想我只需要两条线 play-services-games 和 play-services-ads 吧? 另外,你没有回答我的问题 - 我怎么知道这与 android-10 / android 2.3.3 兼容? 1.如果您使用 android studio,当有新版本可用时,播放服务将突出显示。 好的。您的更新直到现在才显示,所以我没有看到它。谢谢!【参考方案2】:

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

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

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

“强烈建议您使用 GoogleApiClient 类来访问 Google Play 服务功能。这种方法允许您将 OnConnectionFailedListener 对象附加到您的客户端。要检测设备是否具有适当版本的 Google Play 服务 APK,请实现onConnectionFailed() 回调方法。如果由于缺少或过期的 Google Play APK 版本导致连接失败,回调会收到错误代码,例如 SERVICE_MISSING、SERVICE_VERSION_UPDATE_REQUIRED 或 SERVICE_DISABLED。"

【讨论】:

以上是关于哪些 Android 平台/API 与 Google Play 服务版本兼容?的主要内容,如果未能解决你的问题,请参考以下文章

android 7.0对开发者会都有哪些影响

可以在所有市场上列出的应用程序的跨平台移动 API [关闭]

android 可以用go 语言吗

Android API 和 Http 连接函数

哪些平台的api接口比较好用

详解Android/IOS平台下抓包工具使用以及抓取API接口