Awareness API 需要哪个依赖项?

Which dependency is required for Awareness API?

我想看看新的 Awareness API,这是很新的。我正在使用 Play Services 9.0.2。文档有 this example:

GoogleApiClient client = new GoogleApiClient.Builder(context)
        .addApi(Awareness.API)
        .build();
client.connect();

但是,没有提示需要添加哪个依赖项。有什么想法吗?

您需要将 Google Play 服务 的库添加到您的项目中。

Set up Google Play services

To access the Awareness API, your app's development project must include Google Play services. Download and install the Google Play services component via the SDK Manager and add the library to your project. For details, see the Android guide to setting up Google Play services.

Source

我发现了:我需要升级到 PlayServices 9.2.0 并且依赖项隐藏在 play-services-contextmanager 中。只需添加这些依赖项,我们就可以开始了:

compile 'com.google.android.gms:play-services-awareness:10.2.4'

请使用最新的播放服务库,我更新这个答案时是 10.2.4

如果你想知道最新的依赖,你可以使用我的网络工具 DependencyLookup

请记住,此库已添加到 Play Services Repository v31 中。确保您至少在 SDK 管理器中安装了该版本。

设置Google播放服务

要访问 Awareness API,您应用的开发项目必须包含 Google Play 服务。通过 SDK 管理器下载并安装 Google Play 服务组件,并将该库添加到您的项目中。有关详细信息,请参阅 Android 设置指南 Google Play services

这显然与您从 here

获得代码示例的页面相同

大多数情况下,您的应用中的方法引用数超过 65K 限制时,您的应用可能无法编译。因此,为了在编译您的应用时缓解此问题,请仅指定您的应用使用的特定 Google Play 服务 API,而不是所有 API。

compile 'com.google.android.gms:play-services-basement:9.2.0'
compile 'com.google.android.gms:play-services-contextmanager:9.2.0'

您将在这里找到完整的解决方案: http://xordroid.com/create-intelligent-apps-with-google-awareness-api/

启动PlayServices v9.6.0,contextmanager已更改为awareness

因此,之前的答案将不起作用。

从 v10.2.4 开始,正确的依赖项是

compile 'com.google.android.gms:play-services-basement:10.2.0'
compile 'com.google.android.gms:play-services-awareness:10.2.0'