【问题标题】:Firebase on React Native - dependencies issueReact Native 上的 Firebase - 依赖问题
【发布时间】: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-fcmreact-native-firebase 已经获得了对云消息的支持:-P,你可以摆脱react-native-fcm 并按照这里的说明进行操作rnfirebase.io/docs/v3.2.x/installation/android / rnfirebase.io/docs/v3.2.x/messaging/android
  • 即使我想使用推送通知?我一直在查看需要react-native-fcmevollu。还有其他方法可以实现推送通知吗?
  • 好吧,如果你只想要推送通知并且不需要来自 firebase 的任何其他东西,你可以去掉 react-native-firebase 并使用 react-native-fcm(你必须删除 @ 987654337@ 和 new RNFirebasePackage() 来自您的MainApplication.java)

标签: android firebase react-native firebase-cloud-messaging


【解决方案1】:

尝试导入并使用 RNFirebaseMessagingPackage 而不是 FIRMessagingPackage

...
import io.invertase.firebase.messaging.RNFirebaseMessagingPackage;
...
new RNFirebaseMessagingPackage(),
...

还要确保你在 packege.json 文件中有 react-native-fcm,如果没有 make

npm i react-native-fcm --save

【讨论】:

    猜你喜欢
    • 2021-12-05
    • 1970-01-01
    • 2020-05-19
    • 1970-01-01
    • 2020-12-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-09-29
    相关资源
    最近更新 更多