1

My Android Studio project was working fine until I updated a plugin accidentally in a pop-up suggestion. After that "Firebase Auth" methods are not working. For example:

fAuth = FirebaseAuth.getInstance();
fUser = fAuth.getCurrentUser();

I get the error "cannot resolve method getCurrentUser in firebaseAuth". Similarly, in the following code:

ref.child(fAuth.getUid()).child("Orders").child(orderId).orderByChild("orderStatus")
            .addValueEventListener(new ValueEventListener() {.....}

I get error "cannot resolve method getUid in firebaseAuth". Following is my build.gradle file.

dependencies {
implementation 'androidx.appcompat:appcompat:1.6.0'
implementation 'com.squareup.picasso:picasso:2.8'
implementation 'com.google.android.material:material:1.7.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
implementation 'com.google.firebase:firebase-firestore:24.4.0'
implementation 'com.google.firebase:firebase-auth:21.1.0'
implementation 'com.google.firebase:firebase-admin:9.1.1'
implementation 'androidx.annotation:annotation:1.5.0'
implementation 'androidx.lifecycle:lifecycle-livedata-ktx:2.5.1'
implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.5.1'
implementation 'androidx.preference:preference:1.2.0'
implementation 'com.google.firebase:firebase-storage:20.1.0'
implementation 'com.google.firebase:firebase-analytics:21.2.0'
implementation 'com.google.firebase:firebase-messaging:23.1.1'
implementation 'androidx.cardview:cardview:1.0.0'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.5'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'
implementation 'com.github.bumptech.glide:glide:4.14.2'
annotationProcessor 'com.github.bumptech.glide:compiler:4.14.2'
implementation 'com.karumi:dexter:6.2.3'
implementation 'de.hdodenhof:circleimageview:3.1.0'
implementation 'com.vanniktech:android-image-cropper:4.5.0'
implementation 'de.hdodenhof:circleimageview:3.1.0'
implementation 'com.google.android.gms:play-services-location:21.0.1'
implementation 'com.github.p32929:EasiestSqlLibrary:1.0.0.2'
implementation 'com.github.p32929:AndroidEasySQL-Library:1.4.1'
implementation 'androidx.swiperefreshlayout:swiperefreshlayout:1.1.0'
implementation 'com.android.volley:volley:1.2.1'}

I get these errors in my whole project.

Alex Mamo
  • 130,605
  • 17
  • 163
  • 193
Tasneem
  • 118
  • 2
  • 14

2 Answers2

1

You're getting the following error:

cannot resolve method getUid in firebaseAuth

Most likely at the following line of code:

ref.child(fAuth.getUid())...

Because the fAuth object is an object of type FirebaseAuth, a class does not contain any method called getUid(). If you need the UID of the authenticated user, you have to call .getCurrentUser() first. In code that would be:

ref.child(fAuth.getCurrentUser().getUid())...
Alex Mamo
  • 130,605
  • 17
  • 163
  • 193
  • As I mentioned above, I also get error on .getCurrentUser() – Tasneem Feb 27 '23 at 06:44
  • I am not even getting suggestions of "getCurrentUser()" and "getUid" – Tasneem Feb 27 '23 at 06:48
  • 1
    Have you tried `ref.child(FirebaseAuth.getInstance().getCurrentUser().getUid())...` as well? Does it work? If not, are you sure you have added the correct `import`? – Alex Mamo Feb 27 '23 at 07:03
  • Yes, I have tried it. In this case error highlights in .getCurrentUser(). Import is also correct because I have not changed it. It was working for about a month. Problem arised only after plugin update. – Tasneem Feb 27 '23 at 11:21
  • Show me the import you're using. – Alex Mamo Feb 27 '23 at 12:10
  • My imports are: import com.google.firebase.auth.FirebaseAuth; import com.google.firebase.auth.FirebaseUser; import com.google.firebase.database.DataSnapshot; import com.google.firebase.database.DatabaseError; import com.google.firebase.database.DatabaseReference; import com.google.firebase.database.FirebaseDatabase; – Tasneem Mar 01 '23 at 03:11
  • @Tasneem which plugin you updated ? – Sri mani789 Mar 15 '23 at 14:45
  • Hey Tasneem. Did my answer help? Can I help you with other information? – Alex Mamo Mar 15 '23 at 18:28
0

I am answering my own question here. I tried many solutions, but then I got to know I had used a wrong dependency.

implementation 'com.google.firebase:firebase-admin:9.1.1'

After I have removed it, my project is working.

Hope it will help others.

Tasneem
  • 118
  • 2
  • 14