react-native-firebase icon indicating copy to clipboard operation
react-native-firebase copied to clipboard

Android App crashes on release build while receiving notification from FCM in background

Open ashishkumar1000 opened this issue 6 years ago • 7 comments

Issue

Describe your issue here I have recently implemented @react-native-firebase_messaging to send notification from firebase. My react native app is working fine in debug mode and notification are getting delivered.

while In release build, when I send a notification and app is either killed or in background state it crashes while starting some headlessTask.

com.facebook.react.common.c: undefined is not an object (evaluating 's()(o).then'), stack:

Please find the details logs below:

04-10 04:10:02.843 12132 12173 E AndroidRuntime: FATAL EXCEPTION: mqt_native_modules 04-10 04:10:02.843 12132 12173 E AndroidRuntime: Process: com.makemytripseller, PID: 12132 04-10 04:10:02.843 12132 12173 E AndroidRuntime: com.facebook.react.common.c: undefined is not an object (evaluating 's()(o).then'), stack: 04-10 04:10:02.843 12132 12173 E AndroidRuntime: startHeadlessTask@306:3226 04-10 04:10:02.843 12132 12173 E AndroidRuntime: value@35:3518 04-10 04:10:02.843 12132 12173 E AndroidRuntime: @35:822 04-10 04:10:02.843 12132 12173 E AndroidRuntime: value@35:2772 04-10 04:10:02.843 12132 12173 E AndroidRuntime: value@35:794 04-10 04:10:02.843 12132 12173 E AndroidRuntime: value@-1 04-10 04:10:02.843 12132 12173 E AndroidRuntime: 04-10 04:10:02.843 12132 12173 E AndroidRuntime: at com.facebook.react.modules.core.ExceptionsManagerModule.showOrThrowError(Unknown Source:20) 04-10 04:10:02.843 12132 12173 E AndroidRuntime: at com.facebook.react.modules.core.ExceptionsManagerModule.reportFatalException(Unknown Source:0) 04-10 04:10:02.843 12132 12173 E AndroidRuntime: at java.lang.reflect.Method.invoke(Native Method) 04-10 04:10:02.843 12132 12173 E AndroidRuntime: at com.facebook.react.bridge.JavaMethodWrapper.invoke(Unknown Source:149) 04-10 04:10:02.843 12132 12173 E AndroidRuntime: at com.facebook.react.bridge.JavaModuleWrapper.invoke(Unknown Source:21) 04-10 04:10:02.843 12132 12173 E AndroidRuntime: at com.facebook.react.bridge.queue.NativeRunnable.run(Native Method) 04-10 04:10:02.843 12132 12173 E AndroidRuntime: at android.os.Handler.handleCallback(Handler.java:883) 04-10 04:10:02.843 12132 12173 E AndroidRuntime: at android.os.Handler.dispatchMessage(Handler.java:100) 04-10 04:10:02.843 12132 12173 E AndroidRuntime: at com.facebook.react.bridge.queue.MessageQueueThreadHandler.dispatchMessage(Unknown Source:0) 04-10 04:10:02.843 12132 12173 E AndroidRuntime: at android.os.Looper.loop(Looper.java:214) 04-10 04:10:02.843 12132 12173 E AndroidRuntime: at com.facebook.react.bridge.queue.MessageQueueThreadImpl$4.run(Unknown Source:37) 04-10 04:10:02.843 12132 12173 E AndroidRuntime: at java.lang.Thread.run(Thread.java:919) 04-10 04:10:02.850 12132 12173 D io.sentry.i.b.a.a: Proguard UUIDs file not found.

