invertase / react-native-firebase

🔥 A well-tested feature-rich modular Firebase implementation for React Native. Supports both iOS & Android platforms for all Firebase services.
https://rnfirebase.io
Other
11.63k stars 2.2k forks source link

No virtual method getImageUrl()Landroid/net/Uri; in class Lcom/google/firebase/messaging/RemoteMessage$Notification; #3025

Closed kundanbasha closed 4 years ago

kundanbasha commented 4 years ago

2720 Issue

The app is getting crash while receiving the notification but notifications are visible in the status bar. I have integrated crashlytics and found the below output in firebase console. Without notification app is working fine but after notification only app getting crash.

Project Files

android/build.gradle:

buildscript { ext { buildToolsVersion = "28.0.3" minSdkVersion = 16 compileSdkVersion = 28 targetSdkVersion = 28 supportLibVersion = "28.0.0" googlePlayServicesVersion = "15.0.0" } repositories { google() jcenter() maven { url 'https://maven.fabric.io/public' } } dependencies { classpath 'com.android.tools.build:gradle:3.3.2'

    // NOTE: Do not place your application dependencies here; they belong
    // in the individual module build.gradle files
    // classpath 'com.google.gms:google-services:4.2.0'
     classpath 'com.google.gms:google-services:4.3.3'

     classpath 'io.fabric.tools:gradle:1.31.2'
}

}

allprojects { repositories { mavenLocal() google() jcenter() maven { // All of React Native (JS, Obj-C sources, Android binaries) is installed from npm url "$rootDir/../node_modules/react-native/android" } maven { url 'https://maven.google.com/' // Make Sure This block is added over here only name 'Google' } } }

android/app/build.gradle:

dependencies { implementation project(':react-native-background-color') implementation project(':react-native-splash-screen') implementation project(':react-native-exit-app') implementation project(':react-native-version-number') implementation project(':rn-fetch-blob') implementation project(':react-native-snackbar') implementation project(':react-native-document-picker') implementation project(':react-native-vector-icons') implementation project(':@react-native-community_netinfo') implementation project(':react-native-linear-gradient') implementation project(':react-native-gesture-handler') implementation project(':react-native-sound') implementation fileTree(dir: "libs", include: ["*.jar"]) implementation "com.android.support:appcompat-v7:${rootProject.ext.supportLibVersion}" implementation "com.facebook.react:react-native:+" // From node_modules implementation project(':react-native-firebase') implementation "com.google.android.gms:play-services-base:16.1.0" implementation "com.google.firebase:firebase-core:16.0.8" implementation "com.google.firebase:firebase-messaging:17.5.0"

 // (Recommended) Add the Google Analytics dependency.
implementation 'com.google.firebase:firebase-analytics:16.3.0'

// Add the Firebase Crashlytics dependency.
implementation 'com.crashlytics.sdk.android:crashlytics:2.10.1'

}

MainApplication.java:

@Override protected List getPackages() { return Arrays.asList( new MainReactPackage(), new BackgroundColorPackage(), new SplashScreenReactPackage(), new RNExitAppPackage(), new RNVersionNumberPackage(), new RNFetchBlobPackage(), new SnackbarPackage(), new DocumentPickerPackage(), new VectorIconsPackage(), new NetInfoPackage(), new LinearGradientPackage(), new RNGestureHandlerPackage(), new RNFirebaseMessagingPackage(), new RNFirebasePackage(), new RNSoundPackage(), new RNFirebaseNotificationsPackage() ); }

AndroidManifest.xml:

<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

<application
  tools:replace="android:allowBackup"
  android:name=".MainApplication"
  android:label="@string/app_name"
  android:icon="@mipmap/ic_launcher"
  android:roundIcon="@mipmap/ic_launcher_round"
  android:allowBackup="false"
  android:alwaysRetainTaskState="true"
  android:background="@color/opaque_white"
  android:launchMode="singleTop"
  android:theme="@style/AppTheme"
>

    <meta-data
        android:name="com.google.firebase.messaging.default_notification_icon"
        android:resource="@mipmap/ic_notification_small"
    />

  <activity
    android:name=".MainActivity"
    android:label="@string/app_name"
    android:configChanges="keyboard|keyboardHidden|orientation|screenSize"
    android:windowSoftInputMode="stateHidden|adjustResize"
    >
    <intent-filter>
        <action android:name="android.intent.action.MAIN" />
        <category android:name="android.intent.category.LAUNCHER" />
    </intent-filter>
  </activity>
    <service android:name="com.acme.service.LauncherIntentService" />
  <activity android:name="com.facebook.react.devsupport.DevSettingsActivity"/>
    <service android:name="io.invertase.firebase.messaging.RNFirebaseMessagingService">
        <intent-filter>
            <action android:name="com.google.firebase.MESSAGING_EVENT" />
        </intent-filter>
    </service>
    <service android:name="io.invertase.firebase.messaging.RNFirebaseInstanceIdService">
        <intent-filter>
            <action android:name="com.google.firebase.INSTANCE_ID_EVENT"/>
        </intent-filter>
    </service>
    <service android:name="io.invertase.firebase.messaging.RNFirebaseBackgroundMessagingService" />
</application>

React-native INFO: React Native Environment Info: System: OS: Linux 4.15 Ubuntu 16.04.6 LTS (Xenial Xerus) CPU: (4) x64 Intel(R) Core(TM) i7-5600U CPU @ 2.60GHz Memory: 4.02 GB / 15.54 GB Shell: 4.3.48 - /bin/bash Binaries: Node: 10.17.0 - /usr/bin/node npm: 6.11.3 - /usr/bin/npm SDKs: Android SDK: API Levels: 23, 25, 26, 28, 29 Build Tools: 28.0.3, 29.0.2 System Images: android-28 | Intel x86 Atom_64, android-28 | Google APIs Intel x86 Atom npmPackages: react: 16.8.3 => 16.8.3 react-native: 0.59.5 => 0.59.5 npmGlobalPackages: react-native-cli: 2.0.1

OUTPUT: Fatal Exception: java.lang.NoSuchMethodError: No virtual method getImageUrl()Landroid/net/Uri; in class Lcom/google/firebase/messaging/RemoteMessage$Notification; or its super classes (declaration of 'com.google.firebase.messaging.RemoteMessage$Notification' appears in /data/app/com.selekt.chatgen-2/base.apk) at io.invertase.firebase.notifications.RNFirebaseNotifications.parseRemoteMessage(RNFirebaseNotifications.java:396) at io.invertase.firebase.notifications.RNFirebaseNotifications.access$300(RNFirebaseNotifications.java:38) at io.invertase.firebase.notifications.RNFirebaseNotifications$RemoteNotificationReceiver.onReceive(RNFirebaseNotifications.java:455) at androidx.localbroadcastmanager.content.LocalBroadcastManager.executePendingBroadcasts(LocalBroadcastManager.java:313) at androidx.localbroadcastmanager.content.LocalBroadcastManager$1.handleMessage(LocalBroadcastManager.java:121) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:165) at android.app.ActivityThread.main(ActivityThread.java:6375) at java.lang.reflect.Method.invoke(Method.java) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:912) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:802)

