android 在使用 `FusedLocationApi` 时在 `LocationServices.API` 和 `Auth.GOOGLE_SIGN_IN_API` 之间发生冲突

android clashed between `LocationServices.API` and `Auth.GOOGLE_SIGN_IN_API` when using `FusedLocationApi`

我有这样的代码 setGoogleSignInAccount

mGoogleApiClient = new GoogleApiClient.Builder(this)
                .enableAutoManage(this /* FragmentActivity */, this /* OnConnectionFailedListener */)
                .addConnectionCallbacks(this)
                .addOnConnectionFailedListener(this)
                .addApi(LocationServices.API)
                .build();

而且我有使用 FusedLocationApi 获取位置的代码,就像这样

Location mLastLocation = LocationServices.FusedLocationApi.getLastLocation(
                            mGoogleApiClient);

它可以工作,但我现在的问题是当我单击注销时出现错误,因为 .addApi(LocationServices.API) 当我更改为 .addApi(Auth.GOOGLE_SIGN_IN_API, gso) 时注销成功,但现在 FusedLocationApi 出现错误

和这个logcat当FusedLocationApi错误

07-17 11:58:16.763 26607-26607/com.emergency.e_place E/AndroidRuntime: FATAL EXCEPTION: main
                                                                       Process: com.emergency.e_place, PID: 26607
                                                                       java.lang.NullPointerException: Appropriate Api was not requested.
                                                                           at com.google.android.gms.common.internal.zzx.zzb(Unknown Source)
                                                                           at com.google.android.gms.common.api.internal.zzj.zza(Unknown Source)
                                                                           at com.google.android.gms.location.LocationServices.zzi(Unknown Source)
                                                                           at com.google.android.gms.location.internal.zzd.getLastLocation(Unknown Source)
                                                                           at com.emergency.e_place.MainActivity.onClick(MainActivity.java:166)
                                                                           at android.view.View.performClick(View.java:4646)
                                                                           at android.view.View$PerformClick.run(View.java:19403)
                                                                           at android.os.Handler.handleCallback(Handler.java:733)
                                                                           at android.os.Handler.dispatchMessage(Handler.java:95)
                                                                           at android.os.Looper.loop(Looper.java:146)
                                                                           at android.app.ActivityThread.main(ActivityThread.java:5511)
                                                                           at java.lang.reflect.Method.invokeNative(Native Method)
                                                                           at java.lang.reflect.Method.invoke(Method.java:515)
                                                                           at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1283)
                                                                           at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1099)
                                                                           at dalvik.system.NativeStart.main(Native Method)

when i changes to .addApi(Auth.GOOGLE_SIGN_IN_API, gso) the logout is success

不要改变。添加。

mGoogleApiClient = new GoogleApiClient.Builder(this)
                .enableAutoManage(this /* FragmentActivity */, this /* OnConnectionFailedListener */)
                .addConnectionCallbacks(this)
                .addOnConnectionFailedListener(this)
                .addApi(LocationServices.API)
                .addApi(Auth.GOOGLE_SIGN_IN_API, gso)
                // Add more APIs, as needed
                .build();