9
  • I'm trying to build an app with login/register capabilities through Firebase. I'm working on it with a partner (he's on Linux, I'm on Mac), and he's able to get the authentication working but for some reason I am not. We have all the same code, SDK tools checked in the SDK manager, running the same version of everything.
  • Here's the gradle file:

    
    compile 'com.android.support:appcompat-v7:25.3.0'
    compile 'com.android.support.constraint:constraint-layout:1.0.2'
    compile 'com.google.firebase:firebase-auth:10.2.1'
    compile 'com.android.support:design:25.3.0'
    testCompile 'junit:junit:4.12' 
    
  • And the code:



    public class RegisterActivity extends AppCompatActivity {
    private FirebaseAuth mAuth;
    private FirebaseAuth.AuthStateListener mAuthListener;

    private EditText mUsernameField;
    private EditText mPasswordField;
    private EditText mConfirmPasswordField;

    private Button mRegisterButton;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_register);
        Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);

        mUsernameField = (EditText) findViewById(R.id.enterUsername);
        mPasswordField = (EditText) findViewById(R.id.enterPassword);
        mConfirmPasswordField = (EditText) findViewById(R.id.confirmPassword);
        mRegisterButton = (Button) findViewById(R.id.confirmRegistration);

        mRegisterButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                createAccount(mUsernameField.getText().toString(), mPasswordField.getText().toString());
            }
        });
        mAuth = FirebaseAuth.getInstance();

        mAuthListener = new FirebaseAuth.AuthStateListener() {
            @Override
            public void onAuthStateChanged(@NonNull FirebaseAuth firebaseAuth) {
                FirebaseUser user = firebaseAuth.getCurrentUser();
                if (user != null) {
                    // User is signed in
                    Log.d("account", "onAuthStateChanged:signed_in:" + user.getUid());
                } else {
                    // User is signed out
                    Log.d("account", "onAuthStateChanged:signed_out");
                }
                // ...
            }
        };
    }

    @Override
    public void onStart() {
        super.onStart();
        mAuth.addAuthStateListener(mAuthListener);
    }

    @Override
    public void onStop() {
        super.onStop();
        if (mAuthListener != null) {
            mAuth.removeAuthStateListener(mAuthListener);
        }
    }

    private void createAccount(String email, String password) {
        Log.d("account", "createAccount:" + email);
        if (!validateForm()) {
            return;
        }

        // [START create_user_with_email]
        mAuth.createUserWithEmailAndPassword(email, password)
                .addOnCompleteListener(this, new OnCompleteListener() {
                    @Override
                    public void onComplete(@NonNull Task task) {
                        Log.d("account", "createUserWithEmail:onComplete:" + task.isSuccessful());

                        // If sign in fails, display a message to the user. If sign in succeeds
                        // the auth state listener will be notified and logic to handle the
                        // signed in user can be handled in the listener.
                        if (!task.isSuccessful()) {
                            Toast.makeText(RegisterActivity.this, R.string.register_failed,
                                    Toast.LENGTH_SHORT).show();
                        }

                        else {
                            Intent intent = new Intent(RegisterActivity.this, MainActivity.class);
                            RegisterActivity.this.startActivity(intent);
                            finish();
                        }
                    }
                });
        // [END create_user_with_email]
    }

    private boolean validateForm() {
        boolean valid = true;

        String email = mUsernameField.getText().toString();
        if (TextUtils.isEmpty(email)) {
            mUsernameField.setError("Required.");
            valid = false;
        } else {
            mUsernameField.setError(null);
        }

        String password = mPasswordField.getText().toString();
        if (TextUtils.isEmpty(password)) {
            mPasswordField.setError("Required.");
            valid = false;
        } else {
            mPasswordField.setError(null);
        }

        String confirmPassword = mConfirmPasswordField.getText().toString();
        if (TextUtils.isEmpty(confirmPassword)) {
            mConfirmPasswordField.setError("Required.");
            valid = false;
        } else {
            mConfirmPasswordField.setError(null);
        }

        if(!confirmPassword.equals(password)) {
            mConfirmPasswordField.setError("Passwords must be the same.");
            valid = false;
        }

        return valid;
    }

}

 
  • And finally the error:

