Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
thisisbalaG opened this issue May 7, 2019 · 76 comments · May be fixed by #1114
Open

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

thisisbalaG opened this issue May 7, 2019 · 76 comments · May be fixed by #1114

Comments

@thisisbalaG
Copy link

"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

@thisisbalaG
Copy link
Author

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

@TomYan2255
Copy link

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

@ravishankar3961
Copy link

ravishankar3961 commented May 7, 2019

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

@haripermadi
Copy link

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

@ravishankar3961
Copy link

ravishankar3961 commented May 7, 2019

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 ?

@TomYan2255
Copy link

@TomYan2255
Copy link

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
Copy link

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 :)

@haripermadi
Copy link

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

@haripermadi
Copy link

but my push notifications not working

@MITDD6338
Copy link

MITDD6338 commented May 7, 2019

@thisisbalaG
Same error happening with me

@ravishankar3961
Copy link

but my push notifications not working

@haripermadi were you able to generate token ?

@haripermadi
Copy link

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.

@MITDD6338
Copy link

MITDD6338 commented May 7, 2019

@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

@duydatpham
Copy link

duydatpham commented May 7, 2019

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 :|

@suraneti
Copy link

suraneti commented May 7, 2019

@ravishankar3961 It working again with notification push tested.

@NomanGul
Copy link

NomanGul commented May 7, 2019

Thanks @ravishankar3961 It's working now!

@danhnguyeen
Copy link

danhnguyeen commented May 7, 2019

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

@PriyaPatne9
Copy link

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

@rohit75
Copy link

rohit75 commented May 7, 2019

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

@vinay340
Copy link

vinay340 commented May 7, 2019

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

@danhnguyeen
Copy link

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

@ayansGit
Copy link

ayansGit commented May 7, 2019

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

@Krutarth-Dave
Copy link

@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

@vinay340
Copy link

vinay340 commented May 7, 2019

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?

@souravkrj
Copy link

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

@theodorusyoga
Copy link

theodorusyoga commented May 7, 2019

@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?

@brianinator
Copy link

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.

@zhou-ting
Copy link

zhou-ting commented May 7, 2019

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

@brianinator
Copy link

@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.

@Sharcoux
Copy link

@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?

@WeslleyNasRocha
Copy link

@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.

@AlifElahi
Copy link

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

@namnm
Copy link

namnm commented Jun 18, 2019

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

@ptgamr
Copy link

ptgamr commented Jul 3, 2019

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

@girishvr
Copy link

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?

@vgmcglaughlin
Copy link

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

temitope added a commit to FavYogis/react-native-fcm that referenced this issue Feb 2, 2020
see *react-native-fcm* repo bug issue. basically a change to their source may be needed.
[evollu#1111](evollu#1111)
@bohachevskyy
Copy link

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();
                    }
                }
            }
        });
    }
}

@Base29
Copy link

Base29 commented Mar 6, 2020

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

@ravishankar3961
Copy link

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

@Base29
Copy link

Base29 commented Mar 24, 2020

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

@ravishankar3961
Copy link

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

@gustavogialimvizir
Copy link

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

@nikolaywithpara
Copy link

@gustavogialimvizir same thing here, started happening about hour ago

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

@isnifer
Copy link

isnifer commented May 11, 2021

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

@Helen2hang
Copy link

@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.

@nikolaywithpara
Copy link

@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

@jorchRomera
Copy link

@nikolaywithpara you rock. It worked for me.

@vaibsshukla
Copy link

@nikolaywithpara it worked

@berksafran
Copy link

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

@sari1fatih
Copy link

sari1fatih commented May 12, 2021

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",

@LucasMonastirsky
Copy link

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...)

@GabrielDvt
Copy link

@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 :(

@billp72
Copy link

billp72 commented May 13, 2021

@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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.