创建用户后,Firebase Android无法进入addOnCompleteListener

时间:2017-05-05 07:00:06

标签: android firebase firebase-realtime-database firebase-authentication

在这个错误2天后我不得不发布这个问题,我正在创建一个数据库,因为它出现在我的cadastrarUsuario方法中。问题是,在传递“createUserWithEmalandPassword”行并在firebaseAuthentication中创建用户(我在浏览器中检查过它)后,它就崩溃了。控制台说:

05-05 06:36:48.895 4791-4834/studio.brunocasamassa.ajudaaqui W/DynamiteModule: Local module descriptor class for com.google.firebase.auth not found.
05-05 06:36:48.895 4791-4834/studio.brunocasamassa.ajudaaqui W/DynamiteModule: Local module descriptor class for com.google.firebase.auth not found.
05-05 06:36:48.912 4791-6318/studio.brunocasamassa.ajudaaqui V/FA: Activity paused, time: 2141000
05-05 06:36:48.936 4791-4791/studio.brunocasamassa.ajudaaqui V/FA: onActivityCreated
05-05 06:36:48.957 4791-6318/studio.brunocasamassa.ajudaaqui V/FA: Activity resumed, time: 2141044
05-05 06:36:49.122 4791-4791/studio.brunocasamassa.ajudaaqui W/IInputConnectionWrapper: finishComposingText on inactive InputConnection
05-05 06:36:50.541 4791-4805/studio.brunocasamassa.ajudaaqui D/FirebaseAuth: Notifying listeners about user ( Onec4KwKzUUMA5mXualVJSovhum1 ).
05-05 06:36:50.541 4791-4791/studio.brunocasamassa.ajudaaqui D/FirebaseApp: Notifying auth state listeners.
05-05 06:36:50.542 4791-4791/studio.brunocasamassa.ajudaaqui D/FirebaseApp: Notified 0 auth state listeners.
05-05 06:36:59.008 4791-4834/studio.brunocasamassa.ajudaaqui W/DynamiteModule: Local module descriptor class for com.google.firebase.auth not found.
 05-05 06:37:13.445 4791-6318/studio.brunocasamassa.ajudaaqui V/FA: Activity paused, time: 2165532
05-05 06:37:13.460 4791-6318/studio.brunocasamassa.ajudaaqui V/FA: Activity resumed, time: 2165547
05-05 06:37:13.626 4791-4791/studio.brunocasamassa.ajudaaqui W/IInputConnectionWrapper: finishComposingText on inactive InputConnection
  
    

更新错误     它现在出现在控制台中

  

