Q:

Android firebase auth: Link anonymous account with manual user still creating 2 accounts on firebase console

Here are the steps to reproduce the problem: 

Create an anonymous account 
Create a manual account

mFirebaseAuth.createUserWithEmailAndPassword(email, password)
        .addOnCompleteListener(this, task - > {
            if (task.isSuccessful()) {
                AuthCredential credential = EmailAuthProvider.getCredential(email, password);
                linkWithAnonymousAccount(credential);
            } else {
                hideProgressDialog();
                String msg = task.getException().getLocalizedMessage();
                Utils.showDialogMessage(mContext, msg);
            }
        });

Link manual account with the anonymous account 

private void linkWithAnonymousAccount(final AuthCredential credential) {
    mFirebaseAuth.getCurrentUser().linkWithCredential(credential)
        .addOnCompleteListener(this, task - > {
            if (task.isSuccessful()) {
                callUpdateUserApi();
            } else {
                hideProgressDialog();
                Utils.showDialogMessage(mContext, task.getException().getLocalizedMessage());
            }
        });
     }

Current result: 2 accounts, anonymous account, and manual account are created on firebase console 
Expected result: anonymous account should be merged with a manual account. 
Firebase version 
compile "com.google.android.gms:play-services-auth: '11.4.2'

It works properly with a social account but doesn't with the manual account. Please advise 

A:

You can't link 2 existing accounts with Firebase Auth. One of the 2 credentials must be new and not already in the Auth database.
You seem to be signing in an anonymous user and creating an email/password user and then trying to link them. This will fail as you can't link 2 existing users with different UID. In that case you have to manually copy the data from one to the other and then delete the stale user.
What you should do, is not createUserWithEmailAndPassword.
You signInAnonymously the anonymous user and then directly link the email/password credential to that.
// Initialize the email/pass credential and directly link it to the
// current anonymous user already signed in.
AuthCredential credential = EmailAuthProvider.getCredential(email, password);
mFirebaseAuth.getCurrentUser().linkWithCredential(credential)...

