0

I'm facing an issue while accessing the FirebaseUI. The app crashes as soon as it gets launched. Here's the error message:

   --------- beginning of crash
2022-02-21 14:30:48.404 22932-22932/com.ioteeapp.ArduinoCloud E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.ioteeapp.ArduinoCloud, PID: 22932
    java.lang.NullPointerException: Attempt to invoke interface method 'void com.google.firebase.auth.FirebaseAuth$AuthStateListener.onAuthStateChanged(com.google.firebase.auth.FirebaseAuth)' on a null object reference
        at com.google.firebase.auth.zzk.run(com.google.firebase:firebase-auth@@21.0.1:1)
        at android.os.Handler.handleCallback(Handler.java:938)
        at android.os.Handler.dispatchMessage(Handler.java:99)
        at android.os.Looper.loop(Looper.java:236)
        at android.app.ActivityThread.main(ActivityThread.java:8059)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:656)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:967)
2022-02-21 14:30:48.406 22932-22932/com.ioteeapp.ArduinoCloud E/MQSEventManagerDelegate: failed to get MQSService.
2022-02-21 14:30:48.406 22932-22932/com.ioteeapp.ArduinoCloud D/OOMEventManagerFK: checkEventAndDumpForJE: 0
2022-02-21 14:30:48.407 22932-22932/com.ioteeapp.ArduinoCloud E/MQSEventManagerDelegate: failed to get MQSService.
2022-02-21 14:30:48.409 22932-22989/com.ioteeapp.ArduinoCloud V/FA: Connection attempt already in progress
2022-02-21 14:30:48.409 22932-22989/com.ioteeapp.ArduinoCloud V/FA: Screen exposed for less than 1000 ms. Event not sent. time: 29
2022-02-21 14:30:48.409 22932-22989/com.ioteeapp.ArduinoCloud V/FA: Connection attempt already in progress
2022-02-21 14:30:48.409 22932-22989/com.ioteeapp.ArduinoCloud V/FA: Activity paused, time: 41534759
2022-02-21 14:30:48.422 22932-22932/com.ioteeapp.ArduinoCloud I/Process: Sending signal. PID: 22932 SIG: 9

The AuthStateListener:

authStateListener=new FirebaseAuth.AuthStateListener() {
            @Override
            public void onAuthStateChanged(@NonNull FirebaseAuth firebaseAuth) {
                Log.d(TAG, "onAuthStateChanged: Beginning AuthStateListener");
                FirebaseUser user=firebaseAuth.getCurrentUser();
                String displayName;
                if(user!=null){
                    displayName=user.getDisplayName();
//                    user is singed in
                    for (UserInfo userInfo : user.getProviderData()) {
                        if (displayName == null && userInfo.getDisplayName() != null) {
                            displayName = userInfo.getDisplayName();
                        }
                    }
                    Log.d(TAG, "onAuthStateChanged: userName: "+displayName);
//                    Checking and Requesting all the permission
                    Log.d(TAG, "onAuthStateChanged: Requesting for all permissions");
                        checkAllPermissions(permissions);
//                    onSignedInInitialize(displayName);
                }
                else{
//                    user is signed out
//                    onSignedOutCleanup();
                    startActivityForResult(
                            AuthUI.getInstance()
                                    .createSignInIntentBuilder()
                                    .setIsSmartLockEnabled(false)
                                    .setAvailableProviders(Arrays.asList(
                                            new AuthUI.IdpConfig.GoogleBuilder().build(),
                                            new AuthUI.IdpConfig.EmailBuilder().build()))
                                    .build(),
                            RC_SIGN_IN);
                }
            }
        };

Now, the build.gradle(app): Every imported dependency is been set to its latest version. Compile SDK is been set to 32. I have tried to run with SDK 31 but it is also not working.

plugins {
    id 'com.android.application'
    id 'com.google.gms.google-services'
}

android {
    compileSdk 32
    defaultConfig {
        applicationId "com.ioteeapp.ArduinoCloud"
        minSdk 27
        targetSdk 32
        versionCode 1
        versionName "1.0"

        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
}

dependencies {

    implementation 'androidx.appcompat:appcompat:1.4.1'
    implementation 'com.google.android.material:material:1.5.0'
    implementation 'androidx.constraintlayout:constraintlayout:2.1.3'
    implementation 'com.google.firebase:firebase-database:20.0.3'
    implementation 'com.google.firebase:firebase-auth:21.0.1'
    testImplementation 'junit:junit:4.+'
    androidTestImplementation 'androidx.test.ext:junit:1.1.3'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
    implementation platform('com.google.firebase:firebase-bom:29.0.4')
    implementation 'com.google.firebase:firebase-analytics'
    implementation 'com.firebaseui:firebase-ui-auth:8.0.0'
    implementation 'com.polyak:icon-switch:1.0.0'
}

I hope this information is enough to let you diagnose and find the solution of the issue. Thank You.

Himanshu
  • 11
  • 3
  • 3
    If you encounter problems, it's best to create a [MCVE](https://stackoverflow.com/help/mcve) when posting a question. You posted almost **600 (six hundred)** lines of code for this issue. That's a lot for people to parse and try to debug online. Please edit your question and isolate the problem, in that way you increase your chances of being helped. – Alex Mamo Feb 21 '22 at 09:38

0 Answers0