“05-05 07:34:38.011 24936-24967 / studio.brunocasamassa.ajudaaqui E / DynamiteModule:无法加载模块描述符类:未找到类”com.google.android.gms.dynamite.descriptors。 com.google.firebase.auth.ModuleDescriptor“on path:DexPathList [[zip file”/data/app/studio.brunocasamassa.ajudaaqui-1/base.apk",zip file“/data/app/studio.brunocasamassa.ajudaaqui -1 / split_lib_dependencies_apk.apk“,zip文件”/data/app/studio.brunocasamassa.ajudaaqui-1/split_lib_slice_0_apk.apk“,zip文件”/data/app/studio.brunocasamassa.ajudaaqui-1/split_lib_slice_1_apk.apk“, zip文件“/data/app/studio.brunocasamassa.ajudaaqui-1/split_lib_slice_2_apk.apk”,zip文件“/data/app/studio.brunocasamassa.ajudaaqui-1/split_lib_slice_3_apk.apk”,zip文件“/ data / app / studio.brunocasamassa.ajudaaqui-1 / split_lib_slice_4_apk.apk“,zip文件”/data/app/studio.brunocasamassa.ajudaaqui-1/split_lib_slice_5_apk.apk“,zip文件”/data/app/studio.brunocasamassa.ajudaaqui-1/ split_lib_slice_6_apk.apk“,zip文件”/ data / app / s tudio.brunocasamassa.ajudaaqui-1 / split_lib_slice_7_apk.apk“,zip文件”/data/app/studio.brunocasamassa.ajudaaqui-1/split_lib_slice_8_apk.apk“,zip文件”/data/app/studio.brunocasamassa.ajudaaqui-1/ split_lib_slice_9_apk.apk“],nativeLibraryDirectories = [/ data / app / studio.brunocasamassa.ajudaaqui-1 / lib / x86,/ system / lib,/ vendor / lib]]

  
    

此处是我的活动(cadastrarUsuario方法中的错误)

  
package studio.brunocasamassa.ajudaaqui;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.v7.app.AppCompatActivity;
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;
import com.google.firebase.auth.FirebaseAuthInvalidCredentialsException;
import com.google.firebase.auth.FirebaseAuthWeakPasswordException;
import com.google.firebase.auth.FirebaseUser;
import com.google.firebase.database.DatabaseReference;

import studio.brunocasamassa.ajudaaqui.helper.Base64Decoder;
import studio.brunocasamassa.ajudaaqui.helper.FirebaseConfig;
import studio.brunocasamassa.ajudaaqui.helper.Preferences;
import studio.brunocasamassa.ajudaaqui.helper.User;

/**
 * Created by bruno on 24/04/2017.
 */

public class CadastroActivity extends AppCompatActivity {
    private Button cadastrar;
    private EditText email;
    private EditText nome;
    private EditText senha;
    private EditText senhaConfirm;
    private FirebaseAuth autenticacao;
    private DatabaseReference firebaseDatabase;
    public User usuario;
    private Base64Decoder decoder;


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

        nome = (EditText) findViewById(R.id.cadastro_nome);
        email = (EditText) findViewById(R.id.cadastro_email);
        senha = (EditText) findViewById(R.id.cadastro_senha);
        senhaConfirm = (EditText) findViewById(R.id.cadastro_senhaConfirm);

        cadastrar = (Button) findViewById(R.id.buttonValidarCadstro);

        cadastrar.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                usuario = new User();
                usuario.setName(nome.getText().toString());
                usuario.setEmail(email.getText().toString());
                usuario.setSenha(senha.getText().toString());
                System.out.println("EMAIL: " + usuario.getEmail() + "SENHA: " + usuario.getSenha());
                cadastrarUsuario();
                startActivity(new Intent(CadastroActivity.this, LoginActivity.class));
            }
        });

    }

    private void cadastrarUsuario() {

        autenticacao = FirebaseConfig.getFirebaseAuthentication();

        System.out.println("EMAIL: " + usuario.getEmail() + "  SENHA: " + usuario.getSenha());

        autenticacao.createUserWithEmailAndPassword("getRripped2@hotmail.com", "superm34tboy"
            ).addOnCompleteListener(CadastroActivity.this, new OnCompleteListener<AuthResult>() {
                    @Override
                    public void onComplete(@NonNull Task<AuthResult> task) {
                        if (task.isSuccessful()) {

                           // FirebaseUser usuarioFireBase = task.getResult().getUser();
                            String idUser = Base64Decoder.encoderBase64(usuario.getEmail());
                            System.out.println("BASE64 ENCODER: " + idUser);
                            usuario.setId(idUser);
                            usuario.save();

                            /*firebaseDatabase = FirebaseConfig.getFireBase();1

                            firebaseDatabase.child("usuarios").setValue(idUser);*/

                            firebaseDatabase = FirebaseConfig.getFireBase();
                            firebaseDatabase.child("pontos").setValue("300");

                            FirebaseUser usuarioFirebase = task.getResult().getUser();
                            usuario.setId( usuarioFirebase.getUid() );

                            Preferences preferences = new Preferences(CadastroActivity.this);

                            preferences.saveData(idUser);

                            /*autenticacao.signOut();*/
                            Toast.makeText(CadastroActivity.this, "Usuario cadastrado com sucesso", Toast.LENGTH_LONG).show();

                            finish();

                        } else {

                            try {

                                System.out.println("TASK ERROR CARAIO " + task.getException().toString());
                                throw task.getException();

                            } catch (FirebaseAuthWeakPasswordException e) {
                                Toast.makeText(CadastroActivity.this, "Senha invalida, favor escolher outra senha para autenticacao", Toast.LENGTH_LONG).show();
                            } catch (FirebaseAuthInvalidCredentialsException e) {
                                Toast.makeText(CadastroActivity.this, "e-mail invalido, verifique os valores digitados", Toast.LENGTH_LONG).show();
                            } catch (Exception e) {
                                e.printStackTrace();
                                System.out.println("ERROR CARAIO " + e);
                            }
                        }

                    }

                }

        );

    }
}

这是我的构建gradle信息:

apply plugin: 'com.android.application'
android {

    compileSdkVersion 25
    buildToolsVersion "25.0.3"
    defaultConfig {
        applicationId "studio.brunocasamassa.ajudaaqui"
        minSdkVersion 15
        targetSdkVersion 25
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    packagingOptions {
        exclude 'META-INF/LICENSE'
        exclude 'META-INF/LICENSE-FIREBASE.txt'
        exclude 'META-INF/NOTICE'
    }
}



repositories {
    mavenCentral()
}


dependencies {


    compile fileTree(dir: 'libs', include: ['*.jar'])
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })

    compile 'com.android.support:appcompat-v7:23.1.1'
    compile 'de.hdodenhof:circleimageview:2.1.0'
    compile 'com.facebook.android:facebook-android-sdk:4+'
    compile 'com.google.firebase:firebase-database:9.6.1'
    compile 'com.google.firebase:firebase-auth:9.6.1'
    compile 'com.google.firebase:firebase-core:9.6.1'
    compile 'com.github.bumptech.glide:glide:3.7.0'
    compile 'com.android.support:design:23.1.1'
    compile 'com.github.rtoshiro.mflibrary:mflibrary:1.0.0'
    compile 'com.android.support:gridlayout-v7:23.1.1'
    compile('com.mikepenz:materialdrawer:5.3.6@aar') {
        transitive = true
    }
    testCompile 'junit:junit:4.12'
}
apply plugin: 'com.google.gms.google-services'

请帮忙。

2 个答案:

答案 0 :(得分:0)

  • 确保您的播放服务版本高于9。
  • 在firebase控制台中使用电子邮件/密码启用身份验证。
  • 将您的firebase库更新到最新版本。

答案 1 :(得分:0)

问题似乎来自您的Google Play服务版。你检查一下吗?在此之前,请查看offical doc

另外,请确保您的Android设备运行Google Play Services 9.0.0或更高版本。从The Google Play Services SDK检查Android SDK Manager

您的Android Studio 1.5或更高版本?

同时检查Android Studio Project及其package name是否正确。

希望它有所帮助。