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

Which Android platforms / API are compatible with Google Play Services versions?

我是 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 的所有 OS 版本都可以恢复到 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 中的这些行是否正常?

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>' 指定。它将为您节省 space 和构建时间。

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

上面写着

The Google Play services APK is delivered through the Google Play Store, so updates to the services are not dependent on carrier or OEM system image updates. In general, devices running Android 2.3 (API level 9) or later and have the Google Play services app installed receive updates within a few days. This allows you to use the newest APIs in Google Play services and reach most of the devices in the Android ecosystem. Devices older than Android 2.3 or devices without the Google Play services app are not supported.

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

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

"Because it is hard to anticipate the state of each device, you must always check for a compatible Google Play services APK before you access Google Play services features."

"You are strongly encouraged to use the GoogleApiClient class to access Google Play services features. This approach allows you to attach an OnConnectionFailedListener object to your client. To detect if the device has the appropriate version of the Google Play services APK, implement the onConnectionFailed() callback method. If the connection fails due to a missing or out-of-date version of the Google Play APK, the callback receives an error code such as SERVICE_MISSING, SERVICE_VERSION_UPDATE_REQUIRED, or SERVICE_DISABLED."