after successful google authentication, app crashes while using real time database

爱⌒轻易说出口 提交于 2020-07-10 10:36:46

问题


In my app, after a successful login with Google, it crashes when you get an instance of a firebase realtime database.

In my code, the Google sign works fine after that and there are parameters to get user info and a button on which I have set an onClickListener to upload user data in a realtime database.

onCreate method I have

 company_name = (EditText) findViewById(R.id.ip_company_name);
 mdatabase = FirebaseDatabase.getInstance().getReference();
 val_btn = (Button) findViewById(R.id.btn_validate);

this is onClick code for val_btn

String comp_name = mCompanyName.getText().toString().trim();

        HashMap<String, String> datamap = new HashMap<String, String>();
        datamap.put("Company Name", comp_name);

        mdatabase.push().setValue(datamap).addOnCompleteListener(new OnCompleteListener<Void>() {
            @Override
            public void onComplete(@NonNull Task<Void> task) {
                if (task.isSuccessful()) {
                    Toast.makeText(MainActivity.this, "updated  :)", Toast.LENGTH_SHORT).show();
                } else {
                    Toast.makeText(MainActivity.this, "error  :(", Toast.LENGTH_SHORT).show();

                }
            }
        });

if this code is used without google auth it works but it doesn't work with google auth. I have set up firebase rules correctly I assure that is not an issue.

the error is

E/RunLoop: Uncaught exception in Firebase Database runloop (3.0.0). Please report to firebase-database-client@google.com java.lang.NoClassDefFoundError: Failed resolution of: Lcom/google/firebase/FirebaseApp$IdTokenListener;

and

Caused by: java.lang.ClassNotFoundException: Didn't find class "com.google.firebase.FirebaseApp$IdTokenListener" on path: DexPathList[[zip file "/data/app/com.mm.firebaselogin2-0Br4q5KgPHRacm8MT23I1w==/base.apk"],nativeLibraryDirectories=[/data/app/com.mm.firebaselogin2-0Br4q5KgPHRacm8MT23I1w==/lib/arm64, /system/lib64]]


回答1:


Please upgrade your firebase database version to 17 or latest 19.2.0:

implementation 'com.google.firebase:firebase-database:17.0.0'

Hope it will help you.



来源:https://stackoverflow.com/questions/59817305/after-successful-google-authentication-app-crashes-while-using-real-time-databa

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!