Onesignal-flutter-sdk: Error getting FCM Token - FirebaseInstanceId failed

Created on 19 May 2021  路  21Comments  路  Source: OneSignal/OneSignal-Flutter-SDK

Description:
Onesignal plugin started causing issues today without any changes. It was working up to last night both on production app and my environment. Now all the sudden I am getting this error: Unknown error getting FCM Token E/OneSignal( 6855): java.lang.NoClassDefFoundError: Failed resolution of: Lcom/google/firebase/iid/FirebaseInstanceId;

(your description here)

Environment
Flutter 2.2
onesignal_flutter: ^2.6.3
connectivity: ^3.0.3
firebase_core: ^1.2.0
firebase_analytics: ^8.1.0
firebase_messaging: ^10.0.0

Testing on android emulator with api 30

Steps to Reproduce Issue:

(write below this line) -->

  1. Add onesignal to flutter app
  2. Run
  3. Check Debug messages

Anything else:

Trace:

I/FirebaseApp( 6855): Device unlocked: initializing all Firebase APIs for app ONESIGNAL_SDK_FCM_APP_NAME
E/OneSignal( 6855): Unknown error getting FCM Token
E/OneSignal( 6855): java.lang.NoClassDefFoundError: Failed resolution of: Lcom/google/firebase/iid/FirebaseInstanceId;
E/OneSignal( 6855):     at com.onesignal.PushRegistratorFCM.getToken(PushRegistratorFCM.java:94)
E/OneSignal( 6855):     at com.onesignal.PushRegistratorAbstractGoogle.attemptRegistration(PushRegistratorAbstractGoogle.java:97)
E/OneSignal( 6855):     at com.onesignal.PushRegistratorAbstractGoogle.access$100(PushRegistratorAbstractGoogle.java:37)
E/OneSignal( 6855):     at com.onesignal.PushRegistratorAbstractGoogle$1.run(PushRegistratorAbstractGoogle.java:84)
E/OneSignal( 6855):     at java.lang.Thread.run(Thread.java:923)
E/OneSignal( 6855): Caused by: java.lang.ClassNotFoundException: Didn't find class "com.google.firebase.iid.FirebaseInstanceId" on path: DexPathList[[zip file "/data/app/~~YdcDc9kiv7RdbcC-qZ9Zsw==/gr.antenna.easy972-_6WiLGIZYmoEhBhfCQ_fMQ==/base.apk"],nativeLibraryDirectories=[/data/app/~~YdcDc9kiv7RdbcC-qZ9Zsw==/gr.antenna.easy972-_6WiLGIZYmoEhBhfCQ_fMQ==/lib/x86, /data/app/~~YdcDc9kiv7RdbcC-qZ9Zsw==/gr.antenna.easy972-_6WiLGIZYmoEhBhfCQ_fMQ==/base.apk!/lib/x86, /system/lib, /system_ext/lib]]
E/OneSignal( 6855):     at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:207)
E/OneSignal( 6855):     at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
E/OneSignal( 6855):     at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
E/OneSignal( 6855):     ... 5 more

Most helpful comment

They just released a new version Android SDK that fix this issue~!
I've manually modified the OneSignal Android SDK version in OneSignal Flutter SDK to 4.4.0 and it is working now~!

Can you provide some info on what to change?

image
image

try to look for the OneSignal dependency in your project and do according to the image shown. Good luck

All 21 comments

Not sure what is up, but after rolling back to older firebase, it seems to work.

Rolled back to:
firebase_core: ^1.0.1
firebase_analytics: ^7.1.1

Do we have solution for this?
I have the same issue, I tried @leossmith answer but it don't work

having the same issue as well after I updated Flutter to 2.2.0 I think
Edited: roll back to Flutter 2.0.6 still the same issue

Not sure what is up, but after rolling back to older firebase, it seems to work.

Rolled back to:
firebase_core: ^1.0.1
firebase_analytics: ^7.1.1

even tried this also not working

I have not figured out a solution after all. Looks like it works some times when others it doesnt. It is also very strange as it was working up to 3-4 days ago with the latest versions of all.

I tried migrating to onesignal 3 beta but i still get the same issue. It leads me to suspect some problem/conflict with google services. For now I had to release an update without the one signal plugin and wait for a fix.

This was what solved the problem for me:

pubspec.yaml :

dependency_overrides:
crypto: ^2.1.5
archive: ^2.0.13
firebase_dynamic_links: ^0.6.0
firebase_core: ^0.5.2
quiver: ^3.0.0
geolocator_platform_interface: ^2.0.2
plugin_platform_interface: 1.0.2

This was what solved the problem for me:

pubspec.yaml :

