In yourmodule (app-level) Gradle file(usually<project>/<app-module>/build.gradle.ktsor<project>/<app-module>/build.gradle),
add the dependency for theFirebase Authenticationlibrary for Android. We recommend using theFirebase Android BoMto control library versioning.
Also, as part of setting upFirebase Authentication, you need to add the
Credential Manager SDK to your app.
dependencies{// Import theBoMfor the Firebase platformimplementation(platform("com.google.firebase:firebase-bom:34.8.0"))// Add the dependency for theFirebase Authenticationlibrary// When using theBoM, you don't specify versions in Firebase library dependenciesimplementation("com.google.firebase:firebase-auth") // Also add the dependencies for the Credential Manager libraries and specify their versionsimplementation("androidx.credentials:credentials:1.3.0")implementation("androidx.credentials:credentials-play-services-auth:1.3.0")implementation("com.google.android.libraries.identity.googleid:googleid:1.1.1")}
By using theFirebase Android BoM,
your app will always use compatible versions of Firebase Android libraries.
(Alternative)
Add Firebase library dependencies without using theBoM
If you choose not to use theFirebase BoM, you must specify each Firebase library version
in its dependency line.
Note that if you usemultipleFirebase libraries in your app, we strongly
recommend using theBoMto manage library versions, which ensures that all versions are
compatible.
dependencies{// Add the dependency for theFirebase Authenticationlibrary// When NOT using theBoM, you must specify versions in Firebase library dependenciesimplementation("com.google.firebase:firebase-auth:24.0.1") // Also add the dependencies for the Credential Manager libraries and specify their versionsimplementation("androidx.credentials:credentials:1.3.0")implementation("androidx.credentials:credentials-play-services-auth:1.3.0")implementation("com.google.android.libraries.identity.googleid:googleid:1.1.1")}
If you haven't yet specified your app's SHA fingerprint, do so from theSettings pageof theFirebaseconsole. Refer toAuthenticating Your Clientfor details on how to get your app's SHA fingerprint.
Enable Google as a sign-in method in theFirebaseconsole:
On theSign in methodtab, enable theGooglesign-in method
and clickSave.
When prompted in the console, download the updated Firebase config file
(google-services.json), which now contains the OAuth client information
required for Google sign-in.
Move this updated config file into your Android Studio project,replacingthe now-outdated corresponding config file.
(SeeAdd Firebase to your Android project.)
Authenticate with Firebase
Integrate Sign in with Google into your app by following the steps in theCredential Manager documentation. Here are the
high-level instructions:
Instantiate a Google sign in request usingGetGoogleIdOption. Then, create the Credential Manager
request usingGetCredentialRequest:
Kotlin
// Instantiate a Google sign-in requestvalgoogleIdOption=GetGoogleIdOption.Builder()// Your server's client ID, not your Android client ID..setServerClientId(getString(R.string.default_web_client_id))// Only show accounts previously used to sign in..setFilterByAuthorizedAccounts(true).build()// Create the Credential Manager requestvalrequest=GetCredentialRequest.Builder().addCredentialOption(googleIdOption).build()
// Instantiate a Google sign-in requestGetGoogleIdOptiongoogleIdOption=newGetGoogleIdOption.Builder().setFilterByAuthorizedAccounts(true).setServerClientId(getString(R.string.default_web_client_id)).build();// Create the Credential Manager requestGetCredentialRequestrequest=newGetCredentialRequest.Builder().addCredentialOption(googleIdOption).build();
TheWeb applicationtype client ID is your backend
server's OAuth 2.0 client ID.
Check that after you integrate Sign in with Google, your sign-in
activity has code similar to the following:
Kotlin
privatefunhandleSignIn(credential:Credential){// Check if credential is of type Google IDif(credentialisCustomCredential&&credential.type==TYPE_GOOGLE_ID_TOKEN_CREDENTIAL){// Create Google ID TokenvalgoogleIdTokenCredential=GoogleIdTokenCredential.createFrom(credential.data)// Sign in to Firebase with using the tokenfirebaseAuthWithGoogle(googleIdTokenCredential.idToken)}else{Log.w(TAG,"Credential is not of type Google ID!")}}
privatevoidhandleSignIn(Credentialcredential){// Check if credential is of type Google IDif(credentialinstanceofCustomCredentialcustomCredential&&credential.getType().equals(TYPE_GOOGLE_ID_TOKEN_CREDENTIAL)){// Create Google ID TokenBundlecredentialData=customCredential.getData();GoogleIdTokenCredentialgoogleIdTokenCredential=GoogleIdTokenCredential.createFrom(credentialData);// Sign in to Firebase with using the tokenfirebaseAuthWithGoogle(googleIdTokenCredential.getIdToken());}else{Log.w(TAG,"Credential is not of type Google ID!");}}
When initializing your Activity, check to see if the user is currently signed in:
Kotlin
overridefunonStart(){super.onStart()// Check if user is signed in (non-null) and update UI accordingly.valcurrentUser=auth.currentUserupdateUI(currentUser)}
@OverridepublicvoidonStart(){super.onStart();// Check if user is signed in (non-null) and update UI accordingly.FirebaseUsercurrentUser=mAuth.getCurrentUser();updateUI(currentUser);}
Now get the user's Google ID token created in step 1, exchange it for a Firebase credential,
and authenticate with Firebase using the Firebase credential:
Kotlin
privatefunfirebaseAuthWithGoogle(idToken:String){valcredential=GoogleAuthProvider.getCredential(idToken,null)auth.signInWithCredential(credential).addOnCompleteListener(this){task->if(task.isSuccessful){// Sign in success, update UI with the signed-in user's informationLog.d(TAG,"signInWithCredential:success")valuser=auth.currentUserupdateUI(user)}else{// If sign in fails, display a message to the userLog.w(TAG,"signInWithCredential:failure",task.exception)updateUI(null)}}}
privatevoidfirebaseAuthWithGoogle(StringidToken){AuthCredentialcredential=GoogleAuthProvider.getCredential(idToken,null);mAuth.signInWithCredential(credential).addOnCompleteListener(this,task->{if(task.isSuccessful()){// Sign in success, update UI with the signed-in user's informationLog.d(TAG,"signInWithCredential:success");FirebaseUseruser=mAuth.getCurrentUser();updateUI(user);}else{// If sign in fails, display a message to the userLog.w(TAG,"signInWithCredential:failure",task.getException());updateUI(null);}});}
If the call tosignInWithCredentialsucceeds you can use thegetCurrentUsermethod to get the user's account data.
Next steps
After a user signs in for the first time, a new user account is created and
linked to the credentials—that is, the user name and password, phone
number, or auth provider information—the user signed in with. This new
account is stored as part of your Firebase project, and can be used to identify
a user across every app in your project, regardless of how the user signs in.
In your apps, you can get the user's basic profile information from theFirebaseUserobject. SeeManage Users.
In yourFirebase Realtime DatabaseandCloud StorageSecurity Rules, you can
get the signed-in user's unique user ID from theauthvariable,
and use it to control what data a user can access.
To sign out a user, callsignOut. You also need to clear the current user credential
state from all credential providers, as recommended bythe Credential Manager documentation:
Kotlin
privatefunsignOut(){// Firebase sign outauth.signOut()// When a user signs out, clear the current user credential state from all credential providers.lifecycleScope.launch{try{valclearRequest=ClearCredentialStateRequest()credentialManager.clearCredentialState(clearRequest)updateUI(null)}catch(e:ClearCredentialException){Log.e(TAG,"Couldn't clear user credentials:${e.localizedMessage}")}}}
privatevoidsignOut(){// Firebase sign outmAuth.signOut();// When a user signs out, clear the current user credential state from all credential providers.ClearCredentialStateRequestclearRequest=newClearCredentialStateRequest();credentialManager.clearCredentialStateAsync(clearRequest,newCancellationSignal(),Executors.newSingleThreadExecutor(),newCredentialManagerCallback<>(){@OverridepublicvoidonResult(@NonNullVoidresult){updateUI(null);}@OverridepublicvoidonError(@NonNullClearCredentialExceptione){Log.e(TAG,"Couldn't clear user credentials: "+e.getLocalizedMessage());}});}
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2026-01-15 UTC."],[],[]]