2

I was doing this tutorial on Android and Firebase but for some reason when I try to register a new driver it doesn't interact with Firebase at all. Though it does show it's connected to Firebase:

Communication btwn the App & Firebase

I have downgraded my API to 26 because of this error:

Google Play services out of date. Requires 9256000 but found 9080470.

So I installed Genymotion to solve this issue as advised by contributors on this platform.

But it still doesn't communicate with Firebase. It returns 0 Errors and yet doesn't work.

I've installed GenyMotion but every time I try to run on it's devices it keeps crashing.

public class DriverLoginActivity extends AppCompatActivity {
    private EditText mEmail, mPassword;
    private Button mLogin, mRegistration;

    private FirebaseAuth mAuth;
    private FirebaseAuth.AuthStateListener firebaseAuthListener;
    private static final String TAG = "Test";
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_driver_login);

        mAuth = FirebaseAuth.getInstance();

        firebaseAuthListener = new FirebaseAuth.AuthStateListener() {
            @Override
            public void onAuthStateChanged(@NonNull FirebaseAuth firebaseAuth) {
                FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser();
                if(user!=null){
                    Intent intent = new Intent(DriverLoginActivity.this, 
    MainActivity.class);
                    startActivity(intent);
                    finish();
                    return;
                }
            }
        };

        mEmail = findViewById(R.id.email);
        mPassword = findViewById(R.id.password);


        mLogin = findViewById(R.id.login);
        mRegistration = findViewById(R.id.registration);

        mRegistration.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                final String email = mEmail.getText().toString();
                final String password = mPassword.getText().toString();
                mAuth.createUserWithEmailAndPassword(email, 
    password).addOnCompleteListener(DriverLoginActivity.this, new 
    OnCompleteListener<AuthResult>() {
                    @Override
                    public void onComplete(@NonNull Task<AuthResult> task) {
                        if(!task.isSuccessful()){
                            Toast.makeText(DriverLoginActivity.this, "sign up 
    error", Toast.LENGTH_SHORT).show();
                        }else {
                            String user_id = mAuth.getCurrentUser().getUid();
                            DatabaseReference current_user_db = 
  FirebaseDatabase.getInstance().getReference().child("Users").child("Drivers").child(user_id);
                            current_user_db.setValue(true);
                        }
                    }
                });
            }
        });

        mLogin.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                final String email = mEmail.getText().toString();
                final String password = mPassword.getText().toString();
                mAuth.signInWithEmailAndPassword(email, password).addOnCompleteListener(DriverLoginActivity.this, new OnCompleteListener<AuthResult>() {
                    @Override
                    public void onComplete(@NonNull Task<AuthResult> task) {
                        Log.d(TAG, "createUserWithEmail:onComplete:" + task.isSuccessful());
                        if(!task.isSuccessful()){
                            Log.d(TAG, "onComplete: Failed=" + task.getException().getMessage());
                            Toast.makeText(DriverLoginActivity.this, "sign up error", Toast.LENGTH_SHORT).show();
                        }

                    }
                });

            }
        });
    }

    @Override
    protected void onStart() {
        super.onStart();
        mAuth.addAuthStateListener(firebaseAuthListener);
    }
    @Override
    protected void onStop() {
        super.onStop();
        mAuth.removeAuthStateListener(firebaseAuthListener);
    }
}

Here are my build.gradle (app)

apply plugin: 'com.android.application'

android {
    compileSdkVersion 26
    defaultConfig {
        applicationId "ke.co.wafalmelogistics.wafalme"
        minSdkVersion 17
        targetSdkVersion 26
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    implementation fileTree(include: ['*.jar'], dir: 'libs')
    implementation 'com.android.support:appcompat-v7:26.1.0'
    implementation 'com.android.support.constraint:constraint-layout:1.0.2'
    implementation 'com.google.gms:google-services:3.1.0'
    implementation 'com.google.firebase:firebase-core:11.6.0'
    implementation 'com.google.firebase:firebase-database:11.6.0'
    implementation 'com.google.firebase:firebase-auth:11.6.0'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.1'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
}




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

build.gradle (module)

// Top-level build file where you can add configuration options common to all sub-projects/modules.

    buildscript {

        repositories {
            google()
            jcenter()
        }
        dependencies {
            classpath 'com.android.tools.build:gradle:3.0.0'
            classpath 'com.google.gms:google-services:3.1.0'


            // NOTE: Do not place your application dependencies here; they belong
            // in the individual module build.gradle files
        }
    }

    allprojects {
        repositories {
            google()
            jcenter()
        }
    }

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

And here is the Error I keep getting when I try to run the app on GenyMotion;

--------- beginning of crash
E/AndroidRuntime: FATAL EXCEPTION: main
                  Process: ke.co.wafalmelogistics.wafalme, PID: 1640
                  java.lang.NullPointerException: Attempt to invoke virtual method 'com.google.android.gms.tasks.Task com.google.android.gms.common.api.GoogleApi.zzb(com.google.android.gms.common.api.internal.zzdf)' on a null object reference
                      at com.google.android.gms.internal.zzdtp.zzb(Unknown Source)
                      at com.google.android.gms.internal.zzdtw.zza(Unknown Source)
                      at com.google.firebase.auth.FirebaseAuth.createUserWithEmailAndPassword(Unknown Source)
                      at ke.co.wafalmelogistics.wafalme.DriverLoginActivity$2.onClick(DriverLoginActivity.java:61)
                      at android.view.View.performClick(View.java:5637)
                      at android.view.View$PerformClick.run(View.java:22429)
                      at android.os.Handler.handleCallback(Handler.java:751)
                      at android.os.Handler.dispatchMessage(Handler.java:95)
                      at android.os.Looper.loop(Looper.java:154)
                      at android.app.ActivityThread.main(ActivityThread.java:6119)
                      at java.lang.reflect.Method.invoke(Native Method)
                      at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)
                      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)

