evollu / react-native-fcm

react native module for firebase cloud messaging and local notification

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

error: cannot find symbol import com.google.firebase.iid.FirebaseInstanceIdService;

thisisbalaG opened this issue · comments

"react-native": "0.55.3"
"react-native-fcm": "^16.2.4",

Running on android emulator : android version : 7.0

My project is not running suddenly with the following error. Please help.

<===="ProjectDirectory"====> \node_modules\react-native-fcm\android\src\main\java\com\evollu\react\fcm\InstanceIdService.java:14: error: cannot find symbol
import com.google.firebase.iid.FirebaseInstanceIdService;
^
symbol: class FirebaseInstanceIdService
location: package com.google.firebase.iid

log..

Task :react-native-fcm:compileDebugJavaWithJavac FAILED
D:\Balaji Workspace React native\SPIUnlimited\phase 2 Unlimited\unlimited-phase-ii\node_modules\react-native-fcm\android\src\main\java\com\evollu\react\fcm\InstanceIdService.java:14: error: cannot find symbol
import com.google.firebase.iid.FirebaseInstanceIdService;
^
symbol: class FirebaseInstanceIdService
location: package com.google.firebase.iid
D:\Balaji Workspace React native\SPIUnlimited\phase 2 Unlimited\unlimited-phase-ii\node_modules\react-native-fcm\android\src\main\java\com\evollu\react\fcm\InstanceIdService.java:16: error: cannot find symbol
public class InstanceIdService extends FirebaseInstanceIdService {
^
symbol: class FirebaseInstanceIdService
D:\Balaji Workspace React native\SPIUnlimited\phase 2 Unlimited\unlimited-phase-ii\node_modules\react-native-fcm\android\src\main\java\com\evollu\react\fcm\InstanceIdService.java:26: error: method does not override or implement a method from a supertype
@OverRide
^
D:\Balaji Workspace React native\SPIUnlimited\phase 2 Unlimited\unlimited-phase-ii\node_modules\react-native-fcm\android\src\main\java\com\evollu\react\fcm\InstanceIdService.java:44: error: cannot find symbol
ReactInstanceManager mReactInstanceManager = ((ReactApplication) getApplication()).getReactNativeHost().getReactInstanceManager();
^
symbol: method getApplication()
D:\Balaji Workspace React native\SPIUnlimited\phase 2 Unlimited\unlimited-phase-ii\node_modules\react-native-fcm\android\src\main\java\com\evollu\react\fcm\InstanceIdService.java:48: error: cannot find symbol
LocalBroadcastManager.getInstance(getApplicationContext()).sendBroadcast(message);
^
symbol: method getApplicationContext()
D:\Balaji Workspace React native\SPIUnlimited\phase 2 Unlimited\unlimited-phase-ii\node_modules\react-native-fcm\android\src\main\java\com\evollu\react\fcm\InstanceIdService.java:53: error: cannot find symbol
LocalBroadcastManager.getInstance(getApplicationContext()).sendBroadcast(message);
^
symbol: method getApplicationContext()
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
6 errors

FAILURE: Build failed with an exception.

  • What went wrong:
    Execution failed for task ':react-native-fcm:compileDebugJavaWithJavac'.

Compilation failed; see the compiler error output for details.

  • Try:
    Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

  • Get more help at https://help.gradle.org

BUILD FAILED in 1m 8s
236 actionable tasks: 228 executed, 8 up-to-date
Could not install the app on the device, read the error above for details.
Make sure you have an Android emulator running or a device connected and have
set up your Android development environment:
https://facebook.github.io/react-native/docs/getting-started.html

add public void onNewToken(String s) in MessagingService can fixed the issues

add public void onNewToken(String s) in MessagingService can fixed the issues

But error is located in this file:-
\node_modules\react-native-fcm\android\src\main\java\com\evollu\react\fcm\InstanceIdService.java file

Suddenly, I face the same error too, running on android device.

I made some changes in code in below file, and its working now, also receiving notifications successfully:
\node_modules\react-native-fcm\android\src\main\java\com\evollu\react\fcm\InstanceIdService.java file

package com.evollu.react.fcm;

import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.support.v4.content.LocalBroadcastManager;
import android.util.Log;

import com.facebook.react.ReactApplication;
import com.facebook.react.ReactInstanceManager;
import com.facebook.react.bridge.ReactContext;
import com.google.firebase.iid.FirebaseInstanceId;
//import com.google.firebase.iid.FirebaseInstanceIdService; //Commented FirebaseInstanceIdService
import com.google.firebase.messaging.FirebaseMessagingService;  //ADD FirebaseMessagingService

public class InstanceIdService extends FirebaseMessagingService {

