无法实例化 GoogleApiClient
Cannot instantiate GoogleApiClient
这是我尝试实例化它的代码:
gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
.requestEmail()
.build();
mGoogleApiClient = new GoogleApiClient.Builder(PSSignInFlowActivity.this)
.enableAutoManage(this/* FragmentActivity */, new GoogleApiClient.OnConnectionFailedListener() {
@Override
public void onConnectionFailed(@NonNull ConnectionResult connectionResult) {
}
} /* OnConnectionFailedListener */)
.addApi(Auth.GOOGLE_SIGN_IN_API, gso)
.build();
这是我的 build.gradle:
compile 'com.google.android.gms:play-services-maps:+'
compile 'com.google.android.gms:play-services-location:+'
compile 'com.google.android.gms:play-services-gcm:+'
compile 'com.google.android.gms:play-services-analytics:+'
compile 'com.google.android.gms:play-services-auth:9.0.2'
我收到这个错误:
07-19 11:23:47.668: E/AndroidRuntime(2275): FATAL EXCEPTION: main
07-19 11:23:47.668: E/AndroidRuntime(2275): Process: nl.hgrams.passenger, PID: 2275
07-19 11:23:47.668: E/AndroidRuntime(2275): java.lang.NoSuchMethodError: No virtual method zztw()Ljava/util/Set; in class Lcom/google/android/gms/common/internal/zzg; or its super classes (declaration of 'com.google.android.gms.common.internal.zzg' appears in /data/app/nl.hgrams.passenger-1/base.apk)
07-19 11:23:47.668: E/AndroidRuntime(2275): at com.google.android.gms.auth.api.signin.internal.zzd.<init>(Unknown Source)
07-19 11:23:47.668: E/AndroidRuntime(2275): at com.google.android.gms.auth.api.Auth.zza(Unknown Source)
07-19 11:23:47.668: E/AndroidRuntime(2275): at com.google.android.gms.auth.api.Auth.zza(Unknown Source)
07-19 11:23:47.668: E/AndroidRuntime(2275): at com.google.android.gms.common.api.GoogleApiClient$Builder.zza(Unknown Source)
07-19 11:23:47.668: E/AndroidRuntime(2275): at com.google.android.gms.common.api.GoogleApiClient$Builder.zzaof(Unknown Source)
07-19 11:23:47.668: E/AndroidRuntime(2275): at com.google.android.gms.common.api.GoogleApiClient$Builder.build(Unknown Source)
07-19 11:23:47.668: E/AndroidRuntime(2275): at nl.hgrams.passenger.activities.PSSignInFlowActivity.onCreate(PSSignInFlowActivity.java:75)
07-19 11:23:47.668: E/AndroidRuntime(2275): at android.app.Activity.performCreate(Activity.java:6251)
07-19 11:23:47.668: E/AndroidRuntime(2275): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1107)
07-19 11:23:47.668: E/AndroidRuntime(2275): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2369)
07-19 11:23:47.668: E/AndroidRuntime(2275): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)
07-19 11:23:47.668: E/AndroidRuntime(2275): at android.app.ActivityThread.-wrap11(ActivityThread.java)
07-19 11:23:47.668: E/AndroidRuntime(2275): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)
07-19 11:23:47.668: E/AndroidRuntime(2275): at android.os.Handler.dispatchMessage(Handler.java:102)
07-19 11:23:47.668: E/AndroidRuntime(2275): at android.os.Looper.loop(Looper.java:148)
07-19 11:23:47.668: E/AndroidRuntime(2275): at android.app.ActivityThread.main(ActivityThread.java:5417)
07-19 11:23:47.668: E/AndroidRuntime(2275): at java.lang.reflect.Method.invoke(Native Method)
07-19 11:23:47.668: E/AndroidRuntime(2275): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
07-19 11:23:47.668: E/AndroidRuntime(2275): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
添加编译 'com.google.android.gms:play-services-auth:+' 而不是 9.0.2
看到相似的issue,
将 'com.google.android.gms:play-services-auth:9.0.2'
更改为
'com.google.android.gms:play-services-auth:9.2.0'
会很好用。
这是我尝试实例化它的代码:
gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
.requestEmail()
.build();
mGoogleApiClient = new GoogleApiClient.Builder(PSSignInFlowActivity.this)
.enableAutoManage(this/* FragmentActivity */, new GoogleApiClient.OnConnectionFailedListener() {
@Override
public void onConnectionFailed(@NonNull ConnectionResult connectionResult) {
}
} /* OnConnectionFailedListener */)
.addApi(Auth.GOOGLE_SIGN_IN_API, gso)
.build();
这是我的 build.gradle:
compile 'com.google.android.gms:play-services-maps:+'
compile 'com.google.android.gms:play-services-location:+'
compile 'com.google.android.gms:play-services-gcm:+'
compile 'com.google.android.gms:play-services-analytics:+'
compile 'com.google.android.gms:play-services-auth:9.0.2'
我收到这个错误:
07-19 11:23:47.668: E/AndroidRuntime(2275): FATAL EXCEPTION: main
07-19 11:23:47.668: E/AndroidRuntime(2275): Process: nl.hgrams.passenger, PID: 2275
07-19 11:23:47.668: E/AndroidRuntime(2275): java.lang.NoSuchMethodError: No virtual method zztw()Ljava/util/Set; in class Lcom/google/android/gms/common/internal/zzg; or its super classes (declaration of 'com.google.android.gms.common.internal.zzg' appears in /data/app/nl.hgrams.passenger-1/base.apk)
07-19 11:23:47.668: E/AndroidRuntime(2275): at com.google.android.gms.auth.api.signin.internal.zzd.<init>(Unknown Source)
07-19 11:23:47.668: E/AndroidRuntime(2275): at com.google.android.gms.auth.api.Auth.zza(Unknown Source)
07-19 11:23:47.668: E/AndroidRuntime(2275): at com.google.android.gms.auth.api.Auth.zza(Unknown Source)
07-19 11:23:47.668: E/AndroidRuntime(2275): at com.google.android.gms.common.api.GoogleApiClient$Builder.zza(Unknown Source)
07-19 11:23:47.668: E/AndroidRuntime(2275): at com.google.android.gms.common.api.GoogleApiClient$Builder.zzaof(Unknown Source)
07-19 11:23:47.668: E/AndroidRuntime(2275): at com.google.android.gms.common.api.GoogleApiClient$Builder.build(Unknown Source)
07-19 11:23:47.668: E/AndroidRuntime(2275): at nl.hgrams.passenger.activities.PSSignInFlowActivity.onCreate(PSSignInFlowActivity.java:75)
07-19 11:23:47.668: E/AndroidRuntime(2275): at android.app.Activity.performCreate(Activity.java:6251)
07-19 11:23:47.668: E/AndroidRuntime(2275): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1107)
07-19 11:23:47.668: E/AndroidRuntime(2275): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2369)
07-19 11:23:47.668: E/AndroidRuntime(2275): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)
07-19 11:23:47.668: E/AndroidRuntime(2275): at android.app.ActivityThread.-wrap11(ActivityThread.java)
07-19 11:23:47.668: E/AndroidRuntime(2275): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)
07-19 11:23:47.668: E/AndroidRuntime(2275): at android.os.Handler.dispatchMessage(Handler.java:102)
07-19 11:23:47.668: E/AndroidRuntime(2275): at android.os.Looper.loop(Looper.java:148)
07-19 11:23:47.668: E/AndroidRuntime(2275): at android.app.ActivityThread.main(ActivityThread.java:5417)
07-19 11:23:47.668: E/AndroidRuntime(2275): at java.lang.reflect.Method.invoke(Native Method)
07-19 11:23:47.668: E/AndroidRuntime(2275): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
07-19 11:23:47.668: E/AndroidRuntime(2275): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
添加编译 'com.google.android.gms:play-services-auth:+' 而不是 9.0.2
看到相似的issue,
将 'com.google.android.gms:play-services-auth:9.0.2'
更改为
'com.google.android.gms:play-services-auth:9.2.0'
会很好用。