Project Files

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript { ext { buildToolsVersion = "28.0.3" minSdkVersion = 16 compileSdkVersion = 28 targetSdkVersion = 28 supportLibVersion = "28.0.0" } repositories { google() jcenter() } dependencies { classpath('com.android.tools.build:gradle:3.5.3') classpath("com.google.gms:google-services:4.2.0") // NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files } }

allprojects { repositories { mavenLocal() maven { // All of React Native (JS, Obj-C sources, Android binaries) is installed from npm url("$rootDir/../node_modules/react-native/android") } maven { // Android JSC is installed from npm url("$rootDir/../node_modules/jsc-android/dist") }

    google()
    jcenter()
}

}

apply plugin: "com.android.application" apply plugin: 'com.google.gms.google-services'

import com.android.build.OutputFile

/**

  • The react.gradle file registers a task for each build variant (e.g. bundleDebugJsAndAssets
  • and bundleReleaseJsAndAssets).
  • These basically call react-native bundle with the correct arguments during the Android build
  • cycle. By default, bundleDebugJsAndAssets is skipped, as in debug/dev mode we prefer to load the
  • bundle directly from the development server. Below you can see all the possible configurations
  • and their defaults. If you decide to add a configuration block, make sure to add it before the
  • apply from: "../../node_modules/react-native/react.gradle" line. *
  • project.ext.react = [
  • // the name of the generated asset file containing your JS bundle
  • bundleAssetName: "index.android.bundle", *
  • // the entry file for bundle generation
  • entryFile: "index.android.js", *
  • // https://facebook.github.io/react-native/docs/performance#enable-the-ram-format
  • bundleCommand: "ram-bundle", *
  • // whether to bundle JS and assets in debug mode
  • bundleInDebug: false, *
  • // whether to bundle JS and assets in release mode
  • bundleInRelease: true, *
  • // whether to bundle JS and assets in another build variant (if configured).
  • // See http://tools.android.com/tech-docs/new-build-system/user-guide#TOC-Build-Variants
  • // The configuration property can be in the following formats
  • // 'bundleIn${productFlavor}${buildType}'
  • // 'bundleIn${buildType}'
  • // bundleInFreeDebug: true,
  • // bundleInPaidRelease: true,
  • // bundleInBeta: true, *
  • // whether to disable dev mode in custom build variants (by default only disabled in release)
  • // for example: to disable dev mode in the staging build type (if configured)
  • devDisabledInStaging: true,
  • // The configuration property can be in the following formats
  • // 'devDisabledIn${productFlavor}${buildType}'
  • // 'devDisabledIn${buildType}' *
  • // the root of your project, i.e. where "package.json" lives
  • root: "../../", *
  • // where to put the JS bundle asset in debug mode
  • jsBundleDirDebug: "$buildDir/intermediates/assets/debug", *
  • // where to put the JS bundle asset in release mode
  • jsBundleDirRelease: "$buildDir/intermediates/assets/release", *
  • // where to put drawable resources / React Native assets, e.g. the ones you use via
  • // require('./image.png')), in debug mode
  • resourcesDirDebug: "$buildDir/intermediates/res/merged/debug", *
  • // where to put drawable resources / React Native assets, e.g. the ones you use via
  • // require('./image.png')), in release mode
  • resourcesDirRelease: "$buildDir/intermediates/res/merged/release", *
  • // by default the gradle tasks are skipped if none of the JS files or assets change; this means
  • // that we don't look at files in android/ or ios/ to determine whether the tasks are up to
  • // date; if you have any other folders that you want to ignore for performance reasons (gradle
  • // indexes the entire tree), add them here. Alternatively, if you have JS files in android/
  • // for example, you might want to remove it from here.
  • inputExcludes: ["android/", "ios/"], *
  • // override which node gets called and with what additional arguments
  • nodeExecutableAndArgs: ["node"], *
  • // supply additional arguments to the packager
  • extraPackagerArgs: []
  • ] */

project.ext.react = [ entryFile: "index.js", enableHermes: false, // clean and rebuild if changing ]

apply from: "../../node_modules/react-native/react.gradle" apply from: "../../node_modules/react-native-sentry/sentry.gradle"

/**

  • Set this to true to create two separate APKs instead of one:
    • An APK that only works on ARM devices
    • An APK that only works on x86 devices
  • The advantage is the size of the APK is reduced by about 4MB.
  • Upload all the APKs to the Play Store and people will download
  • the correct one based on the CPU architecture of their device. */ def enableSeparateBuildPerCPUArchitecture = true

/**

  • Run Proguard to shrink the Java bytecode in release builds. */ def enableProguardInReleaseBuilds = true

/**

  • The preferred build flavor of JavaScriptCore. *
  • For example, to use the international variant, you can use:
  • def jscFlavor = 'org.webkit:android-jsc-intl:+' *
  • The international variant includes ICU i18n library and necessary data
  • allowing to use e.g. Date.toLocaleString and String.localeCompare that
  • give correct results when using with locales other than en-US. Note that
  • this variant is about 6MiB larger per architecture than default. */ def jscFlavor = 'org.webkit:android-jsc:+'

/**

  • Whether to enable the Hermes VM. *
  • This should be set on project.ext.react and mirrored here. If it is not set
  • on project.ext.react, JavaScript will not be compiled to Hermes Bytecode
  • and the benefits of using Hermes will therefore be sharply reduced. */ def enableHermes = project.ext.react.get("enableHermes", false);

android { compileSdkVersion rootProject.ext.compileSdkVersion

compileOptions {
    sourceCompatibility JavaVersion.VERSION_1_8
    targetCompatibility JavaVersion.VERSION_1_8
}

defaultConfig {
    applicationId "com.makemytripseller"
    minSdkVersion rootProject.ext.minSdkVersion
    targetSdkVersion rootProject.ext.targetSdkVersion
    versionCode 9
    versionName "1.9"
    missingDimensionStrategy 'react-native-camera', 'general'
    multiDexEnabled true
}
splits {
    abi {
        reset()
        enable enableSeparateBuildPerCPUArchitecture
        universalApk true  // If true, also generate a universal APK
        include "armeabi-v7a", "x86", "arm64-v8a", "x86_64"
    }
}
signingConfigs {
    debug {
        storeFile file('debug.keystore')
        storePassword 'android'
        keyAlias 'androiddebugkey'
        keyPassword 'android'
    }

    release {
        if (project.hasProperty('MYAPP_RELEASE_STORE_FILE')) {
            storeFile file(MYAPP_RELEASE_STORE_FILE)
            storePassword MYAPP_RELEASE_STORE_PASSWORD
            keyAlias MYAPP_RELEASE_KEY_ALIAS
            keyPassword MYAPP_RELEASE_KEY_PASSWORD
        }
    }
}
buildTypes {
    debug {
        signingConfig signingConfigs.debug
    }
    release {
        // Caution! In production, you need to generate your own keystore file.
        // see https://facebook.github.io/react-native/docs/signed-apk-android.
        signingConfig signingConfigs.release
        minifyEnabled enableProguardInReleaseBuilds
        proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
    }
}

dexOptions {
   javaMaxHeapSize "3g"
}

// applicationVariants are e.g. debug, release
applicationVariants.all { variant ->
    variant.outputs.each { output ->
        // For each separate APK per architecture, set a unique version code as described here:
        // https://developer.android.com/studio/build/configure-apk-splits.html
        def versionCodes = ["armeabi-v7a": 1, "x86": 2, "arm64-v8a": 3, "x86_64": 4]
        def abi = output.getFilter(OutputFile.ABI)
        if (abi != null) {  // null for the universal-debug, universal-release variants
            output.versionCodeOverride =
                    versionCodes.get(abi) * 1048576 + defaultConfig.versionCode
        }

    }
}

packagingOptions {
    pickFirst '**/armeabi-v7a/libc++_shared.so'
    pickFirst '**/x86/libc++_shared.so'
    pickFirst '**/arm64-v8a/libc++_shared.so'
    pickFirst '**/x86_64/libc++_shared.so'
    pickFirst '**/x86/libjsc.so'
    pickFirst '**/armeabi-v7a/libjsc.so'
}

}

dependencies { implementation project(':@react-native-community_async-storage') implementation project(':react-native-camera') implementation project(':react-native-device-info') implementation project(':@react-native-firebase_app') implementation project(':@react-native-firebase_analytics') implementation project(path: ":@react-native-firebase_messaging") implementation project(':react-native-branch') implementation project(':react-native-exit-app') implementation project(':react-native-sentry') implementation project(':react-native-webview') implementation project(':react-native-linear-gradient') implementation "io.branch.sdk.android:library:3.0.4" implementation "com.facebook.react:react-native:+" // From node_modules implementation 'com.android.support:multidex:1.0.3' implementation project(':react-native-notifications')

if (enableHermes) {
  def hermesPath = "../../node_modules/hermesvm/android/";
  debugImplementation files(hermesPath + "hermes-debug.aar")
  releaseImplementation files(hermesPath + "hermes-release.aar")
} else {
  implementation jscFlavor
}

}

// Run this once to be able to run the application with BUCK // puts all compile dependencies into folder libs for BUCK to use task copyDownloadableDepsToLibs(type: Copy) { from configurations.compile into 'libs' }

apply from: file("../../node_modules/@react-native-community/cli-platform-android/native_modules.gradle"); applyNativeModulesAppBuildGradle(project)

Javascript

Click To Expand

package.json:

# N/A

firebase.json for react-native-firebase v6:

# N/A

iOS

Click To Expand

ios/Podfile:

  • [ ] I'm not using Pods
  • [x] I'm using Pods and my Podfile looks like:
# N/A

AppDelegate.m:

// N/A


Android

Click To Expand

Have you converted to AndroidX?

  • [ ] my application is an AndroidX application?
  • [ ] I am using android/gradle.settings jetifier=true for Android compatibility?
  • [ ] I am using the NPM package jetifier for react-native compatibility?

android/build.gradle:

// N/A

android/app/build.gradle:

// N/A

android/settings.gradle:

rootProject.name = 'MakeMyTripSeller'
include ':@react-native-community_async-storage'
project(':@react-native-community_async-storage').projectDir = new File(rootProject.projectDir, '../node_modules/@react-native-community/async-storage/android')
include ':react-native-camera'
project(':react-native-camera').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-camera/android')
include ':react-native-device-info'
project(':react-native-device-info').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-device-info/android')
include ':@react-native-firebase_app'
project(':@react-native-firebase_app').projectDir = new File(rootProject.projectDir, '../node_modules/@react-native-firebase/app/android')
include ':@react-native-firebase_analytics'
project(':@react-native-firebase_analytics').projectDir = new File(rootProject.projectDir, '../node_modules/@react-native-firebase/analytics/android')
include ':@react-native-firebase_messaging'
project(':@react-native-firebase_messaging').projectDir = new File(rootProject.projectDir, './../node_modules/@react-native-firebase/messaging/android')
include ':react-native-branch'
project(':react-native-branch').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-branch/android')
include ':react-native-exit-app'
project(':react-native-exit-app').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-exit-app/android')
include ':react-native-sentry'
project(':react-native-sentry').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-sentry/android')
include ':react-native-webview'
project(':react-native-webview').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-webview/android')
include ':react-native-linear-gradient'
project(':react-native-linear-gradient').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-linear-gradient/android')
include ':react-native-notifications'
project(':react-native-notifications').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-notifications/lib/android/app')
apply from: file("../node_modules/@react-native-community/cli-platform-android/native_modules.gradle"); applyNativeModulesSettingsGradle(settings)
include ':app'

MainApplication.java:

package com.makemytripseller;

import android.app.Application;
import android.util.Log;

import com.facebook.react.PackageList;
import com.facebook.hermes.reactexecutor.HermesExecutorFactory;
import com.facebook.react.bridge.JavaScriptExecutorFactory;
import com.facebook.react.ReactApplication;
import com.reactnativecommunity.asyncstorage.AsyncStoragePackage;
import org.reactnative.camera.RNCameraPackage;
import io.branch.rnbranch.RNBranchPackage;
import io.branch.referral.Branch;
import com.github.wumke.RNExitApp.RNExitAppPackage;
import io.sentry.RNSentryPackage;
import com.reactnativecommunity.webview.RNCWebViewPackage;
import com.BV.LinearGradient.LinearGradientPackage;
import com.facebook.react.ReactNativeHost;
import com.facebook.react.ReactPackage;
import com.facebook.soloader.SoLoader;
import io.branch.rnbranch.*;
import io.invertase.firebase.app.ReactNativeFirebaseAppPackage;
import io.invertase.firebase.messaging.ReactNativeFirebaseMessagingPackage;

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() {
      @SuppressWarnings("UnnecessaryLocalVariable")
      List<ReactPackage> packages = new PackageList(this).getPackages();
      packages.add( new ReactNativeFirebaseAppPackage());
      return packages;
    }

    @Override
    protected String getJSMainModuleName() {
      return "index";
    }
  };

  @Override
  public ReactNativeHost getReactNativeHost() {
    return mReactNativeHost;
  }

  @Override
  public void onCreate() {
    super.onCreate();
    SoLoader.init(this, /* native exopackage */ false);
    RNBranchModule.getAutoInstance(this);
  }
}

AndroidManifest.xml:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.makemytripseller">

    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>
    <uses-permission android:name="android.permission.VIBRATE" />
    <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
    <permission
            android:name="com.makemytripseller.permission.C2D_MESSAGE"
            android:protectionLevel="signature" />
    <uses-permission android:name="com.makemytripseller.permission.C2D_MESSAGE" />

    <application
      android:name=".MainApplication"
      android:label="@string/app_name"
      android:icon="@mipmap/ic_launcher"
      android:roundIcon="@mipmap/ic_launcher"
      android:allowBackup="false"
      android:theme="@style/AppTheme">
      <activity
        android:name=".MainActivity"
        android:launchMode="singleTask"
        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>
          <!-- Branch URI Scheme -->
            <intent-filter>
                <data android:scheme="acmeSeller" />
                <action android:name="android.intent.action.VIEW" />
                <category android:name="android.intent.category.DEFAULT" />
                <category android:name="android.intent.category.BROWSABLE" />
            </intent-filter>
              <!-- Branch App Links (optional) -->
            <intent-filter android:autoVerify="true">
                <action android:name="android.intent.action.VIEW" />
                <category android:name="android.intent.category.DEFAULT" />
                <category android:name="android.intent.category.BROWSABLE" />
                <data android:scheme="https" android:host="mcbni.app.link" />
            </intent-filter>
      </activity>
      <activity android:name="com.facebook.react.devsupport.DevSettingsActivity" />

        <!-- Branch init -->
        <meta-data android:name="io.branch.sdk.BranchKey" android:value="key_live_kiTKlG5hXWKHcYdmUQWuMcocqAnorsYC" />
        <meta-data android:name="io.branch.sdk.BranchKey.test" android:value="key_test_ikLGeH0a65JMlXiaQM6FPhilxBgfsF1U" />
        <meta-data android:name="io.branch.sdk.TestMode" android:value="false" />

        <!-- Branch install referrer tracking (optional) -->
        <receiver android:name="io.branch.referral.InstallListener" android:exported="true">
            <intent-filter>
                <action android:name="com.android.vending.INSTALL_REFERRER" />
            </intent-filter>
        </receiver>
    </application>

</manifest>


Environment

Click To Expand

react-native info output:

System:
    OS: macOS 10.15.4
    CPU: (12) x64 Intel(R) Core(TM) i7-8750H CPU @ 2.20GHz
    Memory: 74.09 MB / 16.00 GB
    Shell: 5.7.1 - /bin/zsh
  Binaries:
    Node: 12.14.1 - ~/.nvm/versions/node/v12.14.1/bin/node
    Yarn: 1.21.1 - /usr/local/bin/yarn
    npm: 6.13.4 - ~/.nvm/versions/node/v12.14.1/bin/npm
    Watchman: 4.9.0 - /usr/local/bin/watchman
  SDKs:
    iOS SDK:
      Platforms: iOS 13.4, DriverKit 19.0, macOS 10.15, tvOS 13.4, watchOS 6.2
  IDEs:
    Android Studio: 3.5 AI-191.8026.42.35.6010548
    Xcode: 11.4/11E146 - /usr/bin/xcodebuild
  npmPackages:
    react: 16.8.6 => 16.8.6
    react-native: 0.60.4 => 0.60.4
  npmGlobalPackages:
    react-native: 0.61.5
  • Platform that you're experiencing the issue on:
    • [ ] iOS
    • [ ] Android
    • [ ] iOS but have not tested behavior on Android
    • [ ] Android but have not tested behavior on iOS
    • [ ] Both
  • react-native-firebase version you're using that has this issue:
    • e.g. 5.4.3
  • Firebase module(s) you're using that has the issue:
    • e.g. Instance ID
  • Are you using TypeScript?
    • Y/N & VERSION


ashishkumar1000 avatar Apr 09 '20 22:04 ashishkumar1000

I am having the same exact issue except on version 6.7.1

Eralyne avatar May 08 '20 02:05 Eralyne

I'm facing same issue on version 6.3.4. Were you guys able to resolve it?

parth-koshta avatar May 12 '20 06:05 parth-koshta

I haven't found a solution yet.

Eralyne avatar May 16 '20 21:05 Eralyne

I was able to solve this issue with a little hack. Don't use setBackgroundMessageHandler instead register a headless task. Do this as soon as your app start, I put it inside my index.js. My working code


/**
 * Register a ReactNativeFirebaseMessagingHeadlessTask as headless task.
 * This will be trigger a task when FCM payload is received in background.
 */

AppRegistry.registerHeadlessTask('ReactNativeFirebaseMessagingHeadlessTask', () => backgroundMessagingAndroid);
/**
 * This is fix for the issue where app was crashing when in killed/Banckground state and FCM payload is received.
 * @param message payload from FCM
 * @returns {Promise<void>}
 */

function backgroundMessagingAndroid(message) {
    log.info('backgroundMessagingAndroid  -->  task received.');
    //Now we have message object. your code to show notification goes here.
    return Promise.resolve();
}

ashishkumar1000 avatar May 17 '20 21:05 ashishkumar1000

my app crash when ever received notification data in foreground and background
looking for solution but not helped any thing ..notification data show in console but app crash with no exception

arslanafzal077 avatar May 19 '20 06:05 arslanafzal077

Please post full crash traces (from unfiltered adb logcat or console showing log from real device) with crash reports - those are useful

mikehardy avatar May 19 '20 14:05 mikehardy

Thanks for the issue report, @ashishkumar1000, we’re no longer actively supporting <= v5 development so I’m going to go ahead and close this issue - but feel free to continue the discussion. If you have any issues regarding React Native Firebase >= v6, please raise a new issue.

russellwheatley avatar May 21 '20 09:05 russellwheatley