react-native-firebase通知崩溃

时间:2018-10-03 16:04:31

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

在模拟器中使用Android OS 8.1.0的Android设备上收到通知时,应用程序崩溃。这是在应用程序中发生的。当我不在应用程序中并且通知在通知托盘中到达时,不会发生这种情况。 但是,在实际设备上,它同时发生在内部和外部(?)。 对于Android 5.0.0,崩溃不会发生。

Crashlytics中的错误是:

$str = '{  "images": ....  }'; 

// get associative array from json
$result = json_decode($str, true)['images'];
foreach ($result as $imgage => $classifiers) {
    foreach ($classifiers["classifiers"] as $classifier) {
        foreach ($classifier["classes"] as $clas) {
            foreach ($clas as $key => $value) {
                // you can add condition here to target only desired keys
                echo $key . ": " . $value;
            }
        }
    }
}

以及:

Caused by java.lang.NoSuchMethodError: No direct method <init>(Landroid/content/Context;Ljava/lang/String;)V in class Landroid/support/v4/app/NotificationCompat$Builder; or its super classes (declaration of 'android.support.v4.app.NotificationCompat$Builder' appears in /data/app/com.parkour2342345-zqe_7U0B_6slVtK2mLk6RA==/base.apk!classes2.dex)
       at io.invertase.firebase.notifications.DisplayNotificationTask.doInBackground(DisplayNotificationTask.java:68)
       at io.invertase.firebase.notifications.DisplayNotificationTask.doInBackground(DisplayNotificationTask.java:31)
       at android.os.AsyncTask$2.call(AsyncTask.java:333)
       at java.util.concurrent.FutureTask.run(FutureTask.java:266)
       at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:245)
       at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1162)
       at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:636)
       at java.lang.Thread.run(Thread.java:764)

我的react-native-firebase的build.gradle包含:

Fatal Exception: java.lang.RuntimeException: An error occurred while executing doInBackground()
       at android.os.AsyncTask$3.done(AsyncTask.java:353)
       at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:383)
       at java.util.concurrent.FutureTask.setException(FutureTask.java:252)
       at java.util.concurrent.FutureTask.run(FutureTask.java:271)
       at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:245)
       at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1162)
       at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:636)
       at java.lang.Thread.run(Thread.java:764)

我已在此发布问题: https://github.com/invertase/react-native-firebase/issues/1553

环境

应用目标平台: Android

开发操作系统: macOS High Sierra 10.13.6

构建工具: Android Studio:3.1 AI-173.4670197

反应本机版本: 0.54.4 => 0.54.4

React Native Firebase版本: 4.3.8

Firebase模块: 消息

您在使用打字稿吗? 否


更新#1:

在react-native-navigation的build.gradle中:

def DEFAULT_COMPILE_SDK_VERSION = 27
def DEFAULT_BUILD_TOOLS_VERSION = "27.0.3"
def DEFAULT_TARGET_SDK_VERSION = 26
def DEFAULT_FIREBASE_VERSION = "12.0.0"
def DEFAULT_SUPPORT_LIB_VERSION = "27.0.2"

android {
  compileSdkVersion rootProject.hasProperty('compileSdkVersion') ? rootProject.compileSdkVersion : DEFAULT_COMPILE_SDK_VERSION
  buildToolsVersion rootProject.hasProperty('buildToolsVersion') ? rootProject.buildToolsVersion : DEFAULT_BUILD_TOOLS_VERSION
  defaultConfig {
    minSdkVersion 16
    targetSdkVersion rootProject.hasProperty('targetSdkVersion') ? rootProject.targetSdkVersion : DEFAULT_TARGET_SDK_VERSION
    versionCode 1
    versionName "1.0"
    multiDexEnabled true
  }

在项目中似乎没有定义supportLibVersion,因此我假设它将继承文件中的值。此外,尽管重建项目可以正常进行,但它确实将线条突出显示为红色。 enter image description here

1 个答案:

答案 0 :(得分:1)

经过数小时的挫折后的

解决方案: 1)淘汰线: api“ com.android.support:support-v4:$supportVersion”

2)将sdk更改为27。 定义DEFAULT_TARGET_SDK_VERSION = 27

从表面上看,这些都不能解决这个问题,但是他们做到了……