mikehardy commented 4 years ago

Incompatible versions I'd suppose. Switch to the BOM style, and I think you are still AndroidX so you you'll want the last non-AndroidX version https://firebase.google.com/support/release-notes/android#bom_v19-0-0

If my suggestion of moving to the BOM style (for consistent versioning) doesn't work, I'm not sure what would, these versions are pretty old at this point and supporting them isn't worth the effort vs upgrading

For upgarding you should move to react-native 0.59.10 (current - here's how https://react-native-community.github.io/upgrade-helper/?from=0.59.5&to=0.59.10) and switch to AndroidX using Android Studio's migration as well as the jetifier react-native package. I tested those, they work fine, then you can move to the most current Firebase SDKs (BOM 24.3.0). You'll want to get to react-native 0.60+ before much longer in order to support iOS13 well anyway, so you can defer that migration but not much longer. The 'upgrade-helper' tool can help https://react-native-community.github.io/upgrade-helper/

stale[bot] commented 4 years ago

Hello 👋, to help manage issues we automatically close stale issues. This issue has been automatically marked as stale because it has not had activity for quite some time. Has this issue been fixed, or does it still require the community's attention?

This issue will be closed in 15 days if no further activity occurs. Thank you for your contributions.

SurajMDurgad commented 4 years ago

@mikehardy solution worked for me. 🎉

Change your dependencies version to following -

com.google.firebase:firebase-core:16.0.9 com.google.firebase:firebase-ads:17.2.1 com.google.firebase:firebase-analytics:16.5.0 com.google.firebase:firebase-appindexing:18.0.0 com.google.firebase:firebase-auth:17.0.0 com.google.firebase:firebase-firestore:19.0.2 com.google.firebase:firebase-functions:17.0.0 com.google.firebase:firebase-messaging:18.0.0 com.google.firebase:firebase-storage:17.0.0 com.google.firebase:firebase-crash:16.2.1 com.google.firebase:firebase-dynamic-links:17.0.0 com.google.firebase:firebase-invites:17.0.0 com.google.firebase:firebase-inappmessaging:17.2.0 com.google.firebase:firebase-inappmessaging-display:17.2.0 com.google.firebase:firebase-ml-vision:20.0.0 com.google.firebase:firebase-ml-vision-image-label-model:17.0.2 com.google.firebase:firebase-ml-vision-face-model:17.0.2 com.google.firebase:firebase-ml-natural-language:19.0.1 com.google.firebase:firebase-ml-natural-language-language-id-model:19.0.1 com.google.firebase:firebase-ml-natural-language-smart-reply-model:19.0.1 com.google.firebase:firebase-ml-model-interpreter:19.0.0 com.google.firebase:firebase-perf:17.0.2 com.google.firebase:firebase-database:17.0.0 com.google.firebase:firebase-config:17.0.0 com.crashlytics.sdk.android:crashlytics:2.10.1

Change the once you have implemented to above versions. It works like a charm! Thanks again @mikehardy!

mikehardy commented 4 years ago

Glad there seems to be a viable solution! I'm going to close this since the initial diagnosis seems correct. Good luck on your projects, everyone