    private static final String TAG = "InstanceIdService";

    /**
     * Called if InstanceID token is updated. This may occur if the security of
     * the previous token had been compromised. This call is initiated by the
     * InstanceID provider.
     */
    // [START refresh_token]
    @Override
    public void onNewToken(String token) { //Added onNewToken method
        // Get updated InstanceID token.
        String refreshedToken = FirebaseInstanceId.getInstance().getToken();
        Log.d(TAG, "Refreshed token: " + refreshedToken);

        // Broadcast refreshed token
        Intent i = new Intent("com.evollu.react.fcm.FCMRefreshToken");
        Bundle bundle = new Bundle();
        bundle.putString("token", refreshedToken);
        i.putExtras(bundle);

        final Intent message = i;

        Handler handler = new Handler(Looper.getMainLooper());
        handler.post(new Runnable() {
            public void run() {
                // Construct and load our normal React JS code bundle
                ReactInstanceManager mReactInstanceManager = ((ReactApplication) getApplication()).getReactNativeHost().getReactInstanceManager();
                ReactContext context = mReactInstanceManager.getCurrentReactContext();
                // If it's constructed, send a notification
                if (context != null) {
                    LocalBroadcastManager.getInstance(getApplicationContext()).sendBroadcast(message);
                } else {
                    // Otherwise wait for construction, then send the notification
                    mReactInstanceManager.addReactInstanceEventListener(new ReactInstanceManager.ReactInstanceEventListener() {
                        public void onReactContextInitialized(ReactContext context) {
                            LocalBroadcastManager.getInstance(getApplicationContext()).sendBroadcast(message);
                        }
                    });
                    if (!mReactInstanceManager.hasStartedCreatingInitialContext()) {
                        // Construct it in the background
                        mReactInstanceManager.createReactContextInBackground();
                    }
                }
            }
        });
    }
}

Edit: i don't know if it is right thing to do or not, can anyone confirm ?

I made some changes in code in below file, and its working now, also receiving notifications successfully:
\node_modules\react-native-fcm\android\src\main\java\com\evollu\react\fcm\InstanceIdService.java file

package com.evollu.react.fcm;

import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.support.v4.content.LocalBroadcastManager;
import android.util.Log;

import com.facebook.react.ReactApplication;
import com.facebook.react.ReactInstanceManager;
import com.facebook.react.bridge.ReactContext;
import com.google.firebase.iid.FirebaseInstanceId;
//import com.google.firebase.iid.FirebaseInstanceIdService; //Commented FirebaseInstanceIdService
import com.google.firebase.messaging.FirebaseMessagingService;  //ADD FirebaseMessagingService

public class InstanceIdService extends FirebaseMessagingService {

    private static final String TAG = "InstanceIdService";

    /**
     * Called if InstanceID token is updated. This may occur if the security of
     * the previous token had been compromised. This call is initiated by the
     * InstanceID provider.
     */
    // [START refresh_token]
    @Override
    public void onNewToken(String token) { //Added onNewToken method
        // Get updated InstanceID token.
        String refreshedToken = FirebaseInstanceId.getInstance().getToken();
        Log.d(TAG, "Refreshed token: " + refreshedToken);

        // Broadcast refreshed token
        Intent i = new Intent("com.evollu.react.fcm.FCMRefreshToken");
        Bundle bundle = new Bundle();
        bundle.putString("token", refreshedToken);
        i.putExtras(bundle);

        final Intent message = i;

        Handler handler = new Handler(Looper.getMainLooper());
        handler.post(new Runnable() {
            public void run() {
                // Construct and load our normal React JS code bundle
                ReactInstanceManager mReactInstanceManager = ((ReactApplication) getApplication()).getReactNativeHost().getReactInstanceManager();
                ReactContext context = mReactInstanceManager.getCurrentReactContext();
                // If it's constructed, send a notification
                if (context != null) {
                    LocalBroadcastManager.getInstance(getApplicationContext()).sendBroadcast(message);
                } else {
                    // Otherwise wait for construction, then send the notification
                    mReactInstanceManager.addReactInstanceEventListener(new ReactInstanceManager.ReactInstanceEventListener() {
                        public void onReactContextInitialized(ReactContext context) {
                            LocalBroadcastManager.getInstance(getApplicationContext()).sendBroadcast(message);
                        }
                    });
                    if (!mReactInstanceManager.hasStartedCreatingInitialContext()) {
                        // Construct it in the background
                        mReactInstanceManager.createReactContextInBackground();
                    }
                }
            }
        });
    }
}

Edit: i don't know if it is right thing to do or not, can anyone confirm ?

maybe use

