FirebaseUser's profile is not updated

2019-01-08 18:11发布

问题:

I use Firebase Auth on Android.

My signin flow works fine but I can't update username & profileUrl right after.

public void test() {
    String username = "test username";
    Uri avatarUri = Uri.parse("http://www.pixelstalk.net/wp-content/uploads/2016/08/Wonderful-Random-Background.jpg");
    UserProfileChangeRequest.Builder builder = new UserProfileChangeRequest.Builder();
    builder.setDisplayName(username);
    builder.setPhotoUri(avatarUri);

    Log.d("UPDATE PROFILE", "user exists=" + (firebaseAuth.getCurrentUser() != null ? "YES" : "NO"));
    Log.d("UPDATE PROFILE", "user anonymous=" + (firebaseAuth.getCurrentUser().isAnonymous() ? "YES" : "NO"));
    firebaseAuth.getCurrentUser().updateProfile(builder.build()).addOnCompleteListener(new OnCompleteListener<Void>() {
        @Override
        public void onComplete(@NonNull Task<Void> task) {
            if (task.isSuccessful()) {
                if (firebaseAuth.getCurrentUser().getDisplayName() != null) {
                    Log.d("UPDATE PROFILE", "username=" + firebaseAuth.getCurrentUser().getDisplayName());
                } else {
                    Log.d("UPDATE PROFILE", "username=NULL");
                }
                if (firebaseAuth.getCurrentUser().getPhotoUrl() != null) {
                    Log.d("UPDATE PROFILE", "photoUrl=" + firebaseAuth.getCurrentUser().getPhotoUrl().toString());
                } else {
                    Log.d("UPDATE PROFILE", "photoUrl=NULL");
                }
            } else {
                Log.e("UPDATE PROFILE", task.getException().getMessage());
            }
        }
    });

}

I tried the test method above and this is my output

UPDATE PROFILE: user exists=YES

UPDATE PROFILE: user anonymous=NO

UPDATE PROFILE: username=NULL

UPDATE PROFILE: photoUrl=NULL

I don't understand why my currentUser is not updated even with a "isSuccessful()" result

回答1:

This is a known issue in the latest release of Firebase (9.8.0). It's a known issue according to here. The only temp fix right now is to rollback everything to version 9.6.1.

Change your gradle dependencies for the app to this for Firebase components (this is just a temp fix, and it could break something else if using something in new version):

compile 'com.google.android.gms:play-services-auth:9.6.1'
compile 'com.google.firebase:firebase-core:9.6.1'
compile 'com.google.firebase:firebase-messaging:9.6.1'
compile 'com.google.firebase:firebase-auth:9.6.1'
compile 'com.google.firebase:firebase-database:9.6.1'

Change those matching ones in your grandle to the versions specified above.