I've updated both RN Firebase and Firebase SDK for Android and now I'm receiving a lot of errors regarding the ClassNotFoundException reported by Crashlytics
Unable to instantiate service io.invertase.firebase.messaging.MessagingService: java.lang.ClassNotFoundException: Didn't find class "io.invertase.firebase.messaging.MessagingService" on path: DexPathList[[zip file "/data/app/com.example.app-1/base.apk"],nativeLibraryDirectories=[/data/app/com.example.app-1/lib/arm, /vendor/lib, /system/lib]]
These are the only methods that I'm using on componentDidMount()
firebase.messaging().subscribeToTopic(PUSH_NOTIFICATION_TOPIC);
firebase.messaging().hasPermission().then((enabled) => {
if (enabled) {
// user has permissions
} else {
// user doesn't have permission
firebase.messaging().requestPermission().then(() => {
warn('User has authorised');
}).catch((error) => {
warn('User has rejected permissions');
});
}
});
Android
macOS Mojave
XCode Version 9.4.1 (9F2000)
React Native
version:0.56.0
React Native Firebase
Version:4.3.8
Firebase
Module:Messaging
typescript
?No
Apparently I was using old class names in my AndroidManifest
Modifying them to the following seems to be solving the issue:
<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>
<receiver android:name="io.invertase.firebase.notifications.RNFirebaseNotificationReceiver"/>
<receiver android:enabled="true" android:exported="true" android:name="io.invertase.firebase.notifications.RNFirebaseNotificationsRebootReceiver">
there is a typo, should be:
<receiver android:name="io.invertase.firebase.notifications.RNFirebaseNotificationReceiver"</receiver>
<receiver android:enabled="true" android:exported="true" android:name="io.invertase.firebase.notifications.RNFirebaseNotificationsRebootReceiver"></receiver>
For me adding below line to app/build.gradle file fixed the issue:
implementation 'com.google.firebase:firebase-messaging:+'
you need to remove this after 5.2.0, check docs and release notes
Few days ago Firebase release Major Update for Cloud Messaging SDK to 19.0.0 and made another error when I was using implementation 'com.google.firebase:firebase-messaging:+'
.
So now I am using implementation 'com.google.firebase:firebase-messaging:18.0.0'
on app/build.gradle and it works perfectly.
While building apk I see a lot of the following messages:
/Users/mac/Desktop/BeachBandit_git_RN/node_modules/react-native-firebase/android/build/intermediates/intermediate-jars/release/classes.jar: D8: Interface com.google.firebase.database.ChildEventListener
not found. It's needed to make sure desugaring of io.invertase.firebase.database.RNFirebaseDatabaseReference$3
is correct. Desugaring will assume that this interface has no default method.
Although apk builds successfully but it crashes on first launch with the following message in logs
java.lang.RuntimeException: Unable to instantiate service io.invertase.firebase.messaging.RNFirebaseMessagingService: java.lang.ClassNotFoundException: Didn't find class "io.invertase.firebase.messaging.RNFirebaseMessagingService" on path: DexPathList[[zip file "/data/app/com.beachbandits-1/base.apk"],nativeLibraryDirectories=[/data/app/com.beachbandits-1/lib/arm, /data/app/com.beachbandits-1/base.apk!/lib/armeabi-v7a, /system/lib, /vendor/lib]]
at android.app.ActivityThread.handleCreateService(ActivityThread.java:3531)
at android.app.ActivityThread.-wrap6(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1749)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6816)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1563)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1451)
Caused by: java.lang.ClassNotFoundException: Didn't find class "io.invertase.firebase.messaging.RNFirebaseMessagingService" on path: DexPathList[[zip file "/data/app/com.beachbandits-1/base.apk"],nativeLibraryDirectories=[/data/app/com.beachbandits-1/lib/arm, /data/app/com.beachbandits-1/base.apk!/lib/armeabi-v7a, /system/lib, /vendor/lib]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
at java.lang.ClassLoader.loadClass(ClassLoader.java:380)
at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
at android.app.ActivityThread.handleCreateService(ActivityThread.java:3528)
at android.app.ActivityThread.-wrap6(ActivityThread.java)聽
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1749)聽
at android.os.Handler.dispatchMessage(Handler.java:102)聽
at android.os.Looper.loop(Looper.java:154)聽
at android.app.ActivityThread.main(ActivityThread.java:6816)聽
at java.lang.reflect.Method.invoke(Native Method)聽
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1563)聽
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1451)聽
Suppressed: java.lang.NoClassDefFoundError: Failed resolution of: Lcom/google/firebase/messaging/FirebaseMessagingService;
at java.lang.VMClassLoader.findLoadedClass(Native Method)
at java.lang.ClassLoader.findLoadedClass(ClassLoader.java:742)
at java.lang.ClassLoader.loadClass(ClassLoader.java:362)
... 10 more
Caused by: java.lang.ClassNotFoundException: com.google.firebase.messaging.FirebaseMessagingService
at java.lang.VMClassLoader.findLoadedClass(Native Method)
at java.lang.ClassLoader.findLoadedClass(ClassLoader.java:742)
at java.lang.ClassLoader.loadClass(ClassLoader.java:362)
at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
... 13 more
Caused by: java.lang.IllegalAccessError: Class com.google.firebase.iid.zzb extended by class com.google.firebase.messaging.FirebaseMessagingService is inaccessible (declaration of 'com.google.firebase.messaging.FirebaseMessagingService' appears in /data/app/com.beachbandits-1/base.apk)
... 13 more
Any Solution?
My problem was solved by removing these lines from my AndroidManifest.xml.
<service android:name="io.invertase.firebase.messaging.RNFirebaseInstanceIdService">
<intent-filter>
<action android:name="com.google.firebase.INSTANCE_ID_EVENT"/>
</intent-filter>
</service>
According to the docs you should add them only if you're using RNFB versions less than 5.2.0.
there is a typo, should be:
<receiver android:name="io.invertase.firebase.notifications.RNFirebaseNotificationReceiver"</receiver> <receiver android:enabled="true" android:exported="true" android:name="io.invertase.firebase.notifications.RNFirebaseNotificationsRebootReceiver"></receiver>
Typo here too.
@shinigami3000 this issue is almost a year old - if there are still typos anywhere, please propose a PR to help others
I am getting error with the latest integration as per the docs provided:
https://rnfirebase.io/
this is what I am getting:
here is my source code:
import React, { Component } from 'react';
import { Provider } from 'react-redux';
import { PersistGate } from 'redux-persist/lib/integration/react';
import createStore from 'App/Stores';
import RootScreen from './Containers/Root/RootScreen';
import * as Sentry from '@sentry/react-native';
import BackgroundFetch from 'react-native-background-fetch';
import { DefaultTheme, Provider as PaperProvider } from 'react-native-paper';
import { Colors, Fonts } from 'App/Theme';
import CodePush from 'react-native-code-push';
import messaging from '@react-native-firebase/messaging';
import firebase from '@react-native-firebase/app';
import { Alert } from 'react-native';
Sentry.init({
dsn: 'https://[email protected]/1785310',
});
const { store, persistor } = createStore();
const SmsParser = async () => {
console.log('[js] Received background-fetch event while app is not runnung');
//await ReadAndSendSms();
BackgroundFetch.finish();
};
const theme = {
...DefaultTheme,
fonts: Fonts,
colors: {
...DefaultTheme.colors,
...Colors,
},
};
class App extends Component {
codePushStatusDidChange(syncStatus) {
console.log('Code Push syncStatus ', syncStatus);
switch (syncStatus) {
case CodePush.SyncStatus.CHECKING_FOR_UPDATE:
this.setState({ syncMessage: 'Checking for update.' });
break;
case CodePush.SyncStatus.DOWNLOADING_PACKAGE:
this.setState({ syncMessage: 'Downloading package.' });
break;
case CodePush.SyncStatus.AWAITING_USER_ACTION:
this.setState({ syncMessage: 'Awaiting user action.' });
break;
case CodePush.SyncStatus.INSTALLING_UPDATE:
this.setState({ syncMessage: 'Installing update.' });
break;
case CodePush.SyncStatus.UP_TO_DATE:
this.setState({ syncMessage: 'App up to date.', progress: false });
break;
case CodePush.SyncStatus.UPDATE_IGNORED:
this.setState({
syncMessage: 'Update cancelled by user.',
progress: false,
});
break;
case CodePush.SyncStatus.UPDATE_INSTALLED:
this.setState({
syncMessage: 'Update installed and will be applied on restart.',
progress: false,
});
break;
case CodePush.SyncStatus.UNKNOWN_ERROR:
this.setState({
syncMessage: 'An unknown error occurred.',
progress: false,
});
break;
}
}
codePushDownloadDidProgress(progress) {
this.setState({ progress });
}
// Update is downloaded silently, and applied on restart (recommended)
sync() {
CodePush.sync(
{},
this.codePushStatusDidChange.bind(this),
this.codePushDownloadDidProgress.bind(this),
);
}
// Update pops a confirmation dialog, and then immediately reboots the app
syncImmediate() {
CodePush.sync(
null,
{ installMode: CodePush.InstallMode.IMMEDIATE, updateDialog: true },
this.codePushStatusDidChange.bind(this),
this.codePushDownloadDidProgress.bind(this),
);
}
checkPermission = async () => {
const enabled = await messaging().hasPermission();
console.log('enabled ******* ',enabled)
if (enabled) {
this.getFcmToken();
} else {
this.requestPermission();
}
};
getFcmToken = async () => {
const fcmToken = await messaging().getToken();
if (fcmToken) {
console.log('Your Firebase Token is:', fcmToken);
// this.showAlert('Your Firebase Token is:', fcmToken);
} else {
console.log('Failed', 'No token received');
}
};
requestPermission = async () => {
try {
await messaging().requestPermission();
// User has authorised
} catch (error) {
// User has rejected permissions
}
};
messageListener = async () => {
console.log('inside message listener ****** ')
this.messageListener = messaging().onMessage((message) => {
console.log('message ******* ',JSON.stringify(message));
});
};
showAlert = (title, message) => {
Alert.alert(
title,
message,
[{ text: 'OK', onPress: () => console.log('OK Pressed') }],
{ cancelable: false },
);
};
componentDidMount() {
CodePush.disallowRestart();
if (process.env.NODE_ENV === 'development') {
this.syncImmediate();
}
this.checkPermission();
this.messageListener();
}
render() {
return (
<Provider store={store}>
<PersistGate loading={null} persistor={persistor}>
<PaperProvider theme={theme}>
<RootScreen />
</PaperProvider>
</PersistGate>
</Provider>
);
}
}
let codePushOptions = {
checkFrequency: CodePush.CheckFrequency.ON_APP_RESUME,
installMode: CodePush.InstallMode.IMMEDIATE,
};
let Spenny = CodePush(codePushOptions)(App);
export default Spenny;
I am using react native firebase since 4 years and I never got satisfied with this module whenever I tried to add this in any of my projects. It always take more than a day to integrate because every next time I use it, its always has lot of changes itself. This module sucks!
the issue resolved when I removed this code:
<service android:name="io.invertase.firebase.messaging.RNFirebaseMessagingService">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT" />
</intent-filter>
</service>
Basically we need to make sure for the latest docs, we should not add anything in the menifest file because latest react native and latest firebase docs handle this automatically
@rishiankush That is incredibly rude. Your failure to read the documentation and upgrade notes for a module is no indictment of the module.
After rereading Docs about Migrating to v6, I removed RNFirebaseMessagingService
from AndroidManifest.xml and this solved issue with Android
Good luck :)
the issue resolved when I removed this code:
<service android:name="io.invertase.firebase.messaging.RNFirebaseMessagingService"> <intent-filter> <action android:name="com.google.firebase.MESSAGING_EVENT" /> </intent-filter> </service>
Basically we need to make sure for the latest docs, we should not add anything in the menifest file because latest react native and latest firebase docs handle this automatically
Thanks to you I solved this problem!
I'm not sure if the docs have changed since this issue was last commented on, but I don't see anything about removing these lines from the AndroidManifest.xml
file in the migrations section of the docs here
@gp3gp3gp3 that's a good point - if you want to hit the edit button on the top right of that page and a chunk to help others, that could help :pray:
My problem was solved by removing these lines from my AndroidManifest.xml.
<service android:name="io.invertase.firebase.messaging.RNFirebaseInstanceIdService"> <intent-filter> <action android:name="com.google.firebase.INSTANCE_ID_EVENT"/> </intent-filter> </service>
According to the docs you should add them only if you're using RNFB versions less than 5.2.0.
Thank you for saving me from hours of unsuccessful deadends. This worked 馃檪
My problem was solved by removing these lines from my AndroidManifest.xml.
<service android:name="io.invertase.firebase.messaging.RNFirebaseInstanceIdService"> <intent-filter> <action android:name="com.google.firebase.INSTANCE_ID_EVENT"/> </intent-filter> </service>
According to the docs you should add them only if you're using RNFB versions less than 5.2.0.
The docs link is probably outdated. Anyone looking for the working link.... docs
Most helpful comment
My problem was solved by removing these lines from my AndroidManifest.xml.
<service android:name="io.invertase.firebase.messaging.RNFirebaseInstanceIdService"> <intent-filter> <action android:name="com.google.firebase.INSTANCE_ID_EVENT"/> </intent-filter> </service>
According to the docs you should add them only if you're using RNFB versions less than 5.2.0.