我正在將Google Smart Lock應用到應用程序中,並且之前我沒有遇到Api客戶端構建的問題。事實上,我正在完成一些語法修改並清理代碼(甚至沒有觸及初始化Api客戶端的代碼),並且由於abstract method zza
,我的應用現在在Api客戶端構建器上調用build()
時死亡。這裏正在顯示的錯誤:GoogleApiClient構建器無法構建
java.lang.AbstractMethodError: abstract method "com.google.android.gms.common.api.Api$zze com.google.android.gms.common.api.Api$zza.zza(android.content.Context, android.os.Looper, com.google.android.gms.common.internal.zzq, java.lang.Object, com.google.android.gms.common.api.GoogleApiClient$ConnectionCallbacks, com.google.android.gms.common.api.GoogleApiClient$OnConnectionFailedListener)"
at com.google.android.gms.common.api.GoogleApiClient$Builder.build(Unknown Source)
我不知道爲什麼會突然開始失敗了,我找不到我做了會造成這個錯誤的任何變化。爲什麼這種抽象方法沒有被覆蓋?它嵌在圖書館深處,所以我不明白我是如何影響它的。
我在名爲CredentialManager的管理器中封裝了Google Api Client調用。下面是我用來初始化客戶端代碼:
public CredentialManager(ContextProvider contextProvider) {
mContextProvider = contextProvider;
mCredentialsApiClient = new GoogleApiClient.Builder(mContextProvider.getContext())
.addConnectionCallbacks(new GoogleApiClient.ConnectionCallbacks() {
@Override
public void onConnected(@Nullable Bundle bundle) {
Log.i(CredentialManager.TAG, "Api connected");
}
@Override
public void onConnectionSuspended(int i) {
Log.i(CredentialManager.TAG, "Connection suspended with status " + i);
}
})
.enableAutoManage(mContextProvider.getContext(), connectionFailedResult -> {
if (connectionFailedResult.hasResolution()) {
try {
connectionFailedResult.startResolutionForResult(
mContextProvider.getContext(),
CredentialManager.Codes.RESOLVE_CONNECTION_REQUEST_CODE);
} catch (IntentSender.SendIntentException e) {
// Unable to resolve, log error
Log.e(CredentialManager.TAG, "Resolution failed: " + e.getMessage());
}
} else {
//instead of displaying a dialog, just let the user continue and login manually.
Log.e(CredentialManager.TAG, "Connection failed: " + connectionFailedResult.getErrorMessage());
}
})
.addApi(Auth.CREDENTIALS_API)
.build();
}
如果您有任何見解,以什麼原因造成這種錯誤,請讓我知道。我曾經在互聯網上搜索過曾經見過類似內容的人,但找不到任何東西。