Недавно я клонировал новый проект и попытался react-native run-android
К сожалению, по некоторым причинам я не могу запустить свой проект, и терминал показывает мне эту ошибку: > Task :react-native-firebase:compileDebugJavaWithJavac FAILED
, и выше этой ошибки я увидел больше информации об этом подробно => 'не могу найти символ импорта com.google.firebase. iid.FirebaseInstanceIdService;»
.
Я много искал эту проблему и обнаружил, что «FirebaseInstanceIdService» устарел, поэтому я должен прокомментировать import com.google.firebase.iid.FirebaseInstanceIdService;
в InstanceIdService.java, расположенном в => \node_modules\react-native-fcm\android\src\main\java\com\evollu\react\fcm\InstanceIdService.java
, кроме того, я должен также внести некоторые другие изменения. но я снова получаю ту же ошибку.
Содержимое InstanceIdService.java (до внесения каких-либо изменений):
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;
public class InstanceIdService extends FirebaseInstanceIdService {
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 onTokenRefresh() {
// 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();
}
}
}
});
}
}
Содержание отредактированного InstanceIdService.java:
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 {
public class MyFireBaseInstanceIDService extends FirebaseMessagingService {
private static final String TAG = "InstanceIdService";
// private static final String TAG = MyFireBaseInstanceIDService.class.getSimpleName();;
/**
* 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();
}
}
}
});
}
}
Обратите внимание, что: У меня одна и та же проблема как в react-native-fcm
, так и в react-native-firebase
, похоже, мне нужно внести некоторые изменения в 'RNFirebaseInstanceIdService.java
' и 'RNFirebasePerformance.java
'
ПРОСТО ДОБАВИЛ ЭТОТ ЗАПИСЬ ПОСЛЕ ТОГО, КАК Я РЕШЕН СЕБЕ ПРОБЛЕМА ::
это вообще не про реактив-native-fcm! это было все о реактивном-собственном-firebase, как я уже говорил, хотя устаревший 'instanceIdService' существует в реактивном-родном-fcm, который когда-то я пытался внести некоторые изменения.
Спасибо