0

I followed the code guided on the Firebase Android Studio tutorial on YouTube, https://www.youtube.com/watch?v=tJVBXCNtUuk

However, when I try to run the (almost) same code on my Android Studio, soon after pressing the "Login" button, the app abruptly stops working.

Here is the java code for my Login Activity: LoginActivity.java

package com.example.user.compounderapp;

import android.app.ProgressDialog;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;

import android.content.Intent;
import android.view.View;
import android.widget.Button;
//import android.widget.CompoundButton;
import android.widget.EditText;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.RadioGroup.OnCheckedChangeListener;

import android.widget.TextView;
import android.widget.Toast;

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 butterknife.ButterKnife;
import butterknife.InjectView;

public class LoginActivity extends AppCompatActivity implements View.OnClickListener {
    private static final String TAG = "LoginActivity";
    private static final int REQUEST_SIGNUP = 0;
    private boolean checked = false;
    private boolean patientChecked = false;
    private boolean doctorChecked = false;
    private boolean adminChecked = false;
    //private RadioGroup radioGroupLogin;
    private FirebaseAuth firebaseAuth;
    private ProgressDialog progressDialog;

    @InjectView(R.id.input_email) EditText _emailText;
    @InjectView(R.id.input_password) EditText _passwordText;
    @InjectView(R.id.btn_login) Button _loginButton;
    @InjectView(R.id.btnToSignup) Button _btnToSignup;
    //@InjectView(R.id.link_signup) TextView _signupLink;
    @InjectView(R.id.loginRadioGroup) RadioGroup radioGroupLogin;
    @InjectView(R.id.radioButtonPatient) RadioButton radioPatient;
    @InjectView(R.id.radioButtonDoctor) RadioButton radioDoctor;
    @InjectView(R.id.radioButtonAdmin) RadioButton radioAdmin;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_login);
        ButterKnife.inject(this);

        firebaseAuth = FirebaseAuth.getInstance();
        /*
        if(firebaseAuth.getCurrentUser()!=null)
        {
            startActivity(new Intent(this, P2.class));
        }
        */

        radioGroupLogin.setOnCheckedChangeListener(new OnCheckedChangeListener() {

            @Override
            public void onCheckedChanged(RadioGroup radioGroupLogin, int checkedId) {

                // find which radio button is selected

                if(checkedId == R.id.radioButtonPatient)
                    patientChecked = true;

                else if(checkedId == R.id.radioButtonDoctor)
                    doctorChecked = true;
                else if (checkedId == R.id.radioButtonAdmin)
                    adminChecked = true;



            }
        });


        progressDialog = new ProgressDialog(this);
        _loginButton.setOnClickListener(this);
        _btnToSignup.setOnClickListener(this);
    }

    private void userLogin()
    {
        String email = _emailText.getText().toString().trim();
        String password = _passwordText.getText().toString().trim();

        if (email.isEmpty() || !android.util.Patterns.EMAIL_ADDRESS.matcher(email).matches()) {
            _emailText.setError("enter a valid email address");
            return;
        } else {
            _emailText.setError(null);
            }
        if (password.isEmpty() || password.length() < 4 || password.length() > 10) {
            _passwordText.setError("between 4 and 10 alphanumeric characters");
            return;
        } else {
            _passwordText.setError(null);
        }
        if (radioGroupLogin.getCheckedRadioButtonId() == -1)
        {
            // no radio buttons are checked
            Toast.makeText(getApplicationContext(), "Please select whether Patient, Doctor or Admin", Toast.LENGTH_SHORT).show();
            return;
        }

        progressDialog.setMessage("Logging in...");
        progressDialog.show();

        firebaseAuth.signInWithEmailAndPassword(email, password).addOnCompleteListener(this, new OnCompleteListener<AuthResult>(){
            @Override
            public void onComplete(@NonNull Task<AuthResult> task)
            {
                progressDialog.dismiss();
                if(task.isSuccessful())
                {
                    finish();
                    startActivity(new Intent(getApplicationContext(), P2.class));
                }
            }
        });
    }

    @Override
    public void onClick(View view)
    {
        if(view == _loginButton)
            userLogin();
        if(view == _btnToSignup)
        {
            if(patientChecked==true)
            {finish();
             startActivity(new Intent(this,SignupActivity.class));
            }
            else if(doctorChecked==true)
            {finish();
                startActivity(new Intent(this,SignupDoctorActivity.class));

            }
        }
    }
}

The XML code for login is: activity_login.xml

