【发布时间】:2018-02-24 11:44:27
【问题描述】:
我目前正在尝试在 React Native 上实现 Firebase 云消息传递功能(我想使用通知)。
但是我遇到了一个与依赖项相关的错误。
运行react-native run-android时出现以下错误
D:\wrkfldr\Hiking\android\app\src\main\java\com\hiking\MainApplication.java:6: error: package io.invertase.firebase does not exist
import io.invertase.firebase.RNFirebasePackage;
^
D:\wrkfldr\Hiking\android\app\src\main\java\com\hiking\MainApplication.java:29: error: cannot find symbol
new RNFirebasePackage(),
^
symbol: class RNFirebasePackage
2 errors
:app:compileDebugJavaWithJavac FAILED
FAILURE: Build failed with an exception
这是我的 app\build.gradle 中的依赖项
dependencies {
compile project(':react-native-fcm')
compile 'com.google.firebase:firebase-messaging:11.6.0'
compile "com.google.android.gms:play-services-base:11.6.0"
compile "com.google.firebase:firebase-core:11.6.0"
compile project(':react-native-cardview')
compile fileTree(dir: "libs", include: ["*.jar"])
compile "com.android.support:appcompat-v7:23.0.1"
compile "com.facebook.react:react-native:+" // From node_modules
}
这里是 MainApplication.java
package com.hiking;
import android.app.Application;
import com.facebook.react.ReactApplication;
import io.invertase.firebase.RNFirebasePackage;
import com.kishanjvaghela.cardview.RNCardViewPackage;
import com.facebook.react.ReactNativeHost;
import com.facebook.react.ReactPackage;
import com.facebook.react.shell.MainReactPackage;
import com.evollu.react.fcm.FIRMessagingPackage;
import com.facebook.soloader.SoLoader;
import java.util.Arrays;
import java.util.List;
public class MainApplication extends Application implements ReactApplication {
private final ReactNativeHost mReactNativeHost = new ReactNativeHost(this) {
@Override
public boolean getUseDeveloperSupport() {
return BuildConfig.DEBUG;
}
@Override
protected List<ReactPackage> getPackages() {
return Arrays.<ReactPackage>asList(
new MainReactPackage(),
new RNFirebasePackage(),
new FIRMessagingPackage(),
new RNCardViewPackage()
);
}
@Override
protected String getJSMainModuleName() {
return "index";
}
};
...
}
我真的不知道问题出在哪里。有人知道吗?
【问题讨论】:
-
你用的是什么库?
react-native-firebase? -
是的。检查 package.json 后,我有
"react-native-firebase": "^3.2.7"和"react-native-fcm": "^13.3.1" -
你不需要
react-native-fcm,react-native-firebase已经获得了对云消息的支持:-P,你可以摆脱react-native-fcm并按照这里的说明进行操作rnfirebase.io/docs/v3.2.x/installation/android / rnfirebase.io/docs/v3.2.x/messaging/android -
即使我想使用推送通知?我一直在查看需要
react-native-fcm的evollu。还有其他方法可以实现推送通知吗? -
好吧,如果你只想要推送通知并且不需要来自 firebase 的任何其他东西,你可以去掉
react-native-firebase并使用react-native-fcm(你必须删除 @ 987654337@ 和new RNFirebasePackage()来自您的MainApplication.java)
标签: android firebase react-native firebase-cloud-messaging