createUserWithEmailAndPassword doesn't work for me

3,514 views
Skip to first unread message

chen...@gmail.com

unread,
Sep 14, 2016, 9:13:56 PM9/14/16
to Firebase Google Group
I'm working on Register function by using createUserWithEmailAndPassword  in Android Studio. But I can't make it work. 

What I have done:

1. Download and paste google-services.json under app folder
2. Modify build.gradle and app.gradle according to tutorial
3. Enable Email Sign-In Method from my Firebase console
4. Then I created a RegisterActivity activity:

import android.app.ProgressDialog;
import android.content.Intent;
import android.provider.ContactsContract;
import android.support.annotation.NonNull;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.text.TextUtils;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ProgressBar;
import android.widget.TextView;

import com.firebase.client.Firebase;
import com.google.android.gms.tasks.OnCompleteListener;
import com.google.android.gms.tasks.Task;
import com.google.firebase.auth.AuthResult;
import com.google.firebase.auth.FirebaseAuth;
import com.google.firebase.database.DatabaseReference;
import com.google.firebase.database.FirebaseDatabase;

public class RegisterActivity extends AppCompatActivity {

    private static final String TAG = "chen";
    private EditText mNameField;
    private EditText mEmailField;
    private EditText mPasswordField;

    private FirebaseAuth mAuth;
    private DatabaseReference mDatabase;


    private ProgressDialog mProgress;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_register);

        mAuth = FirebaseAuth.getInstance();
        mDatabase = FirebaseDatabase.getInstance().getReference().child("Users");
        mDatabase.keepSynced(true);

        mProgress = new ProgressDialog(this);

        mNameField = (EditText)findViewById(R.id.nameField);
        mEmailField = (EditText)findViewById(R.id.emailField);
        mPasswordField = (EditText)findViewById(R.id.passwordField);
        Button mRegisterBtn = (Button) findViewById(R.id.registerBtn);

        mRegisterBtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                startRegister();
            }
        });

    }

    private void startRegister() {
        final String name = mNameField.getText().toString().trim();
        String email = mEmailField.getText().toString().trim();
        String password = mPasswordField.getText().toString().trim();

        if(!TextUtils.isEmpty(name) && !TextUtils.isEmpty(email) && !TextUtils.isEmpty(password)) {

            mProgress.setMessage("Signing Up ...");
            mProgress.show();

            mAuth.createUserWithEmailAndPassword(email, password).addOnCompleteListener(new OnCompleteListener<AuthResult>() {
                @Override
                public void onComplete(@NonNull Task<AuthResult> task) {

                    if(task.isSuccessful()){

                        String user_id = mAuth.getCurrentUser().getUid();
                        DatabaseReference current_user_db = mDatabase.child(user_id);
                        current_user_db.child("name").setValue(name);
                        current_user_db.child("image").setValue("default");

                        mProgress.dismiss();

                        Intent mainIntent = new Intent(RegisterActivity.this, MainActivity.class);
                        mainIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                        startActivity(mainIntent);

                    }
                }
            });

        }
    }
}


Unfortunately this doesn't work for me. I can't add any new User to Firebase Auth.
Have googled a lot with different solutions, still no luck.

Hope anyone here can help me out.

Thanks in advance!

Kind regards,
Chen

Kato Richardson

unread,
Sep 16, 2016, 1:19:15 AM9/16/16
to Firebase Google Group
Hi Chen,

Can you try logging the error in the case that the create task is not successful? Also, is this really the minimum code needed to reproduce your issue? Would be great to see if you can recreate it with some hard coded values (cutting out the possibility that the inputs are a culprit). What version of the SDK are we working with?

☼, Kato

--
You received this message because you are subscribed to the Google Groups "Firebase Google Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to firebase-talk+unsubscribe@googlegroups.com.
To post to this group, send email to fireba...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/firebase-talk/159e3202-cd92-48e9-991b-3cd83589835a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--

Kato Richardson | Developer Programs Eng | kato...@google.com | 775-235-8398

chen...@gmail.com

unread,
Sep 16, 2016, 8:00:49 PM9/16/16
to Firebase Google Group
Hi Kato,

Thanks for your reply. Finally I find the reason after struggled with this issue more than 3 days!,......
I googled almost everything relate to firebase/createUserWithEmailAndPassword/Auth/Rules/ etc. No any answer has been found the same as my case. 
Here I share it to people who has the similar problem:

