Android电子邮件和密码验证应用程序崩溃

时间:2018-10-26 13:57:06

标签: java android firebase crash

Activity开头的Firebase电子邮件和密码身份验证应用程序崩溃

  

E / Android运行时:致命异常:主要                     流程:company.pawelzielinski.drdtr,PID:18455                     java.lang.IllegalAccessError:由类com.google.firebase.auth.FirebaseAuth实现的接口com.google.android.gms.internal.zzeuq无法访问(“ / data”声明为“ com.google.firebase.auth.FirebaseAuth” /app/company.pawelzielinski.drdtr-9wLtUa_yKNZf-NsqQCRFzw==/base.apk)                         在java.lang.Class.classForName(本机方法)                         在java.lang.Class.forName(Class.java:453)                         在java.lang.Class.forName(Class.java:378)                         在com.google.firebase.FirebaseApp.zza(SourceFile:734)                         在com.google.firebase.FirebaseApp.zze(SourceFile:705)                         在com.google.firebase.FirebaseApp.initializeApp(SourceFile:328)                         在com.google.firebase.FirebaseApp.initializeApp(SourceFile:294)                         在com.google.firebase.FirebaseApp.initializeApp(SourceFile:281)                         在com.google.firebase.provider.FirebaseInitProvider.onCreate(SourceFile:37)                         在android.content.ContentProvider.attachInfo(ContentProvider.java:1925)                         在android.content.ContentProvider.attachInfo(ContentProvider.java:1900)                         在com.google.firebase.provider.FirebaseInitProvider.attachInfo(SourceFile:31)                         在android.app.ActivityThread.installProvider(ActivityThread.java:6572)                         在android.app.ActivityThread.installContentProviders(ActivityThread.java:6127)                         在android.app.ActivityThread.handleBindApplication(ActivityThread.java:6037)                         在android.app.ActivityThread.-wrap1(未知来源:0)                         在android.app.ActivityThread $ H.handleMessage(ActivityThread.java:1764)                         在android.os.Handler.dispatchMessage(Handler.java:105)                         在android.os.Looper.loop(Looper.java:164)                         在android.app.ActivityThread.main(ActivityThread.java:6938)                         在java.lang.reflect.Method.invoke(本机方法)                         在com.android.internal.os.Zygote $ MethodAndArgsCaller.run(Zygote.java:327)                         在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1374)

package company.pawelzielinski.drdtr;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
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;

public class register_with_firebase extends AppCompatActivity {

    EditText email,password;
    Button registerButton;
    FirebaseAuth firebaseAuth;
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_register_with_firebase);

        email = (EditText) findViewById(R.id.email_firebase_register);
        password = (EditText) findViewById(R.id.password_firebase_register);
        registerButton = (Button) findViewById(R.id.register_button);


        firebaseAuth = FirebaseAuth.getInstance();

        registerButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String email_string = email.getText().toString();
                String password_string = password.getText().toString();

                if(TextUtils.isEmpty(email_string)){
                    Toast.makeText(getApplicationContext(),"Please fill in the required fields", Toast.LENGTH_SHORT).show();
                    return;
                }
                if(TextUtils.isEmpty(password_string)){
                    Toast.makeText(getApplicationContext(),"Please fill in the required fields",Toast.LENGTH_SHORT).show();
                }

                if(password_string.length()<7){
                    Toast.makeText(getApplicationContext(),"Password must be at least 6 characters",Toast.LENGTH_SHORT).show();
                }

                firebaseAuth.createUserWithEmailAndPassword(email_string,password_string)
                        .addOnCompleteListener(new OnCompleteListener<AuthResult>() {
                            @Override
                            public void onComplete(@NonNull Task<AuthResult> task) {
                                if(task.isSuccessful()){
                                    startActivity(new Intent(getApplicationContext(),register_window.class));
                                    finish();
                                }
                                else{
                                    Toast.makeText(getApplicationContext(),"E-mail or password is wrong",Toast.LENGTH_SHORT).show();
                                }
                            }
                        });
            }
        });


        if(firebaseAuth.getCurrentUser()!=null){
           startActivity(new Intent(getApplicationContext(),main_menu_in_game.class));
        }
    }
}
  

依赖项{       实现fileTree(dir:'libs',包括:['* .jar'])

implementation 'com.android.support:appcompat-v7:28.0.0-rc02'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
implementation 'com.android.support:design:28.0.0-rc02'
implementation 'com.squareup.retrofit2:retrofit:2.4.0'
implementation 'com.squareup.retrofit2:converter-gson:2.3.0'
implementation 'com.android.support:support-v4:28.0.0'
implementation 'com.google.firebase:firebase-auth:11.6.0'
implementation 'com.google.firebase:firebase-database:11.8.0'
implementation 'com.google.firebase:firebase-firestore:11.8.0'
testImplementation 'junit:junit:4.12'

implementation 'com.android.volley:volley:1.1.1'
implementation 'com.squareup.okhttp3:logging-interceptor:3.3.1'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
implementation 'com.google.firebase:firebase-core:16.0.1'
     

}应用插件:“ com.google.gms.google-services”

     

buildscript {

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


    // NOTE: Do not place your application dependencies here; they belong
    // in the individual module build.gradle files
    classpath 'com.google.gms:google-services:3.1.1'
} }
     

allprojects {       储存库{           谷歌()           jcenter()       }

     

任务清理(类型:删除){       删除rootProject.buildDir}

1 个答案:

答案 0 :(得分:0)

    buildscript {

        repositories {
            google()
            jcenter()
        }
        dependencies {
            classpath 'com.android.tools.build:gradle:3.0.1'
            classpath 'com.google.gms:google-services:4.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
    }

添加依赖项如下

 implementation 'com.google.firebase:firebase-auth:16.0.4'
 implementation 'com.google.firebase:firebase-database:16.0.3'
 implementation 'com.google.firebase:firebase-firestore:17.1.1'