        <!--<intent-filter>-->
          <!--<action android:name="com.google.firebase.INSTANCE_ID_EVENT"/>-->
        <!--</intent-filter>-->
    <!--</service>-->

and add public void onNewToken(String s) in MessagingService

add public void onNewToken(String s) in MessagingService can fixed the issues

But error is located in this file:-
\node_modules\react-native-fcm\android\src\main\java\com\evollu\react\fcm\InstanceIdService.java file

hide InstanceIdService.java don't used the class :)

It working again after I follow @ravishankar3961 , thanks. It is because depreciated method

but my push notifications not working

@thisisbalaG
Same error happening with me

but my push notifications not working

@haripermadi were you able to generate token ?

but my push notifications not working

@haripermadi were you able to generate token ?

yes, I can generate the token. I used this for a chatting feature using qiscus sdk. When I test sending push notif from firebase console, it is working properly, but when I test using my chat it doesn't work.

@ravishankar3961
I can change this code in my project
my App Successfully build but
App install in my device
has stopped this app

so can We Help me

It working again after I follow @ravishankar3961 , thanks. It is because depreciated method

i build successfully. but this app crash when run.
this is exception :
java.lang.NoClassDefFoundError: Failed resolution of: Lcom/google/firebase/auth/FirebaseAuth;
at com.google.firebase.auth.FirebaseAuthRegistrar.getComponents(Unknown Source:3)

someone help me :|

@ravishankar3961 It working again with notification push tested.

Thanks @ravishankar3961 It's working now!

I have same problem. It worked before. But now, It shown the error.
After trying @ravishankar3961 's solution, I can build without error now. But I tried to send the notification, it doesn't work

Thanks for the help @ravishankar3961. Your solution resolved the error but my app is crashing on launch without any error.

Solution resolved the error for me also but app crashes on start

Thanks @ravishankar3961 .Your solution works but application started crashing on launch.

ah, I confirm that @ravishankar3961 's solution is worked for me. Many thanks

Thanks @ravishankar3961 . The Solution did worked, you saved the day..!! 👍
The FirebaseInstanceIdService class is deprecated, So FirebaseMessagingService and onNewToken
really worked !! Thanks again.

@ravishankar3961 After doing the changes, I am getting this Error and Build fails.

