32

大约一周以来,我一直在努力解决这个问题。一直在搜索类似的主题,但仍然无法解决我的问题。

问题是,当我尝试在 Polar m600 磨损或磨损模拟器(Android V 7.1.1 和 API25)上运行我的程序时,他们给我这条消息“Google Play 服务已过期。需要 11011000 但找到 10289574” .

我遵循了 android 开发者网站中的“获取最后一个已知位置”部分。(网站链接https://developer.android.com/training/location/retrieve-current.html#play-services

这是我正在使用的 Mainactivity 代码

public class MainActivity extends Activity {

private FusedLocationProviderClient mFusedLocationClient;
public Location mLastLocation;
private TextView mTextView;


@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    final WatchViewStub stub = (WatchViewStub) findViewById(R.id.watch_view_stub);
    stub.setOnLayoutInflatedListener(new WatchViewStub.OnLayoutInflatedListener() {
        @Override
        public void onLayoutInflated(WatchViewStub stub) {
            mTextView = (TextView) stub.findViewById(R.id.text);
        }
    });

    mFusedLocationClient = LocationServices.getFusedLocationProviderClient(this);
    if (ActivityCompat.checkSelfPermission(this, android.Manifest.permission.ACCESS_FINE_LOCATION)
            != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, android.Manifest.permission.ACCESS_COARSE_LOCATION)
            != PackageManager.PERMISSION_GRANTED) {
        return;
    }
    mFusedLocationClient.getLastLocation()
            .addOnSuccessListener(this, new OnSuccessListener<Location>() {
                @Override
                public void onSuccess(Location location) {
                    mLastLocation = location;
                    Log.d("Location is:",""+mLastLocation);

                    if (location != null) {

                    }
                }
            });

}
}

这是我的 manifest.xml`

<uses-feature android:name="android.hardware.type.watch" />

<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />

<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:supportsRtl="true"
    android:theme="@android:style/Theme.DeviceDefault">
    <meta-data android:name="com.google.android.gms.version"
        android:value="@integer/google_play_services_version" />
    <activity
        android:name=".MainActivity"
        android:label="@string/app_name">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
</application>

最后但并非最不重要的是我的 build.gradle

android {
compileSdkVersion 25
buildToolsVersion "25.0.2"
defaultConfig {
    applicationId "ims.fhj.at.testnavigators"
    minSdkVersion 21
    targetSdkVersion 25
    versionCode 1
    versionName "1.0"
    multiDexEnabled true
}
buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
     }
  }
 }

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.google.android.support:wearable:2.0.3'
compile 'com.google.android.gms:play-services-wearable:11.0.1'
compile 'com.google.android.gms:play-services:11.0.1'}
4

8 回答 8

62

使用 Android 版本 O - api 26 - x86 或 Android 版本 Nougat - api 24 - x86 创建模拟器 Nexus 5x 连结 5 倍

在此处输入图像描述

然后点击模拟器中的 3 个点,这将打开扩展窗口,点击 Google Play + 更新。这会将 Google Play 服务更新到今天 11.0.55 的最新更新。

在此处输入图像描述

于 2017-07-25T20:20:05.167 回答
2

这里的问题是模拟器和gradle文件上的google play服务(版本)不匹配。

可以通过两种方式解决:

  1. gradle通过将文件中的 google play services (version) 版本降级为模拟器的Google Play Services (version) 来消除不匹配。

  2. 升级模拟器上的Google Play 服务。

于 2017-09-08T12:24:00.883 回答
2

您必须降级可穿戴 gradle 文件中的 API。

问题是您的设备没有最新的 Google Play 服务应用程序。

要修复它,请更改为:

compile 'com.google.android.gms:play-services-wearable:10.0.0'
compile 'com.google.android.gms:play-services:10.0.0'
于 2017-06-16T21:31:54.000 回答
2

我的解决方案非常奇怪:转到设置 -> 应用程序 -> 系统应用程序 -> Google Play 商店 我的版本是 10xxxxx,这很奇怪,因为我的手表在启动时更新了。所以,我点击删除更新,版本更改为 11xxxxxx。

于 2017-08-08T22:55:51.870 回答
1

正如字符串所写,播放服务未在设备上更新。不幸的是,在 WearOS 世界中,Play 服务可能是最新的,但它们在可穿戴设备上根本不可用。在这种情况下,您可以使用以下方法做出反应:

GoogleApiAvailability apiAvailability = GoogleApiAvailability.getInstance();
int result = apiAvailability.isGooglePlayServicesAvailable(this);
if (result != ConnectionResult.SUCCESS) {
    ... 
} else {
     apiAvailability.getErrorDialog(this, result, REQUEST_CODE,this).show();
}
于 2019-02-11T17:18:58.290 回答
0

多年来,这一直是 Wear 存在的问题(例如,请参阅Android Wear Google Play Services)。

最好的解决方案似乎是不使用最新的 Play Services 版本。一种选择是找到似乎涵盖您的目标生产设备的最低版本;在你的情况下,这听起来像是 10.2 范围内的东西。或者,选择包含您需要的所有功能的最低版本(我个人使用的是 9.8.0)。

作为参考,这里是 Play Services 的发布历史:https ://developers.google.com/android/guides/releases

于 2017-06-16T17:21:32.497 回答
0

您必须为您的模拟器使用的图像升级 Google Play 服务和 API。查看这个为我制定的答案(Android Studio 3.1):https ://stackoverflow.com/a/49751932/2292056

于 2019-03-06T23:27:05.243 回答
0

当您传递错误的 web-client-id 值时,有时会发生此错误

val gso = GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
                .requestIdToken(**web-client-id here**)
                .requestEmail()
                .build()

使用指示 Web 客户端的 OAuth 客户端 ID 部分中的值(由 google 服务自动创建)

使用 OAuth 客户端 ID 部分中指示 Web 客户端的值(由 google 服务自动创建

于 2018-12-23T18:27:09.930 回答