If your createUserWithEmailAndPassword doesn't do anything, Instead of spend lots of time doing:

denpendency version (sb. says 9.2.0 / 9.0.2 / 9.4.0 etc...) / google-services.json / Sign-In method / Rules / Google play store ... / length of password .... /

I suggest you first check your emulator... Are you using any virtual device? then stop using it. Try to build your app to be an apk file, install it in your physical device or directly connect your physical device via Android Studio to set it as your simulator.  

Then you will see createUserWithEmailAndPassword works perfectly.

Hope this will help others :)
To unsubscribe from this group and stop receiving emails from it, send an email to firebase-tal...@googlegroups.com.

To post to this group, send email to fireba...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/firebase-talk/159e3202-cd92-48e9-991b-3cd83589835a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Kato Richardson

unread,
Sep 16, 2016, 11:14:55 PM9/16/16
to Firebase Google Group

Hi Chen,

I couldn't come up with any reason that the emulator could matter here. Seems like the promise would fail with an error or there would be one in the console.

If you feel otherwise, is love to see a minimal repro, console logs, and info about your specific emulator version, including Google Play version.

Kato


To unsubscribe from this group and stop receiving emails from it, send an email to firebase-talk+unsubscribe@googlegroups.com.

To post to this group, send email to fireba...@googlegroups.com.

chen...@gmail.com

unread,
Sep 17, 2016, 12:24:22 PM9/17/16
to Firebase Google Group
Hi Kato,

i have denpendencies:

a) In build.gradle I added dependencies: dependencies { 
classpath 'com.android.tools.build:gradle:2.1.2' 
classpath 'com.google.gms:google-services:3.0.0' 

b) In app.gradle I added: dependencies { 
compile fileTree(dir: 'libs', include: ['*.jar']) 
testCompile 'junit:junit:4.12' 
compile 'com.android.support:appcompat-v7:24.2.0' 
compile 'com.google.firebase:firebase-core:9.0.2' 
compile 'com.google.firebase:firebase-database:9.0.2' 
compile 'com.google.firebase:firebase-crash:9.0.2' 
compile 'com.google.firebase:firebase-auth:9.0.2' 

apply plugin: 'com.google.gms.google-services' 

I have also tried 9.4.0 and 9.2.0, didn't work.

That's true in my log always see issue related to Google Play 

I used Genymotion 2.7.2 free version (personal use), no google play store there. Maybe this caused the issue.

console log if i run app in genymotion, Samsung galaxy S3, 4.3 API18:
09-17 02:18:41.092 1287-1306/com.fili.chen I/FA: This instance being marked as an uploader
09-17 02:18:50.516 1287-1306/com.fili.chen I/FA: Tag Manager is not found and thus will not be used
09-17 02:19:01.724 1287-1293/com.fili.chen D/dalvikvm: GC_FOR_ALLOC freed 1229K, 22% free 5343K/6772K, paused 7ms, total 8ms
09-17 02:19:41.504 1287-1287/com.fili.chen I/Choreographer: Skipped 56 frames!  The application may be doing too much work on its main thread.
09-17 02:19:46.000 1287-1287/com.fili.chen D/chen: createUserWithEmail:onComplete:
09-17 02:19:46.020 1287-1287/com.fili.chen D/dalvikvm: GC_FOR_ALLOC freed 179K, 19% free 5505K/6772K, paused 6ms, total 6ms
09-17 02:19:46.020 1287-1287/com.fili.chen I/dalvikvm-heap: Grow heap (frag case) to 6.645MB for 1127532-byte allocation
09-17 02:19:46.020 1287-1296/com.fili.chen D/dalvikvm: GC_FOR_ALLOC freed <1K, 17% free 6606K/7876K, paused 5ms, total 5ms
09-17 02:19:46.044 1287-1301/com.fili.chen W/DynamiteModule: Local module descriptor class for com.google.firebase.auth not found.
09-17 02:19:46.044 1287-1301/com.fili.chen W/GooglePlayServicesUtil: Google Play Store is missing.
09-17 02:19:46.064 1287-1287/com.fili.chen W/EGL_genymotion: eglSurfaceAttrib not implemented

KInd regards,
Chen
Reply all
Reply to author
Forward
0 new messages