簡體   English   中英

evollu / react-native-fcm-ClassNotFoundException

[英]evollu/react-native-fcm - ClassNotFoundException

我的應用程序運行良好,但是...當它從Firebase接收到通知時崩潰。

我認為這是因為我實現了“ react-native-fcm”示例而導致配置錯誤。

我getFCMToken()成功。

你看有什么錯誤嗎? 你知道為什么會這樣嗎? 有想法嗎? 救命!!

控制台錯誤

package.json

"dependencies": {
    "firebase": "^4.8.2",
    "lodash": "^4.17.4",
    "moment": "^2.20.1",
    "react": "16.0.0-alpha.12",
    "react-firebase-storage-connector": "^1.1.0",
    "react-native": "0.47",
    "react-native-fbsdk": "^0.7.0",
    "react-native-fcm": "^13.3.1",
    "react-native-fetch-blob": "^0.10.8",
    "react-native-image-picker": "^0.26.7",
    "react-native-modal": "^5.0.0",
    "react-native-responsive-image": "^2.2.0",
    "react-native-side-menu": "^1.1.3",
    "react-native-textinput-effects": "^0.4.2",
    "react-native-vector-icons": "^4.5.0",
    "react-navigation": "^1.0.0-beta.11",
    "react-redux": "^5.0.6",
    "redux": "^3.7.2",
    "redux-thunk": "^2.2.0",
    "slugify": "^1.2.9"
},

app / build.gradlew

      compileSdkVersion 27
      buildToolsVersion "27.0.1"

      defaultConfig {
          applicationId "com.reactnavigationdrawer"
          minSdkVersion 16
          targetSdkVersion 22
          versionCode 1
          versionName "1.0"
          ndk {
              abiFilters "armeabi-v7a", "x86"
          }
      }

  dependencies {
      compile fileTree(dir: "libs", include: ["*.jar"])
      compile "com.android.support:appcompat-v7:+"
      compile "com.facebook.react:react-native:+"  // From node_modules
      compile(project(':react-native-fbsdk')) {
       exclude(group: 'com.facebook.android', module: 'facebook-android-sdk')
      }
      compile('com.facebook.android:facebook-android-sdk:4.22.1')
      compile ("com.google.android.gms:play-services-base:11.2.0") {
        force = true;
     }
      compile ('com.google.firebase:firebase-core:11.2.0') {
          force = true;
      }
      compile ('com.google.firebase:firebase-auth:11.2.0') {
          force = true;
      }
      compile (project(':react-native-fcm')){
          exclude group: "com.google.firebase"
      }
      compile ("com.google.android.gms:play-services-gcm:11.2.0") {
          force = true;
      }
      compile project(':react-native-vector-icons')
      compile project(':react-native-fetch-blob')
      compile project(':react-native-image-picker')

  }

  apply plugin: 'com.google.gms.google-services'

build.gradlew

    dependencies {
        classpath 'com.android.tools.build:gradle:2.2.+' // <- USE 2.2.+ version
        classpath 'com.android.tools.build:gradle:2.2.3'
        classpath 'com.google.gms:google-services:3.0.0'
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }

MainActivity.java

  package com.reactnavigationdrawer;

  import com.facebook.react.ReactActivity;
  import android.content.Intent;

  public class MainActivity extends ReactActivity {

      @Override
      public void onNewIntent (Intent intent) {
          super.onNewIntent(intent);
          setIntent(intent);
      }

      @Override
      public void onActivityResult(int requestCode, int resultCode, Intent data) {
          super.onActivityResult(requestCode, resultCode, data);
          MainApplication.getCallbackManager().onActivityResult(requestCode, resultCode, data);
      }

      @Override
      protected String getMainComponentName() {
          return "reactnavigationdrawer";
      }
  }

