Try Sign-In for Android

Use our Android sample app to see how Sign-In works, or add Sign-In to your existing app.

Required: The latest versions of Android Studio and Google Play Services.

Get the project

If this is your first time using a Google services sample, check out the google-services repository.

$ git clone https://github.com/googlesamples/google-services.git

Open Android Studio.

Select File > Open, browse to where you cloned the google-services repository, and open google-services/android/signin.

Configure a Google API project

To use the sample, you need to provide some additional information to finish setting up your project. Click the button below, and specify the package name com.google.samples.quickstart.signin when prompted. You will also need to provide the SHA-1 hash of your signing certificate. See Authenticating Your Client for information.

Configure a project

The sample's IdTokenActivity and ServerAuthCodeActivity examples require you to specify an OAuth 2.0 web client ID. In a real app, this client ID would represent your app's backend server. A client ID for this purpose was created when you configured the project above.

Find this value by opening the Google API Console:

Google API Console

Your web server client ID is displayed next to Web client (Auto-created for Google Sign-in). Copy and paste the client ID into your project's strings.xml file:

<string name="server_client_id">YOUR_SERVER_CLIENT_ID</string>

Run the sample

Now you're ready to build the sample and run it from Android Studio.

Build the sample and click the run button and select a connected device or emulator with Google Play Services 11.8.0 or newer.

How it works

The application builds a GoogleSignInClient, specifying the sign-in options it needs. Then, when the sign-in button is clicked, the application starts the sign-in intent, which prompts the user to sign in with a Google account.

// Configure sign-in to request the user's ID, email address, and basic
// profile. ID and basic profile are included in DEFAULT_SIGN_IN.
GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
        .requestEmail()
        .build();
// Build a GoogleSignInClient with the options specified by gso.
mGoogleSignInClient = GoogleSignIn.getClient(this, gso);
private void signIn() {
    Intent signInIntent = mGoogleSignInClient.getSignInIntent();
    startActivityForResult(signInIntent, RC_SIGN_IN);
}

Next steps

If you want to see how you can implement Google Sign-In in your own app, take a look at our implementation guide.

Add Sign-In to your app

Did you have a good experience? Run into trouble? Let us know!