  • What went wrong:
    Execution failed for task ':app:transformClassesAndResourcesWithProguardForPreqaRelease'.

Job failed, see logs for details

Hello everyone ,
Below is the crash log i am getting when app launches.

E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.appID, PID: 18120
java.lang.NoClassDefFoundError: Failed resolution of: Lcom/google/firebase/auth/FirebaseAuth;
at com.google.firebase.auth.FirebaseAuthRegistrar.getComponents(Unknown Source)
at com.google.firebase.components.ComponentRuntime.(com.google.firebase:firebase-common@@17.0.0:56)
at com.google.firebase.FirebaseApp.(com.google.firebase:firebase-common@@17.0.0:478)

How to solve the above issue?

Screenshot 2019-05-07 at 5 59 39 PM

getToken() is also deprecated as written in documentation so what to do? should we use getInstanceId() as written

@ravishankar3961 @haripermadi just facing this error around 3 hours ago, previously was running just fine. I tried @ravishankar3961's solution and the build succeed.

Notification received on background, but not on the foreground. For background notification, click_action is also not working. Probably the best time to switch to react-native-firebase?

The @ravishankar3961 's solution worked but it not the right way as a build server will not get the fix. It needs to be added upstream to react-native-fcm.

change firebase version in below files:
${project}\android\app\build.gradle

...
//implementation 'com.google.firebase:firebase-core'
//implementation 'com.google.firebase:firebase-messaging'
implementation 'com.google.firebase:firebase-core:16.0.8'
implementation 'com.google.firebase:firebase-messaging:17.6.0'
...

and
${project}\android\gradle.properties
At the bottom of file add

firebaseCoreVersion=16.0.8
firebaseMessagingVersion=17.6.0

change firebase version in below files:
${project}\node_modules\react-native-fcm\android\build.gradle,

...
//def DEFAULT_FIREBASE_CORE_VERSION           = "+"
//def DEFAULT_FIREBASE_MESSAGING_VERSION      = "+"
def DEFAULT_FIREBASE_CORE_VERSION           = "16.0.3"
def DEFAULT_FIREBASE_MESSAGING_VERSION      = "17.6.0"
...

and
${project}\android\app\build.gradle

...
//implementation 'com.google.firebase:firebase-core'
//implementation 'com.google.firebase:firebase-messaging'
implementation 'com.google.firebase:firebase-core:16.0.3'
implementation 'com.google.firebase:firebase-messaging:17.6.0'
...

Hmmm... my ${project}\node_modules\react-native-fcm\android\build.gradle originally didn't have
def DEFAULT_FIREBASE_CORE_VERSION = "+"
def DEFAULT_FIREBASE_MESSAGING_VERSION = "+"
this 2 line.

At which part should I add the new lines?

@Gabsys I had the same issue and found out I am several version behind on react-native-fcm. I updated to react-native-fcm": "^16.2.4" and this line is now present in that file.

apparently it’s because google deprecated FirebaseInstanceService, now you must use FirebaseMessagingService

@zhou-ting , thanks for the solution. Alternatively, you can add below configuration in ${project}\android\gradle.properties file. So that every time when you clean the project, don't need to change ${project}\node_modules\react-native-fcm\android\build.gradle again.

googlePlayServicesVersion=16.0.3
firebaseMessagingVersion=17.6.0

The @ravishankar3961 's solution worked but it not the right way as a build server will not get the fix. It needs to be added upstream to react-native-fcm.

yeah 😄, i cannot agree more

@theodorusyoga , No Need to Switch to react-native-firebase. I got a solution to get a push when app is in foreground. simply we need to make use of

FCM.presentLocalNotification()

Function with some inputs when app is in foreground explicitly .Below FCM object helped to solve issue.

FCM.presentLocalNotification({
channel: “channel ID",
title:”Title"
body: “Body"
sound: “default"
priority: “High"
auto_cancel: true,
icon: “icon name"
color: “any default colour"
vibrate: 300,
wake_screen: true,
group: "group",
ongoing: true,
show_in_foreground: true // this is very important
});

@ravishankar3961 The docs for onNewToken(String token) states that

public void onNewToken (String token)
Called when a new token for the default Firebase project is generated.

This is invoked after app install when a token is first generated, and again if the token changes.

So, do we still need this line (below) for getting the updated token?

