Nicoara Talpes
Nicoara Talpes

Reputation: 720

react-native-firebase notification crash

App crashes when receiving a notification on Android device with Android OS 8.1.0, in simulator. This happens while in the app. It does not happen when I am outside the app and the notification arrives fine in the notification tray. On a real device though, it happens both inside and outside (?). The crash does not happen for Android 5.0.0.

The error in Crashlytics is :

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)

as well as:

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)

My build.gradle for react-native-firebase contains:

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
  }

I have posted the issue here: https://github.com/invertase/react-native-firebase/issues/1553

Environment

Application Target Platform: Android

Development Operating System: macOS High Sierra 10.13.6

Build Tools: Android Studio: 3.1 AI-173.4670197

React Native version: 0.54.4 => 0.54.4

React Native Firebase Version: 4.3.8

Firebase Module: messaging

Are you using typescript? no


update #1:

in react-native-navigation's build.gradle:

def DEFAULT_SUPPORT_LIB_VERSION = "27.0.2"
...
def supportVersion = rootProject.hasProperty('supportLibVersion') ? rootProject.supportLibVersion : DEFAULT_SUPPORT_LIB_VERSION

dependencies {
  // compile fileTree(include: ['*.jar'], dir: 'libs')
  api "com.facebook.react:react-native:+"  // From node_modules
  api "com.android.support:support-v4:$supportVersion"

there does not appear to be a supportLibVersion defined in the project, so I assume It will inherit the value in the file. Also, although rebuilding the project works, it does highlight the line as red. enter image description here

Upvotes: 2

Views: 1741

Answers (1)

Nicoara Talpes
Nicoara Talpes

Reputation: 720

solution, after hours of frustration: 1) eliminated line: api "com.android.support:support-v4:$supportVersion"

2) changed sdk to 27. def DEFAULT_TARGET_SDK_VERSION = 27

on face value, none of these should fix this, but they did...

Upvotes: 2

Related Questions