androidkotlingoogle-apigoogle-play-servicesgoogle-identity

How to use the Google Identity Credentials library?


I'm trying to use this relatively new :play-services-identity-credentials library (release notes):

implementation("com.google.android.gms:play-services-identity-credentials:16.0.0-alpha03")
implementation("androidx.work:work-runtime:2.9.1") // required, else it doesn't work at all.

But whatever I try with that IdentityCredentialClient, this is the default result; thrown by com.google.android.gms.identitycredentials.internal.IIdentityCredentialCallbacks:

com.google.android.gms.common.api.ApiException: 17: 
    at com.google.android.gms.common.internal.ApiExceptionUtil.fromStatus(com.google.android.gms:play-services-base@@18.4.0:3)
    at com.google.android.gms.common.api.internal.TaskUtil.setResultOrApiException(com.google.android.gms:play-services-base@@18.4.0:4)
    at com.google.android.gms.identitycredentials.internal.InternalIdentityCredentialClient$registerCredentials$1$callback$1.onRegisterCredentials(com.google.android.gms:play-services-identity-credentials@@16.0.0-alpha03:1)
    at com.google.android.gms.identitycredentials.internal.IIdentityCredentialCallbacks$Stub.dispatchTransaction(com.google.android.gms:play-services-identity-credentials@@16.0.0-alpha03:16)
    at com.google.android.gms.internal.identity_credentials.zzb.onTransact(com.google.android.gms:play-services-identity-credentials@@16.0.0-alpha03:2)
    at android.os.Binder.execTransactInternal(Binder.java:1505)
    at android.os.Binder.execTransact(Binder.java:1444)

While 17 generally means CommonStatusCodes.API_NOT_CONNECTED:

The client attempted to call a method from an API that failed to connect.

The code which produces this ApiException is available on GitHub. Adding google-services.json did not solve the problem. On the console there's only an "Identity Toolkit API" available. So how can I enable and/or even connect that Identity Credentials API?


Solution

  • This also needs credentials-play-services-auth, which even depends on it.

    implementation("com.google.android.gms:play-services-identity-credentials:16.0.0-alpha03")
    
    // required, else it doesn't work at all.
    implementation("androidx.work:work-runtime:2.9.1")
    
    // required, else it will throw ApiException 17.
    implementation("androidx.credentials:credentials-play-services-auth:1.5.0-alpha05")