<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:fitsSystemWindows="true">

    <LinearLayout
        android:orientation="vertical"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:paddingTop="56dp"
        android:paddingLeft="24dp"
        android:paddingRight="24dp">

        <ImageView
            android:id="@+id/imageView"
            android:layout_width="wrap_content"
            android:layout_height="72dp"
            android:layout_gravity="center_horizontal"
            android:layout_marginBottom="24dp"
            android:src="@drawable/logo" />

        <!-- Email Label -->
        <TableRow
            android:layout_width="wrap_content"
            android:layout_height="wrap_content">
            <RadioGroup
                android:orientation="horizontal"
                android:id="@+id/loginRadioGroup"
                >
        <RadioButton
            android:id="@+id/radioButtonPatient"
            android:layout_width="120dp"
            android:layout_height="wrap_content"
            android:text="Patient"
            />
        <RadioButton
            android:id="@+id/radioButtonDoctor"
            android:layout_width="120dp"
            android:layout_height="wrap_content"
            android:text="Doctor"
            />
        <RadioButton
            android:id="@+id/radioButtonAdmin"
            android:layout_width="120dp"
            android:layout_height="wrap_content"
            android:text="Admin"
            />
            </RadioGroup>
        </TableRow>

        <!--Email label-->
        <android.support.design.widget.TextInputLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="8dp"
            android:layout_marginBottom="8dp">

            <EditText android:id="@+id/input_email"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:inputType="textEmailAddress"
                android:hint="Email" />
        </android.support.design.widget.TextInputLayout>

        <!-- Password Label -->
        <android.support.design.widget.TextInputLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="8dp"
            android:layout_marginBottom="8dp">
            <EditText android:id="@+id/input_password"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:inputType="textPassword"
                android:hint="Password"/>
        </android.support.design.widget.TextInputLayout>

        <android.support.v7.widget.AppCompatButton
            android:id="@+id/btn_login"
            android:layout_width="fill_parent"
            android:layout_height="37dp"
            android:layout_marginTop="24dp"
            android:layout_marginBottom="24dp"
            android:padding="10dp"
            android:text="Login"/>

        <TextView
            android:id="@+id/link_signup"
            android:layout_width="334dp"
            android:layout_height="wrap_content"
            android:layout_marginBottom="24dp"
            android:gravity="center"
            android:text="No account yet?"
            android:textSize="16dip" />

        <Button
            android:id="@+id/btnToSignup"
            style="@style/Widget.AppCompat.Button.Borderless.Colored"
            android:layout_width="343dp"
            android:layout_height="wrap_content"
            android:text="Create one Here." />


    </LinearLayout>
</ScrollView>

Error log:

05-02 02:31:37.958 3257-3257/com.example.user.compounderapp I/InstantRun: Starting Instant Run Server for com.example.user.compounderapp
05-02 02:31:37.958 1565-2012/system_process W/ActivityManager: getRunningAppProcesses: caller 10060 does not hold REAL_GET_TASKS; limiting output
05-02 02:31:37.962 3257-3277/com.example.user.compounderapp V/FA: Using measurement service
05-02 02:31:37.962 3257-3277/com.example.user.compounderapp V/FA: Connecting to remote service
05-02 02:31:37.970 3257-3257/com.example.user.compounderapp D/FirebaseApp: Notifying auth state listeners.
05-02 02:31:37.971 3257-3257/com.example.user.compounderapp D/FirebaseApp: Notified 0 auth state listeners.
05-02 02:31:37.971 3257-3257/com.example.user.compounderapp D/FirebaseApp: Notifying auth state listeners.
05-02 02:31:37.971 3257-3257/com.example.user.compounderapp D/FirebaseApp: Notified 0 auth state listeners.
05-02 02:31:37.997 3257-3279/com.example.user.compounderapp D/FirebaseInstanceId: topic sync succeeded
05-02 02:31:38.001 3257-3277/com.example.user.compounderapp D/FA: Connected to remote service
05-02 02:31:38.001 3257-3277/com.example.user.compounderapp V/FA: Processing queued up service tasks: 1
05-02 02:31:38.541 1172-1529/? W/AudioFlinger: write blocked for 1475 msecs, 1 delayed writes, thread 0xb5cac000
05-02 02:31:39.791 1565-1672/system_process D/TaskPersister: removeObsoleteFile: deleting file=47_task.xml
05-02 02:31:39.791 1565-1672/system_process D/TaskPersister: removeObsoleteFile: deleting file=47_task_thumbnail.png
05-02 02:31:42.249 2229-3256/com.google.android.gms W/PlatformStatsUtil: Could not retrieve Usage & Diagnostics setting. Giving up.
05-02 02:31:43.037 3257-3277/com.example.user.compounderapp V/FA: Inactivity, disconnecting from the service
05-02 02:31:48.097 3257-3273/com.example.user.compounderapp W/DynamiteModule: Local module descriptor class for com.google.firebase.auth not found.
Pang
  • 9,564
  • 146
  • 81
  • 122
Prerona
  • 1
  • 1
  • Please add the Logs so we can see why it crashed https://developer.android.com/studio/debug/am-logcat.html – Blundell May 01 '17 at 20:45
  • I have added the logs. May look too big and clumsy. I am an amateur in android coding. So wasn't sure about the exact error line. Thanks in advance! – Prerona May 01 '17 at 21:09

1 Answers1

0

In your crash log there is this specific line that is causing the problem:

05-02 02:31:48.097 3257-3273/com.example.user.compounderapp W/DynamiteModule: Local module descriptor class for com.google.firebase.auth not found.

In order to fully use Firebase on Android, here is the 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.

You can check out more information here: Android Firebase DynamiteModule: Failed to load module descriptor

Community
  • 1
  • 1
DeanK
  • 344
  • 2
  • 14