Open thisisbalaG opened 5 years ago
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
@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.
@nikolaywithpara it worked
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'
toapp/build.gradle
andfirebaseMessagingVersion=21.1.0
togradle.properties
. Worked for me
didnt work for me :(
@gustavogialimvizir @isnifer @Helen2hang
Try to add
implementation 'com.google.firebase:firebase-messaging:21.1.0'
toapp/build.gradle
andfirebaseMessagingVersion=21.1.0
togradle.properties
. Worked for me
Fantastic! It worked. Thanks a lot
"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