React Native上的Firebase - 依赖项问题

问题描述 投票:0回答:1

我目前正在尝试在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";
    }
  };

  ...
}

我真的无法弄清问题在哪里。有人有什么想法吗?

android firebase react-native firebase-cloud-messaging
1个回答
0
投票

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

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

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

npm i react-native-fcm --save
© www.soinside.com 2019 - 2024. All rights reserved.