W/DynamiteModule: Local module descriptor class for com.google.firebase.auth not found.
W/GooglePlayServicesUtil: Google Play Store is missing.
I/art: Background partial concurrent mark sweep GC freed 5866(313KB) AllocSpace objects, 1(14KB) LOS objects, 39% free, 2MB/4MB, paused 5.176ms total 27.761ms
D/account: createUserWithEmail:onComplete:false 
  • Pretty much everything was taken textbook from the Firebase website. Please help, we've been stuck on this for hours, and none of the other similar questions have helped.
John Doe
  • 91
  • 1
  • 1
  • 2

5 Answers5

6

Option 1: Go to Firebase Console < Authentication < SIGN-IN METHOD, and see if you are using it in the Anonymous state. If you are, disable that and enable Email/Password or whichever login method you are using.

Option 2: Check if the device you are testing with is running Google Play Services 9.0.0 or later.

6

Add a log in onComplete() listener of createUserWithEmailAndPassword() to see what exactly is the reason behind the failure.

   if (!task.isSuccessful()) {
    Log.e(TAG, "onComplete: Failed=" + task.getException().getMessage()); 
    }

This can be due to the password or email you entered to create an account. Check:

  • if the email you entered is in proper format and does exist.
  • if password is strong enough to be accepted (usually not less than 6 letters).
  • if there is already an account with the same email.
Niraj Niroula
  • 2,376
  • 1
  • 17
  • 36
3

In my case, I was debugging the application and was missing the SHA1 Key in my firebase project configuration. If you are debugging make sure you have your SHA1 Key in place.

Jawand Singh
  • 1,929
  • 1
  • 24
  • 21
1

Can you check your Google Play Services version?

Prerequisites :

  • An Android device running Google Play services 9.0.0 or later
  • The Google Play services SDK from the Android SDK Manager
  • Android Studio 1.5 or higher
  • An Android Studio project and its package name.

One of the reason for this problem could be, your Sign In Method inside Firebase > Auth Dashboard might be disabled.

EDIT

The 10.2.1 version wasn't available for downloading from any (virtual) device that you tested, required update.

The version of Google Play Services shown in the Extras section at the bottom of the Standalone SDK Manager has no effect on the version used by an emulator. The emulators run on system images configured to contain some particular version of Play Services, which is not always the same.

You should confirm that you have downloaded the latest emulator images having version compatibility like version 10.2.1(latest).

Abhishek Aryan
  • 19,936
  • 8
  • 46
  • 65
  • I'm running it on an emulator for the Nexus 7 API 22 (Android 5.1.1, API 22). My Google Play services SDK is installed with a version of 39, Android Studio is 2.3.1, the Sign In method is authorized for email which is what I have been trying. – John Doe Apr 15 '17 at 15:59
  • @Aryan do you have the link to the documentation which states that it's compulsory to have google play services of version 9 and above to get it to work? I'm using a device with version "8.3.01 (2385995-434) " and apparently it's not working: https://stackoverflow.com/questions/53370161/sms-authentication-on-android-nullpointerexception – user1872384 Nov 30 '18 at 06:30
  • @user1872384 I don't have any reference link right now because post is somehow old, why you want to stick to older version ?? – Abhishek Aryan Nov 30 '18 at 07:02
  • To support more devices with older version of google play services. (e.g. grandma without any knowledge of how to update google play services, to be able to use our app) – user1872384 Nov 30 '18 at 07:21
  • What is controlling the minimum version of google play services needed to run your app by the way? – user1872384 Nov 30 '18 at 07:23
  • controlling the minimum version ?? – Abhishek Aryan Nov 30 '18 at 11:42
1

Same thing happened with me because I was using old auth version as you can see the old one is mentioned and commented out and the new one is at the bottom inside dependencies.

enter image description here

So always try to follow dependencies that are mentioned here

TAHA SULTAN TEMURI
  • 4,031
  • 2
  • 40
  • 66