React Native上的Firebase - 依赖项问题

时间:2018-02-24 11:44:28

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

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

  ...
}

我真的无法找出问题所在。有人有什么想法吗?

1 个答案:

答案 0 :(得分:0)

尝试导入并使用RNFirebaseMessagingPackage代替FIRMessagingPackage

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

还请确保您在packege.json文件中有react-native-fcm,如果没有创建

npm i react-native-fcm --save