dependency_overrides:
crypto: ^2.1.5
archive: ^2.0.13
firebase_dynamic_links: ^0.6.0
firebase_core: ^0.5.2
quiver: ^3.0.0
geolocator_platform_interface: ^2.0.2
plugin_platform_interface: 1.0.2

Was that just downgrading firebase? which version of onesignal are you using?

This was what solved the problem for me:

pubspec.yaml :

dependency_overrides:
crypto: ^2.1.5
archive: ^2.0.13
firebase_dynamic_links: ^0.6.0
firebase_core: ^0.5.2
quiver: ^3.0.0
geolocator_platform_interface: ^2.0.2
plugin_platform_interface: 1.0.2

the downgrade of firebase version affects too many other plugins that I am currently using on my project... so it is not working for me

@leossmith I use onesignal_flutter: ^2.6.3

I just downgrade the firebase dependecies, you can maybe check the source code of one signal

Sadly rolling back firebase to a so old version is not an option. I am starting to consider moving to Firebase Messaging instead.

image

I just realised they committed and pushed these lines in their OneSignal-Android-SDK, therefore, I believe it is really an issue from the Android SDK plugin, so we have to wait for the fix from them.

image

I just realised they committed and pushed these lines in their OneSignal-Android-SDK, therefore, I believe

Yes it looks like it is only affecting android as iOS works ok.

Looks like Flutter sdk is way outdated compared to native.

It looks like this was a common issue in Android SDK and was fixed in newer versions:

https://github.com/OneSignal/OneSignal-Android-SDK/issues?q=is%3Aissue+firebase+iid+is%3Aclosed

They just released a new version Android SDK that fix this issue~!
I've manually modified the OneSignal Android SDK version in OneSignal Flutter SDK to 4.4.0 and it is working now~!

They just released a new version Android SDK that fix this issue~!
I've manually modified the OneSignal Android SDK version in OneSignal Flutter SDK to 4.4.0 and it is working now~!

Can you provide some info on what to change?

They just released a new version Android SDK that fix this issue~!
I've manually modified the OneSignal Android SDK version in OneSignal Flutter SDK to 4.4.0 and it is working now~!

Can you provide some info on what to change?

image
image

try to look for the OneSignal dependency in your project and do according to the image shown. Good luck

Thank you @danielseow-simplify . This solved my issue (on which i have spent like 5 hours trying to figure out how to fix it). I hope OneSignal will update their flutter sdk soon

I tried updatig the version for OneSignal Android SDK, but I get build errors now. Some of the errors:

C:\Users\user\AppData\Local\Pub\Cache\hosted\pub.dartlang.org\onesignal_flutter-2.6.3\android\src\main\java\com\onesignal\flutter\OneSignalOutcomeEventsController.java:4: error: cannot find symbol
import com.onesignal.OutcomeEvent;
^
symbol: class OutcomeEvent
location: package com.onesignal
C:\Users\user\AppData\Local\Pub\Cache\hosted\pub.dartlang.org\onesignal_flutter-2.6.3\android\src\main\java\com\onesignal\flutter\OneSignalOutcomeEventsController.java:31: error: cannot find symbol
public void onSuccess(OutcomeEvent outcomeEvent) {
^
symbol: class OutcomeEvent
location: class OSFlutterOutcomeEventsHandler

I tried updatig the version for OneSignal Android SDK, but I get build errors now. Some of the errors:

C:\Users\user\AppData\Local\Pub\Cache\hosted\pub.dartlang.org\onesignal_flutter-2.6.3\android\src\main\java\com\onesignal\flutter\OneSignalOutcomeEventsController.java:4: error: cannot find symbol
import com.onesignal.OutcomeEvent;
^
symbol: class OutcomeEvent
location: package com.onesignal
C:\Users\user\AppData\Local\Pub\Cache\hosted\pub.dartlang.org\onesignal_flutter-2.6.3\android\src\main\java\com\onesignal\flutter\OneSignalOutcomeEventsController.java:31: error: cannot find symbol
public void onSuccess(OutcomeEvent outcomeEvent) {
^
symbol: class OutcomeEvent
location: class OSFlutterOutcomeEventsHandler

I think it is better to upgrade your OneSignal Flutter to the latest beta version, also you will need to change the code for OneSignal in your project
Please refer to this link https://documentation.onesignal.com/docs/step-by-step-flutter-2x-to-300-upgrade-guide

I have the same problem. Can someone help? None of the above mentioned solutions are working for me.

I have the same problem. Can someone help? None of the above mentioned solutions are working for me.

Update to beta4 version, flutter clean, then rebuild. It should fix it.

This was due to a compatibility issue with Firebase FCM 22.0.0. I can confirm the issue has been fixed in the 3.0.0-beta4 Release and is now also included in the 2.6.4 Release we just released today.

This is the same issue as #402

Was this page helpful?
0 / 5 - 0 ratings