 String refreshedToken = FirebaseInstanceId.getInstance().getToken();

Isn't the updated token available in the token parameter of this method? Can we just write

@Override
    public void onNewToken(String token) {
        // Get updated InstanceID token.
        String refreshedToken = token;
        ...
        ...

@ravishankar3961 working fine when the app is in background, closed but when the app is in forgeround its not working

@ravishankar3961 The docs for onNewToken(String token) states that

public void onNewToken (String token)
Called when a new token for the default Firebase project is generated.

This is invoked after app install when a token is first generated, and again if the token changes.

So, do we still need this line (below) for getting the updated token?

 String refreshedToken = FirebaseInstanceId.getInstance().getToken();

Isn't the updated token available in the token parameter of this method? Can we just write

@Override
    public void onNewToken(String token) {
        // Get updated InstanceID token.
        String refreshedToken = token;
        ...
        ...

yes we can do that, as the onNewToken method is already giving us token

I've made a quick dirty hack updating InstanceIdService.java and pointing my package.json to my project fork:

"react-native-fcm": "git@github.com:jpventura/react-native-fcm.git#bugfix/issue-1111"

however it would be cleaner if the solution was merged, because I don't intent keeping the fork alive forever 😉

I have the same issue. If any one found working solution can pls share.

Since I only depended on Android notifications from this module I decided to migrate to react-native-firebase and it was a smooth transition for me.

Resolve by doing this :

android/app/build.gradle

    implementation 'com.google.firebase:firebase-core:16.0.3'
    implementation 'com.google.firebase:firebase-messaging:17.6.0'

android/gradle.properties
At the bottom of file

firebaseCoreVersion=16.0.3
firebaseMessagingVersion=17.6.0

NOTE: No need to change the version of the library or in node_modules code
Just need to update global config using your project gradle.properties file

Cheers guys....

commented

@ravishankar3961 i resolve the problem about build. but. push_notificatioin is not work.

before fix, it worked.

the way get token, is it right?

import FCM from 'react-native-fcm';
const fmc_token = await FCM.getFCMToken().then(token => token);

@yourbob method worked perfectly as well as changing my compiledSdkVersion and targetSdkVersion to 28 in build.gradle(not app one) file. iOS notifications worked fine and since Android is at Oreo i needed to add channel: default to the payload for the notifications to work.

@digitalh2o2 hey, i can get the Fcm Token but when sending the notification to my app i didn't see any notify but in Firebase i see it's done and sent!

I think issue with this file AndroidManifest.xml

FAILURE: Build failed with an exception.

  • What went wrong:
    Execution failed for task ':app:processDebugResources'.

Android resource linking failed

What version are you on @anastely ? I set mine to 16.1.0 and classpath 'com.google.gms:google-services:4.1.0 in my build.gradle file. Also in your build.gradle file make sure to move google() to the top within repositories brackets of buildscript and allprojects

Since I only depended on Android notifications from this module I decided to migrate to react-native-firebase and it was a smooth transition for me.

can you help me on how to migrate from fcm to react-native-firebase?

Resolve by doing this :

android/app/build.gradle

    implementation 'com.google.firebase:firebase-core:16.0.3'
    implementation 'com.google.firebase:firebase-messaging:17.6.0'

android/gradle.properties
At the bottom of file

firebaseCoreVersion=16.0.3
firebaseMessagingVersion=17.6.0

NOTE: No need to change the version of the library or in node_modules code Just need to update global config using your project gradle.properties file

Cheers guys....

I can confirm that this way works, thanks

@axdamx Sure. I'm in react-native-firebase discord.

Can someone explain to me how something that was working fine can suddenly stop working despite not changing anything in my code or package-lock.json (ie with the same dependencies versions) ? I don't understand.

@Sharcoux I had the same thought. Simply put, the module is not locked to a Firebase SDK version. It's implementation broke as it is compiled against a newer Firebase SDK version. It's a not like this moment.

@testshallpasswork Thank you for your answer. I'm not sure about what you mean though. Don't I have everything I need inside my node_modules? If not what is it exactly that is being taken from away? Does it mean that I could not build the app without an internet connection?

@Sharcoux generaly when your android project build, it fetches its natives dependencies on maven, in this case the latest version of firebase sdk, which has deprecated somethings. That's why the fixed version works.

@iamcxa did you face any problem or error building signed apk after following this solution?

I confirm the solution from suresh-borad works!!!

How do you guys find out what version of com.google.firebase:firebase-core available?

I looked at https://firebase.google.com/support/release-notes/android#latest_sdk_versions but only see the latest verison. I would expect the release notes page would have all available versions in it... pretty bad actually

I made some changes in code in below file, and its working now, also receiving notifications successfully:
\node_modules\react-native-fcm\android\src\main\java\com\evollu\react\fcm\InstanceIdService.java file

package com.evollu.react.fcm;

import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.support.v4.content.LocalBroadcastManager;
import android.util.Log;

import com.facebook.react.ReactApplication;
import com.facebook.react.ReactInstanceManager;
import com.facebook.react.bridge.ReactContext;
import com.google.firebase.iid.FirebaseInstanceId;
//import com.google.firebase.iid.FirebaseInstanceIdService; //Commented FirebaseInstanceIdService
import com.google.firebase.messaging.FirebaseMessagingService;  //ADD FirebaseMessagingService

public class InstanceIdService extends FirebaseMessagingService {

    private static final String TAG = "InstanceIdService";

    /**
     * Called if InstanceID token is updated. This may occur if the security of
     * the previous token had been compromised. This call is initiated by the
     * InstanceID provider.
     */
    // [START refresh_token]
    @Override
    public void onNewToken(String token) { //Added onNewToken method
        // Get updated InstanceID token.
        String refreshedToken = FirebaseInstanceId.getInstance().getToken();
        Log.d(TAG, "Refreshed token: " + refreshedToken);

        // Broadcast refreshed token
        Intent i = new Intent("com.evollu.react.fcm.FCMRefreshToken");
        Bundle bundle = new Bundle();
        bundle.putString("token", refreshedToken);
        i.putExtras(bundle);

        final Intent message = i;

        Handler handler = new Handler(Looper.getMainLooper());
        handler.post(new Runnable() {
            public void run() {
                // Construct and load our normal React JS code bundle
                ReactInstanceManager mReactInstanceManager = ((ReactApplication) getApplication()).getReactNativeHost().getReactInstanceManager();
                ReactContext context = mReactInstanceManager.getCurrentReactContext();
                // If it's constructed, send a notification
                if (context != null) {
                    LocalBroadcastManager.getInstance(getApplicationContext()).sendBroadcast(message);
                } else {
                    // Otherwise wait for construction, then send the notification
                    mReactInstanceManager.addReactInstanceEventListener(new ReactInstanceManager.ReactInstanceEventListener() {
                        public void onReactContextInitialized(ReactContext context) {
                            LocalBroadcastManager.getInstance(getApplicationContext()).sendBroadcast(message);
                        }
                    });
                    if (!mReactInstanceManager.hasStartedCreatingInitialContext()) {
                        // Construct it in the background
                        mReactInstanceManager.createReactContextInBackground();
                    }
                }
            }
        });
    }
}

Edit: i don't know if it is right thing to do or not, can anyone confirm ?

maybe use

        <!--<intent-filter>-->
          <!--<action android:name="com.google.firebase.INSTANCE_ID_EVENT"/>-->
        <!--</intent-filter>-->
    <!--</service>-->

and add public void onNewToken(String s) in MessagingService

@TomYan2255 this answer has saved my life. Can I buy you a beer?

How do you guys find out what version of com.google.firebase:firebase-core available?

I looked at https://firebase.google.com/support/release-notes/android#latest_sdk_versions but only see the latest verison. I would expect the release notes page would have all available versions in it... pretty bad actually

@ptgamr see the full list here - https://developers.google.com/android/guides/releases

I made some changes in code in below file, and its working now, also receiving notifications successfully:
\node_modules\react-native-fcm\android\src\main\java\com\evollu\react\fcm\InstanceIdService.java file

package com.evollu.react.fcm;

import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.support.v4.content.LocalBroadcastManager;
import android.util.Log;

import com.facebook.react.ReactApplication;
import com.facebook.react.ReactInstanceManager;
import com.facebook.react.bridge.ReactContext;
import com.google.firebase.iid.FirebaseInstanceId;
//import com.google.firebase.iid.FirebaseInstanceIdService; //Commented FirebaseInstanceIdService
import com.google.firebase.messaging.FirebaseMessagingService;  //ADD FirebaseMessagingService

public class InstanceIdService extends FirebaseMessagingService {

    private static final String TAG = "InstanceIdService";

    /**
     * Called if InstanceID token is updated. This may occur if the security of
     * the previous token had been compromised. This call is initiated by the
     * InstanceID provider.
     */
    // [START refresh_token]
    @Override
    public void onNewToken(String token) { //Added onNewToken method
        // Get updated InstanceID token.
        String refreshedToken = FirebaseInstanceId.getInstance().getToken();
        Log.d(TAG, "Refreshed token: " + refreshedToken);

        // Broadcast refreshed token
        Intent i = new Intent("com.evollu.react.fcm.FCMRefreshToken");
        Bundle bundle = new Bundle();
        bundle.putString("token", refreshedToken);
        i.putExtras(bundle);

        final Intent message = i;

        Handler handler = new Handler(Looper.getMainLooper());
        handler.post(new Runnable() {
            public void run() {
                // Construct and load our normal React JS code bundle
                ReactInstanceManager mReactInstanceManager = ((ReactApplication) getApplication()).getReactNativeHost().getReactInstanceManager();
                ReactContext context = mReactInstanceManager.getCurrentReactContext();
                // If it's constructed, send a notification
                if (context != null) {
                    LocalBroadcastManager.getInstance(getApplicationContext()).sendBroadcast(message);
                } else {
                    // Otherwise wait for construction, then send the notification
                    mReactInstanceManager.addReactInstanceEventListener(new ReactInstanceManager.ReactInstanceEventListener() {
                        public void onReactContextInitialized(ReactContext context) {
                            LocalBroadcastManager.getInstance(getApplicationContext()).sendBroadcast(message);
                        }
                    });
                    if (!mReactInstanceManager.hasStartedCreatingInitialContext()) {
                        // Construct it in the background
                        mReactInstanceManager.createReactContextInBackground();
                    }
                }
            }
        });
    }
}

Edit: i don't know if it is right thing to do or not, can anyone confirm ?

For those of you who still use this library. Here is InstanceIdService with AndroidX support: 😄

package com.evollu.react.fcm;

import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import androidx.localbroadcastmanager.content.LocalBroadcastManager;
import android.util.Log;

import com.facebook.react.ReactApplication;
import com.facebook.react.ReactInstanceManager;
import com.facebook.react.bridge.ReactContext;
import com.google.firebase.iid.FirebaseInstanceId;
//import com.google.firebase.iid.FirebaseInstanceIdService; //Commented FirebaseInstanceIdService
import com.google.firebase.messaging.FirebaseMessagingService;  //ADD FirebaseMessagingService

public class InstanceIdService extends FirebaseMessagingService {

    private static final String TAG = "InstanceIdService";

    /**
     * Called if InstanceID token is updated. This may occur if the security of
     * the previous token had been compromised. This call is initiated by the
     * InstanceID provider.
     */
    // [START refresh_token]
    @Override
    public void onNewToken(String token) { //Added onNewToken method
        // Get updated InstanceID token.
        String refreshedToken = FirebaseInstanceId.getInstance().getToken();
        Log.d(TAG, "Refreshed token: " + refreshedToken);

        // Broadcast refreshed token
        Intent i = new Intent("com.evollu.react.fcm.FCMRefreshToken");
        Bundle bundle = new Bundle();
        bundle.putString("token", refreshedToken);
        i.putExtras(bundle);

        final Intent message = i;

        Handler handler = new Handler(Looper.getMainLooper());
        handler.post(new Runnable() {
            public void run() {
                // Construct and load our normal React JS code bundle
                ReactInstanceManager mReactInstanceManager = ((ReactApplication) getApplication()).getReactNativeHost().getReactInstanceManager();
                ReactContext context = mReactInstanceManager.getCurrentReactContext();
                // If it's constructed, send a notification
                if (context != null) {
                    LocalBroadcastManager.getInstance(getApplicationContext()).sendBroadcast(message);
                } else {
                    // Otherwise wait for construction, then send the notification
                    mReactInstanceManager.addReactInstanceEventListener(new ReactInstanceManager.ReactInstanceEventListener() {
                        public void onReactContextInitialized(ReactContext context) {
                            LocalBroadcastManager.getInstance(getApplicationContext()).sendBroadcast(message);
                        }
                    });
                    if (!mReactInstanceManager.hasStartedCreatingInitialContext()) {
                        // Construct it in the background
                        mReactInstanceManager.createReactContextInBackground();
                    }
                }
            }
        });
    }
}

I made some changes in code in below file, and its working now, also receiving notifications successfully:
\node_modules\react-native-fcm\android\src\main\java\com\evollu\react\fcm\InstanceIdService.java file

package com.evollu.react.fcm;

import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.support.v4.content.LocalBroadcastManager;
import android.util.Log;

import com.facebook.react.ReactApplication;
import com.facebook.react.ReactInstanceManager;
import com.facebook.react.bridge.ReactContext;
import com.google.firebase.iid.FirebaseInstanceId;
//import com.google.firebase.iid.FirebaseInstanceIdService; //Commented FirebaseInstanceIdService
import com.google.firebase.messaging.FirebaseMessagingService;  //ADD FirebaseMessagingService

public class InstanceIdService extends FirebaseMessagingService {

    private static final String TAG = "InstanceIdService";

    /**
     * Called if InstanceID token is updated. This may occur if the security of
     * the previous token had been compromised. This call is initiated by the
     * InstanceID provider.
     */
    // [START refresh_token]
    @Override
    public void onNewToken(String token) { //Added onNewToken method
        // Get updated InstanceID token.
        String refreshedToken = FirebaseInstanceId.getInstance().getToken();
        Log.d(TAG, "Refreshed token: " + refreshedToken);

        // Broadcast refreshed token
        Intent i = new Intent("com.evollu.react.fcm.FCMRefreshToken");
        Bundle bundle = new Bundle();
        bundle.putString("token", refreshedToken);
        i.putExtras(bundle);

        final Intent message = i;

        Handler handler = new Handler(Looper.getMainLooper());
        handler.post(new Runnable() {
            public void run() {
                // Construct and load our normal React JS code bundle
                ReactInstanceManager mReactInstanceManager = ((ReactApplication) getApplication()).getReactNativeHost().getReactInstanceManager();
                ReactContext context = mReactInstanceManager.getCurrentReactContext();
                // If it's constructed, send a notification
                if (context != null) {
                    LocalBroadcastManager.getInstance(getApplicationContext()).sendBroadcast(message);
                } else {
                    // Otherwise wait for construction, then send the notification
                    mReactInstanceManager.addReactInstanceEventListener(new ReactInstanceManager.ReactInstanceEventListener() {
                        public void onReactContextInitialized(ReactContext context) {
                            LocalBroadcastManager.getInstance(getApplicationContext()).sendBroadcast(message);
                        }
                    });
                    if (!mReactInstanceManager.hasStartedCreatingInitialContext()) {
                        // Construct it in the background
                        mReactInstanceManager.createReactContextInBackground();
                    }
                }
            }
        });
    }
}

Edit: i don't know if it is right thing to do or not, can anyone confirm ?

@ravishankar3961 trying to apply your fix but doesn't seem to work for me. I have react-native-fcm version 11.3.1

I am seeing this in "instanceIdService.java" file
image

@Base29 What is your project's RN version? This looks like AndroidX support error. Try adding support for AndroidX.

@ravishankar3961 RN version is 0.59.10. What is the best way of adding androidx support?

@Base29 You can visit this blog to understand and implement the AndroidX support.

@Base29 some news?
Here it just started happens out of the blue, without any change or update in the project and development environment..

@gustavogialimvizir same thing here, started happening about hour ago

Do anyone have an idea what to do in such cases?

@gustavogialimvizir @nikolaywithpara same here, but got this issue in react-native-push-notification

@gustavogialimvizir Same here... both our projects uses react-native-push-notification and now we can't build both of them on Android all of the sudden.

@gustavogialimvizir @isnifer @Helen2hang

Try to add implementation 'com.google.firebase:firebase-messaging:21.1.0' to app/build.gradle and
firebaseMessagingVersion=21.1.0 to gradle.properties. Worked for me

@nikolaywithpara you rock. It worked for me.

Thank you so much @nikolaywithpara. It has worked successfully.

Previously running application has failed com.google.firebase.iid.FirebaseInstanceIdService.This worked for me. I hope I can help you
android/build.gradle
ext {
...
firebaseMessagingVersion = "21.1.0"
}
package.json
"react-native-push-notification": "^3.5.2",

Previously running application has failed com.google.firebase.iid.FirebaseInstanceIdService.This worked for me. I hope I can help you
android/build.gradle
ext {
...
firebaseMessagingVersion = "21.1.0"
}
package.json
"react-native-push-notification": "^3.5.2",

Adding the firebaseMessagingVersion line worked for me, no need to specify the react-native-push-notification version (although it's still probably a good idea to do so...)

@gustavogialimvizir @isnifer @Helen2hang

Try to add implementation 'com.google.firebase:firebase-messaging:21.1.0' to app/build.gradle and
firebaseMessagingVersion=21.1.0 to gradle.properties. Worked for me

didnt work for me :(

commented

@gustavogialimvizir @isnifer @Helen2hang

Try to add implementation 'com.google.firebase:firebase-messaging:21.1.0' to app/build.gradle and
firebaseMessagingVersion=21.1.0 to gradle.properties. Worked for me

Fantastic! It worked. Thanks a lot