ItI am a learner, any help is appreciated.

  • The error points to: `at ke.co.wafalmelogistics.wafalme.DriverLoginActivity$2.onClick(DriverLoginActivity.java:61)` - this means that the error occurs on your `DriverLoginActivity` at line number 61. Which line is this? – Grimthorr Nov 16 '17 at 14:05
  • @Grimthorr: mAuth.createUserWithEmailAndPassword(email, password).addOnCompleteListener(DriverLoginActivity.this, new OnCompleteListener() { – Mfalme Droid Nov 16 '17 at 14:12
  • The error relates to `mAuth` not being initialised (is `null`), which is strange because you have already called `mAuth = FirebaseAuth.getInstance()`, and this cannot be `null`. Can you share your [`build.gradle` files](https://stackoverflow.com/q/28295933/2754146) by editing them into the question please? – Grimthorr Nov 16 '17 at 14:23
  • Delete this line from the dependencies block: `implementation 'com.google.gms:google-services:3.1.0'`. It's a plugin and you are correctly applying it at the bottom of the file. It doesn't belong in the dependencies. – Bob Snyder Nov 17 '17 at 04:24
  • Have u found a solution for this ? – Abdelrhman Talat Jan 09 '18 at 14:29
  • Anyone found a solution for this yet? – casolorz Mar 30 '18 at 15:07

7 Answers7

3

I get the same error because I was use Emulator .. but when I try it in a real device it is working perfectly .. Hope it works for you too..

Mina Samir
  • 1,527
  • 14
  • 15
1

Worked for me using these dependencies:

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.android.support:appcompat-v7:26.1.0'
    implementation 'com.android.support.constraint:constraint-layout:1.0.2'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.1'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
    //NOT DEFAULT BELOW
    compile 'com.firebase:firebase-client-android:2.3.1'
    compile 'com.android.support:design:26.1.0'
    compile 'com.github.rtoshiro.mflibrary:mflibrary:1.0.0'
    compile 'com.google.firebase:firebase-core:11.2.0'
    compile 'com.google.firebase:firebase-database:11.2.0'
    compile 'com.google.firebase:firebase-auth:11.2.0'
}

Thank you for all the help.

Gaspar
  • 1,515
  • 13
  • 20
0

I have the same problem when I use 'com.google.firebase:firebase-auth:11.6.0'

change to 'com.google.firebase:firebase-auth:11.2.0' `

Try this dependencies:

implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:26.1.0'
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
compile 'com.firebase:firebase-client-android:2.3.1'
compile 'com.google.firebase:firebase-database:11.2.0'
compile 'com.google.firebase:firebase-crash:11.2.0'
compile 'com.google.firebase:firebase-auth:11.2.0'
compile 'com.google.firebase:firebase-messaging:11.2.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.1'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
0

had the same issue in my project while running in the emulator but I solved this by using this in Android Studio 3.0.1

app/build.gradle

compile "com.google.firebase:firebase-auth:9.0.2"

build.gradle ( root directory )

classpath 'com.google.gms:google-services:3.0.0'

there setting work for me

0

Looking at https://github.com/firebase/FirebaseUI-Android/issues/1104. I think this is an acknowledged issue in the SDK that would be resolved in the next 1 or 2 SDK updates. A github user called Samstern posts this -

A fix for this bug has been submitted internally, so this should be fixed in the next 1-2 Firebase Auth SDK releases depending on the release cycle.

I am going to close this issue here since there's nothing more FIrebaseUI can do, thanks for everyone who reported it!

Nonetheless, try the following and see if it works. To repeat what Bob Snyder said - Delete this line from the dependencies block: implementation 'com.google.gms:google-services:3.1.0'. Upgrade your firebase to 11.8.0. So your app's build.gradle should look like something like this.

implementation 'com.google.firebase:firebase-core:11.8.0'
implementation 'com.google.firebase:firebase-auth:11.8.0'
implementation 'com.google.firebase:firebase-messaging:11.8.0'
implementation 'com.google.firebase:firebase-storage:11.8.0'
implementation 'com.google.firebase:firebase-database:11.8.0'

Let me know how that goes.

Samuel Agbede
  • 380
  • 1
  • 4
  • 14
0

I solved this by upgrading Google Play Services in the emulator. It was not necessary to change anything in gradle.

Sagar
  • 23,903
  • 4
  • 62
  • 62
0

For me works change from compile:

com.google.firebase:firebase-auth:11.8.0

to compile:

com.google.firebase:firebase-auth:11.2.0
Stephen Rauch
  • 47,830
  • 31
  • 106
  • 135