Firebase AuthListener无法正常工作 [英] Firebase AuthListener not working

查看:129
本文介绍了Firebase AuthListener无法正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  W / DynamiteModule:com.google.firebase.auth的本地模块描述符类
未找到

如果我决定处理 onCompleteListener ,但是当我尝试从 FirebaseAuth.AuthStateListener 处理它时,出现一个错误。



这里是我的签名/注册Activity:

  public class MainActivity extends AppCompatActivity implements 
AdapterView .OnItemSelectedListener {

EditText编号;
EditText ans;
TextView questionText;
Spinner country_code;
String []代码;
字符串c_code;
按钮next_button_1;
ArrayAdapter< String>适配器;
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;
字符串ran2;
字符串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(){
$ b @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 = ();
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(电子邮件,密码);
}
} 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,您的数学测试答案
是错误的,Toast.LENGTH_LONG).show();
}
}
});


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

$ b @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>任务){
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);
}
}
});

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

}

我的build.gradle文件是如下所示:

pre $ $ $ code $ apply





$ compileSdkVersion 24
buildToolsVersion '24 .0.3'

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

defaultConfig {
applicationIdbiz.batto.mobilemoneymarket
minSdkVersion 16
targetSdkVersion 24
versionCode 1
versionName1.0
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android。 txt'),'
proguard-rules.pro'
}
}
}

依赖{
编译fileTree(包括:[ '* .jar'],dir:'libs')
testCompile'junit:junit:4.12'
compile'c​​om.android.support:appcompat-v7:24.2.1
compile'c​​om.android.support:design:24.2.1'
compile'c​​om.google.firebase:firebase-core:9.6.1'
compile'c​​om.google.firebase: firebase-database:9.6.1'
// compile'c​​om.google.firebase:firebase-storage:9.6.1'
// compile'c​​om.google.firebase:firebase-crash:9.6 1'
compile'c​​om.google.firebase:firebase-auth:9.6.1'
// compile'c​​om.google.firebase:firebase-messaging:9.6.1'
compile' com.google.firebase:firebase-config:9.6.1'
compile'c​​om.google.firebase:firebase-invites:9.6.1'
// compile'c​​om.google.firebase:firebase- ads:9.6.1'
compile'c​​om.firebase:firebase-client-android:2.5.2'
compile'c​​om.firebaseui:firebase-ui:0.6.0'
compile' com.google.android.gms:play-services-auth:9.6.1'

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

另外,我想让你k现在我的所有SDK库都是最新的,而且我的AVD上的Google Play服务也是最新的。



从我的MainActivity中,我尝试先认证用户,然后如果失败,我尝试创建一个帐户。当我运行此代码并测试帐户创建过程(或登录过程)时,新帐户实际上是在我的Firebase控制台中创建的,但不会通知 AuthStateListener p>

因此,我的第二个活动没有启动,我的用户用户保持在同一个活动,没有应用程序崩溃。我还获得了Android监视器上的日志:

$ $ p $ W $ DynamiteModule:com.google.firebase.auth的本地模块描述符类未找到。

今天才开始。我已经在Firebase上进行了一段时间的验证,没有任何问题。我可以做什么?

解决方案

我遇到了同样的问题, b,并将其添加到项目级gradle中

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

这可以解决问题

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?

解决方案

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

这篇关于Firebase AuthListener无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