Android crashes on getting notification
The library is awesome and I appreciate all the hard work you guys are putting in!
Any help on this would be amazing. I hate putting issue's up and try to find a solution, but I am stuck and think this might be a bug.
The title says it -- I have looked through the other issues on here and tried to find a solution. Whenever the android app is going to receive a notification it crashes - this is the reason from the log:
08-13 20:14:19.053 18036-18237/? E/AndroidRuntime: FATAL EXCEPTION: AsyncTask #5
Process: com.myapp, PID: 18036
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)
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.myapp-fTcxeavrsU6eP1VNM2_Fvg==/base.apk)
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)
I think that "Caused by: java.lang.NoSuchMethodError: No direct method
So far I have tried altering my gradle dependicies, changing the gradle file for react-native-firebase to use v7, different versions of v4 etc. Either the project won't sync, or I get it syncing and have it crash when notifications come through.
Here is my gradle file
`apply plugin: "com.android.application"
project.ext.react = [ entryFile: "index.js" ]
apply from: "../../node_modules/react-native/react.gradle"
def enableSeparateBuildPerCPUArchitecture = false
def enableProguardInReleaseBuilds = false
android { compileSdkVersion 25 buildToolsVersion "27.0.3"
defaultConfig {
applicationId "com.myapp"
minSdkVersion 19
targetSdkVersion 25
versionCode 12
versionName "1.1.1"
ndk {
abiFilters "armeabi-v7a", "x86"
}
}
signingConfigs {
release {
******
}
}
splits {
abi {
reset()
enable enableSeparateBuildPerCPUArchitecture
universalApk false // If true, also generate a universal APK
include "armeabi-v7a", "x86"
}
}
buildTypes {
release {
minifyEnabled enableProguardInReleaseBuilds
proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
signingConfig signingConfigs.release
}
}
applicationVariants.all { variant ->
variant.outputs.each { output ->
// For each separate APK per architecture, set a unique version code as described here:
// http://tools.android.com/tech-docs/new-build-system/user-guide/apk-splits
def versionCodes = ["armeabi-v7a":1, "x86":2]
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
}
}
}
}
configurations.all { resolutionStrategy.eachDependency { DependencyResolveDetails details -> def requested = details.requested if (requested.group == 'com.android.support') { if (!requested.name.startsWith("multidex")) { details.useVersion '25.3.0' //I have tried many different version's here, I'd love some more to try though } } } }
dependencies {
implementation project(':react-native-firebase')
implementation 'com.google.android.gms:play-services-base:15.0.1'
implementation 'com.google.firebase:firebase-core:16.0.1'
implementation 'com.google.firebase:firebase-messaging:17.1.0'
implementation project(':react-native-iap')
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation 'com.facebook.react:react-native:+'
implementation 'com.android.support:appcompat-v7:25.4.0'
}
// 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 plugin: 'com.google.gms.google-services'`
Environment
- Application Target Platform:
Android
- Development Operating System:
macOS Sierra
- Build Tools:
Android Studio
React Nativeversion:
"react-native": "^0.53.0",
React Native FirebaseVersion:
4.3.0
FirebaseModule:
messaging and notifications modules
- Are you using
typescript?
no
EDIT: Built app on coworkers phones to test other code - they are running older versions of Android (7 and 6 I believe) and everything worked great for them, no crashes. So it is only with Android 8 that this is a bug.
Loving react-native-firebase? Please consider supporting them with any of the below:
- 👉 Back financially via Open Collective
- 👉 Follow
React Native FirebaseandInvertaseon Twitter - 👉 Star this repo on GitHub ⭐️
Hello 👋, this issue has been automatically marked as stale because it has not had activity for quite some time. Has the issue been fixed, or does it still require the community's attention? This issue may be closed if no further activity occurs. Thank you for your contributions.
Closing this issue after a prolonged period of inactivity. If this is still present in the latest release, please feel free to create a new issue with up-to-date information.
Issue
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
}
The issue is similar to an issue I created 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 Nativeversion:
0.54.4 => 0.54.4
React Native FirebaseVersion:
4.3.8
FirebaseModule:
messaging
- Are you using
typescript?
no
@Salakar Can you please respond to my above problem instead of closing this ticket? Thank you!
solution, after hours of frustration, (with no help on this github or stack overflow):
- eliminated line: api "com.android.support:support-v4:$supportVersion"
- changed target sdk to 27. def DEFAULT_TARGET_SDK_VERSION = 27
on face value, none of these should fix this, but they did...
Hey, I closed it because it was a duplicate. The issue here is that "com.android.support:support-v4" needs to be version v26 or higher as that's the version most of these API's that are causing crashes were introduced. I'd imagine it was being set to a version less than this which is why removing those lines made it work.
You can see here that this method specifically was only introduced in version 26 of the dependency and is being called by Firebase internally but it doesn't exist in that version.
We do add checks in the code for build versions e.g. if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { (26) but if the methods don't exist in the library because the version is out of date it would have crashed.
I've just added some try catches around all the methods that we've used that were introduced in v26 of the library - so it should now gracefully continue to work on v24-25 albeit without those specific notification features functioning.
However - should this error continue to keep happening then I'd suggest ensuring you're using v26 and above of the Android support library as some of these calls may be out of our control.
Loving react-native-firebase and the support we provide? Please consider supporting us with any of the below:
- 👉 Back financially via Open Collective
- 👉 Follow
React Native FirebaseandInvertaseon Twitter - 👉 Star this repo on GitHub ⭐️