Android Login

This tutorial will show you how to integrate Lock v2 in your Android project in order to present a login screen.

Sample Project

Download this sample project configured with your Auth0 API Keys.

System Requirements
  • Android Studio 2.2
  • Android SDK 24
  • Emulator - Nexus 5X - Android 6.0
Show requirements

Add the Lock Dependency

Your first step is to add Lock into your project. Lock is a library for displaying a native UI in your app for logging in and signing up with different platforms via Auth0.

Add Lock with Gradle

Inside the build.gradle dependencies section:

apply plugin: ''
android {
dependencies {
  compile ''   

Then, run Sync Project with Gradle Files inside Android Studio or ./gradlew clean assembleDebug from the command line.

For more information about Gradle usage, check their official documentation.

Configure the Manifest File

Add the following code to your project's AndroidManifest.xml.

        <action android:name="android.intent.action.VIEW" />

        <category android:name="android.intent.category.DEFAULT" />
        <category android:name="android.intent.category.BROWSABLE" />

            android:scheme="https" />

<activity android:name=""/>

Add the following permissions:

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

Do not add <android:noHistory="true"> to the LockActivity as this will alter the correct functionality of Lock.

Implement the Login

At this point, you're all set to implement the login in any activity you want. Inside the activity, add the onCreate, onDestroy, and callback methods.

protected void onCreate(Bundle savedInstanceState) {
    Auth0 auth0 = new Auth0("YOUR_CLIENT_ID", "YOUR_AUTH0_DOMAIN");
    lock = Lock.newBuilder(auth0, callback)
                    // Add parameters to the Lock Builder
protected void onDestroy() {
    // Your own Activity code
    lock = null;
private LockCallback callback = new AuthenticationCallback() {
    public void onAuthentication(Credentials credentials) {
        // Login Success response

    public void onCanceled() {
        // Login Cancelled response

    public void onError(LockException error){
        // Login Error response

Finally, whenever you want to start the login widget, call:

Mobile example screenshot

If you require in-depth configuration, see Lock Builder for more information

There are multiple ways of implementing the login dialog. What you see above is the default widget; however, if you want, you can use your own UI.

Optional: Log In with Social Connections

To have a simple login mechanism through social connections, all you have to do is enable them in your account's dashboard. Every social connection you switch on there, will appear in the login screen of your app.

Previous Tutorial
1. Introduction
Next Tutorial
3. Custom Login
Use Auth0 for FREECreate free Account