Tata Fombar
Tata Fombar

Reputation: 349

Firebase AuthListener not working

I get the following error:

W/DynamiteModule: Local module descriptor class for com.google.firebase.auth
not found

My code works perfectly if I decide to handle the authentication inside the onCompleteListener, but when I try to handle it from the FirebaseAuth.AuthStateListener, I get an error.

Here's my signin/signup Activity:

public class MainActivity extends AppCompatActivity implements 
AdapterView.OnItemSelectedListener {

EditText number;
EditText ans;
TextView questionText;
Spinner country_code;
String[] codes;
String c_code;
Button next_button_1;
ArrayAdapter<String> adapter;
FirebaseAuth mAuth;
FirebaseAuth.AuthStateListener mAuthListener;

Random rand = new Random();

int a = rand.nextInt(10);
int b = rand.nextInt(10);
int c = a+b;

String tes;
String ran2;
String ran1;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);


    codes = new String[] {"+237","+233","+234"};
    number = (EditText) findViewById(R.id.editText1);
    ans = (EditText) findViewById(R.id.editText_question);
    questionText = (TextView) findViewById(R.id.questionText);


    ran1 = Integer.toString(a);
    ran2 = Integer.toString(b);
    tes = Integer.toString(c);
    questionText.setText( ran1 + " + " + ran2 + " = ");

    country_code = (Spinner) findViewById(R.id.spinner_country_codes);
    country_code.setOnItemSelectedListener(this);
    adapter = new ArrayAdapter<>(this,
            android.R.layout.simple_list_item_1,
            codes);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    country_code.setAdapter(adapter);

    next_button_1 = (Button) findViewById(R.id.sign_in_next_button);

    mAuth = FirebaseAuth.getInstance();
    mAuthListener = new FirebaseAuth.AuthStateListener() {

        @Override
        public void onAuthStateChanged(@NonNull FirebaseAuth firebaseAuth) {
            if (firebaseAuth.getCurrentUser() != null) {
                FirebaseUser user = firebaseAuth.getCurrentUser();
                String uid = user.getUid();
                Intent i = new Intent(MainActivity.this,Main2Activity.class);
                i.putExtra("uid", uid);
                i.putExtra("telephone", number.getText().toString());
                i.putExtra("country_code",c_code);
                startActivity(i);
            }
        }
    };

    if(next_button_1!=null){
        next_button_1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                /*
                Intent intent = new Intent(MainActivity.this, 
Main2Activity.class);
                startActivity(intent);
                */
                String answer = ans.getText().toString();
                if(answer.equals(tes)) {
                    String telphone_number = number.getText().toString();
                    if (TextUtils.isEmpty(c_code) || 
TextUtils.isEmpty(telphone_number)) {
                        Toast.makeText(MainActivity.this, "Empty field 
detected", Toast.LENGTH_SHORT).show();
                    } else {
                        String email = c_code + telphone_number + 
"mydomain.com";
                        String password = c_code + telphone_number;
                        startSignIn(email, password);
                    }
                }else {
                    a = rand.nextInt(10);
                    b = rand.nextInt(10);
                    c = a + b;

                    ran1 = Integer.toString(a);
                    ran2 = Integer.toString(b);
                    tes = Integer.toString(c);

                    questionText.setText( ran1 + " + " + ran2 + " = ");
                    Toast.makeText(MainActivity.this, "Your math test answer 
is wrong.", Toast.LENGTH_LONG).show();
                }
            }
        });
    }
}

@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, 
long id) {
    String c_code = codes[position].toString();
    this.c_code=c_code;
}

@Override
public void onNothingSelected(AdapterView<?> parent) {
}



public void startSignIn(final String e,final String p) {
    //Toast.makeText(MainActivity.this, "email is "+ email +" and password 
is "+ password + "." , Toast.LENGTH_SHORT).show();
      mAuth.signInWithEmailAndPassword(e, p)
             .addOnCompleteListener(this, new OnCompleteListener<AuthResult>
() {
                 @Override
                 public void onComplete(@NonNull Task<AuthResult> task) {
                     if (!task.isSuccessful()) {
                         Toast.makeText(MainActivity.this, "Account not 
found.",
                                 Toast.LENGTH_SHORT).show();
                         Toast.makeText(MainActivity.this, "Creating a new 
Account.",
                                 Toast.LENGTH_LONG).show();
                         createAccont(e, p);
                     }
                 }
             });
}

public void createAccont(String e, String p){
    mAuth.createUserWithEmailAndPassword(e, p)
            .addOnCompleteListener(this, new OnCompleteListener<AuthResult>
() {
                @Override
                public void onComplete(@NonNull Task<AuthResult> task) {
                    if (!task.isSuccessful()) {
                        Toast.makeText(MainActivity.this, "Authentication 
Failed",
                                Toast.LENGTH_SHORT).show();
                    }
                }
            });
}

}

My build.gradle file is as follows:

apply plugin: 'com.android.application'

android {
compileSdkVersion 24
buildToolsVersion '24.0.3'

packagingOptions {
    exclude 'META-INF/LICENSE'
    exclude 'META-INF/LICENSE-FIREBASE.txt'
    exclude 'META-INF/NOTICE'
}

defaultConfig {
    applicationId "biz.batto.mobilemoneymarket"
    minSdkVersion 16
    targetSdkVersion 24
    versionCode 1
    versionName "1.0"
}
buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), '    
proguard-rules.pro'
    }
}
}

dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:24.2.1'
compile 'com.android.support:design:24.2.1'
compile 'com.google.firebase:firebase-core:9.6.1'
compile 'com.google.firebase:firebase-database:9.6.1'
//compile 'com.google.firebase:firebase-storage:9.6.1'
//compile 'com.google.firebase:firebase-crash:9.6.1'
compile 'com.google.firebase:firebase-auth:9.6.1'
//compile 'com.google.firebase:firebase-messaging:9.6.1'
compile 'com.google.firebase:firebase-config:9.6.1'
compile 'com.google.firebase:firebase-invites:9.6.1'
//compile 'com.google.firebase:firebase-ads:9.6.1'
compile 'com.firebase:firebase-client-android:2.5.2'
compile 'com.firebaseui:firebase-ui:0.6.0'
compile 'com.google.android.gms:play-services-auth:9.6.1'

compile 'com.google.android.gms:play-services-appindexing:9.6.1'
}
apply plugin: 'com.google.gms.google-services'

Also, I would like to let you know that I have all my SDK libraries up-to-date and the Google Play Services on my AVD is also up-to-date.

From my MainActivity, I try to authenticate the user first, then if that fails, I try to create you an account. When I run this code and test the account creation process (or login process), the new account is actually created in my Firebase Console, but the AuthStateListener is not notified.

Hence my second activity is not launched and my user user remains on the same activity without the app crashing. I also get the log on the Android Monitor:

W/DynamiteModule: Local module descriptor class for com.google.firebase.auth not found.

This started only today. I have been authenticating on Firebase for a while now with no problems. What can i do?

Upvotes: 0

Views: 906

Answers (1)

Aloy A Sen
Aloy A Sen

Reputation: 764

I faced the same problem, googled a bit I think a maven repository on the gradle and added this to the project level gradle

allprojects {
    repositories {
        // ...
        maven { url 'https://maven.fabric.io/public' }
    } }

this would solve the problem

Upvotes: 1

Related Questions