3

I'm trying to use the createUserWithEmailAndPassword method to create users but not able to do so. The OnAuthenticate method is being called but user object is null and no user is being created inside firebase console. Here is my code, which is the one available online as well.

MAinActivity.java

private static FirebaseAuth mAuth;
private static FirebaseAuth.AuthStateListener mAuthListener;
private static String TAG = "RegisterDEbug";
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    //setContentView(R.layout.activity_main);
    mAuth = FirebaseAuth.getInstance();
    mAuthListener = new FirebaseAuth.AuthStateListener() {
        @Override
        public void onAuthStateChanged(@NonNull FirebaseAuth firebaseAuth) {
            waitForDebugger();
            FirebaseUser user = firebaseAuth.getCurrentUser();
            if (user != null) {
                // User is signed in
                Log.d(TAG, "onAuthStateChanged:signed_in:" + user.getUid());
            } else {
                // User is signed out
                Log.d(TAG, "onAuthStateChanged:signed_out");
            }
            // ...
        }
    };
    mAuth.addAuthStateListener(mAuthListener);
    mAuth.createUserWithEmailAndPassword("9199999989@pintech.com", "corrfecthorsebatterystaple")
            .addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
                @Override
                public void onComplete(@NonNull Task<AuthResult> task) {
                    waitForDebugger();
                    Log.d(TAG, "Authentication successful");
                    if (!task.isSuccessful()) {
                        //Toast.makeText(this, "Authentication failed.",  Toast.LENGTH_SHORT).show();
                    }
                }
            });
}

app.properties

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:2.1.0'

        classpath 'com.google.gms:google-services:3.0.0'
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        jcenter()
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

app.gradle

apply plugin: 'com.android.application'

android {
    compileSdkVersion 23
    buildToolsVersion "23.0.3"

    defaultConfig {
        applicationId "com.pt.reg"
        minSdkVersion 10
        targetSdkVersion 23
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    testCompile 'junit:junit:4.12'
    compile 'com.android.support:appcompat-v7:23.4.0'
    compile 'com.google.android.gms:play-services:9.0.2'
    //compile 'com.google.android.gms:play-services-auth:9.0.2'

    compile 'com.google.firebase:firebase-core:9.0.2'
    compile 'com.google.firebase:firebase-auth:9.0.2'
}

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

Note - I have tried web solution from firebase for creating a user which works fine.

Neeraj Sewani
  • 3,952
  • 6
  • 38
  • 55
ajay parmar
  • 31
  • 1
  • 1
  • 2

9 Answers9

24

I had this problem too. The password I was testing the app with was just too short. I extended it to a longer password and it worked. You have to meet google's password complexity standards.

Vell
  • 391
  • 2
  • 9
2

I spent 2 days searching for this solution, only to find out it is because of the emulator. Try to use a smartphone to run your app. For me it worked.

de.
  • 7,068
  • 3
  • 40
  • 69
1

I have the same problem.

change:

mAuth.createUserWithEmailAndPassword("9199999989@pintech.com", "corrfecthorsebatterystaple")
            .addOnCompleteListener(this, new OnCompleteListener<AuthResult>()

to:

mAuth.createUserWithEmailAndPassword("9199999989@pintech.com", "corrfecthorsebatterystaple")
            .addOnCompleteListener(MainActivity.this, new OnCompleteListener<AuthResult>()
Yoav
  • 150
  • 3
  • 9
1

For me, the way I solved this issue was firstly to make sure that I had enabled Email/Password signInAuth in firebase

lastly I made sure that the line

mAuth.createUserWithEmailAndPassword(username,password)
                .addOnCompleteListener(**SignUpActivity.this**, task -> { 

... }) had myactivity.this instead of this alone as the context

Sterlingking
  • 190
  • 1
  • 6
0

Enable email/password singn-in method on Firebase console Authentication-->sign-in method:
Authentication-->sign-in method

Dharman
  • 30,962
  • 25
  • 85
  • 135
0

I think the problem is that you might not have added the firebase SDKs in your App.

Add the following implementation inside the dependencies in your module(app-level) Gradle file(app/build.gradle):

dependencies {
       implementation 'com.google.firebase:firebase-auth:19.3.1'
}
Muhammad Dyas Yaskur
  • 6,914
  • 10
  • 48
  • 73
Yash Maheshwari
  • 1,842
  • 2
  • 7
  • 16
0

Just for anyone still looking something that hasn't worked above:

I found that using your activity name before the this keyword in the first parameter of the .addOnCompleteListener works for me.

eg. .addOnCompleteListener(LoginActivity.this, etc..);

Hope this helps anyone still looking, Adam

Harry J
  • 1,842
  • 3
  • 12
  • 28
Adam
  • 1
  • 1
0

I spent 2 full days trying to figure this out and finally observed that my emulator was not connecting to the internet. I entered the DNS server in my Mac's Network preferences and entered 8.8.8.8 and restarted my emulator. IT STARTED WORKING!!

Intstructions I followed: https://medium.com/mobile-app-development-publication/making-android-emulator-connect-to-internet-e7b622a00f09

0

it also happens when you try to pass unapropriate email or dummy text like eg. email = fsjflk;

try adding @gmail.com or something relavent which seems like a valid email address eg. email=fsjflk@gmail.com;

it worked for me i wasted 2 hours for passing dummy text like "fhsjhfk"