I'm running into the same problem when I build the application with BUCK but I am able to use Firebase correctly when I build with Gradle. You may want to verify that Firebase was initialized. You should see this in your logs if so:
I/FirebaseInitProvider: FirebaseApp initialization successful
Looking at the documentation here: https://firebase.google.com/docs/reference/android/com/google/firebase/iid/FirebaseInstanceId, FirebaseInstanceId.getInstance().getToken() is deprecated in favor of getInstanceId().
Instead, this documentation shows how to get the current firebase token: https://firebase.google.com/docs/cloud-messaging/android/client?authuser=1#retrieve-the-current-registration-token
FirebaseInstanceId.getInstance().getInstanceId()
.addOnCompleteListener(new OnCompleteListener<InstanceIdResult>() {
@Override
public void onComplete(@NonNull Task<InstanceIdResult> task) {
if (!task.isSuccessful()) {
Log.w(TAG, "getInstanceId failed", task.getException());
return;
}
// Get new Instance ID token
String token = task.getResult().getToken();
// Log and toast
String msg = getString(R.string.msg_token_fmt, token);
Log.d(TAG, msg);
Toast.makeText(MainActivity.this, msg, Toast.LENGTH_SHORT).show();
}
});
This documentation says that the onNewToken method gets called when the token has been updated: https://firebase.google.com/docs/cloud-messaging/android/client?authuser=1#monitor-token-generation
/**
* Called if InstanceID token is updated. This may occur if the security of
* the previous token had been compromised. Note that this is called when the InstanceID token
* is initially generated so this is where you would retrieve the token.
*/
@Override
public void onNewToken(String token) {
Log.d(TAG, "Refreshed token: " + token);
// If you want to send messages to this application instance or
// manage this apps subscriptions on the server side, send the
// Instance ID token to your app server.
sendRegistrationToServer(token);
}
With Gradle, I was able to get this to work with these libraries:
implementation 'com.google.firebase:firebase-messaging:18.0.0'
implementation 'com.google.firebase:firebase-auth:17.0.0'
I had migrated from GCM to FCM, and the documentation was straight forward for getting it to work with Gradle: https://developers.google.com/cloud-messaging/android/android-migrate-fcm
This documentation seems straight forward as well if you are using Gradle to build: https://firebase.google.com/docs/cloud-messaging/android/client?authuser=1#monitor-token-generation