Ale*_*sky 2 android google-play-services
我从 Google Play Services 11.0.4 切换到 18.1.1 并在以下代码中收到编译器错误:
public boolean isGooglePlayServicesAvailable()
{
com.google.android.gms.common.GoogleApiAvailability googleApiAvailability = com.google.android.gms.common.GoogleApiAvailability.getInstance();
int resultCode = googleApiAvailability.isGooglePlayServicesAvailable(this);
return resultCode == com.google.android.gms.common.ConnectionResult.SUCCESS;
}
Run Code Online (Sandbox Code Playgroud)
错误信息是:
MainActivity.java:246: error: cannot find symbol
com.google.android.gms.common.GoogleApiAvailability googleApiAvailability = com.google.android.gms.common.GoogleApiAvailability.getInstance();
^
symbol: class GoogleApiAvailability
location: package com.google.android.gms.common
Run Code Online (Sandbox Code Playgroud)
Google Play Services 18.1.1 中是否提供GoogleApiAvailability?
在build.gradle我有这个:
apply plugin: 'com.android.application'
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar', '*.aar'])
implementation 'com.google.android.gms:play-services-ads:18.1.1'
}
Run Code Online (Sandbox Code Playgroud)
编辑1:
有com.google.android.gms.common.GoogleApiAvailabilityLight至少。
小智 7
我遇到了同样的问题。升级后,一些 Google 移动服务 (GMS) 库GoogleApiAvailability类消失了。
看起来谷歌最近已经放松了对 GMS 的依赖。我未能在网络上找到一些有用的信息,因此我决定查看 的源代码GoogleApiAvailability并尝试找出GoogleApiAvailability&之间的区别GoogleApiAvailabilityLight。
在我看来,主要区别如下:GoogleApiAvailabilityLight有助于检查设备上 GMS 服务的可用性,而且GoogleApiAvailability还有助于恢复 GMS 功能(如果损坏或过时)。这种恢复技术似乎知道 GMS 并且需要它们。因此,Google 分成了 2 类:一类用于检查(独立于 GMS),另一类用于检查 + 恢复(依赖于 GMS)。
因为我唯一需要的是检查 GMS 的可用性 - 我替换GoogleApiAvailability为GoogleApiAvailabilityLight就是这样。
希望这可以帮助遇到同样问题的人。
| 归档时间: |
|
| 查看次数: |
1536 次 |
| 最近记录: |