MainApplication.java

  @Override
  protected List<ReactPackage> getPackages() {
     return Arrays.<ReactPackage>asList(
        new MainReactPackage(),
        new VectorIconsPackage(),
        new ImagePickerPackage(),
        new RNFetchBlobPackage(),
        new FIRMessagingPackage(),
        new FBSDKPackage(mCallbackManager)
    );
 }

AndroidManifest.xml

  <manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="com.reactnavigationdrawer"
      android:versionCode="1"
      android:versionName="1.0">

      <uses-permission android:name="android.permission.INTERNET" />
      <uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>
      <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
      <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
      <uses-permission android:name="android.permission.CAMERA" />
      <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
      <uses-permission android:name="android.permission.VIBRATE" />
      <uses-feature android:name="android.hardware.camera" android:required="false"/>
      <uses-feature android:name="android.hardware.camera.autofocus" android:required="false"/>

      <uses-sdk
          android:minSdkVersion="16"
          android:targetSdkVersion="22" />

      <application
        android:name=".MainApplication"
        android:allowBackup="true"
        android:label="@string/app_name"
        android:icon="@mipmap/ic_launcher"
        android:theme="@style/AppTheme">

        <meta-data android:name="com.facebook.sdk.ApplicationId" android:value="@string/facebook_app_id"/>
        <meta-data android:name="com.google.firebase.messaging.default_notification_icon" android:resource="@drawable/ic_launcher"/>

        <service android:name="com.evollu.react.fcm.MessagingService" android:enabled="true" android:exported="true">
           <intent-filter>
             <action android:name="com.google.firebase.MESSAGING_EVENT"/>
           </intent-filter>
        </service>

        <service android:name="com.evollu.react.fcm.InstanceIdService" android:exported="false">
           <intent-filter>
             <action android:name="com.google.firebase.INSTANCE_ID_EVENT"/>
           </intent-filter>
        </service>

        <receiver android:name="com.evollu.react.fcm.FIRLocalMessagingPublisher"/>
        <receiver android:enabled="true" android:exported="true"  android:name="com.evollu.react.fcm.FIRSystemBootEventReceiver">
            <intent-filter>
                <action android:name="android.intent.action.BOOT_COMPLETED"/>
                <action android:name="android.intent.action.QUICKBOOT_POWERON"/>
                <action android:name="com.htc.intent.action.QUICKBOOT_POWERON"/>
                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
        </receiver>
        <activity
          android:name=".MainActivity"
          android:launchMode="singleTop"
          android:label="@string/app_name"
          android:screenOrientation="portrait"
          android:configChanges="keyboard|keyboardHidden|orientation|screenSize"
          android:windowSoftInputMode="adjustResize">
          <intent-filter>
              <action android:name="android.intent.action.MAIN" />
              <category android:name="android.intent.category.LAUNCHER" />
          </intent-filter>
        </activity>
        <activity android:name="com.facebook.react.devsupport.DevSettingsActivity" />
      </application>
  </manifest>

如果您需要更多信息,請告訴我!

錯誤顯示為...

無法解析 com.evullu.react.fcm.MessagingService的超類

這意味着要么Mainfest.xml中的引用不正確和/或所引用的類com.evullu.react.fcm.MessagingService不存在。 它可能被稱為com.reactnavigationdrawer.MessagingService (或類似名稱),並且也不需要編譯已廢棄的包play-services-gcm

最好為com.google.firebase:firebase-messaging:11.8.0添加一個依賴項,該依賴項應包含com.evullu.react.fcm.MessagingServicesuperclass ,該superclass無法解析。 您可以使用./gradlew app:dependencies | grep firebase進行檢查./gradlew app:dependencies | grep firebase ./gradlew app:dependencies | grep firebase是否存在。

該文件build.gradlew應該稱為build.gradle ,Android Studio可能會抱怨過時的版本...同時是com.android.tools.build:gradle:3.0.1 com.google.gms:google-services:3.1.2 那個force = true; 在那種情況下也似乎沒有用,至少不了解該怎么做,請參見ResolutionStrategy

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM