OneSignal-Flutter-SDK icon indicating copy to clipboard operation
OneSignal-Flutter-SDK copied to clipboard

Error getting FCM Token - FirebaseInstanceId failed

Open leossmith opened this issue 5 years ago • 21 comments

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

leossmith avatar May 19 '21 14:05 leossmith

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

leossmith avatar May 20 '21 15:05 leossmith

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

Danis96 avatar May 21 '21 12:05 Danis96

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

danielseow-simplify avatar May 21 '21 13:05 danielseow-simplify

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.

leossmith avatar May 21 '21 22:05 leossmith

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

Danis96 avatar May 23 '21 16:05 Danis96

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?

leossmith avatar May 24 '21 09:05 leossmith

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

danielseow-simplify avatar May 24 '21 10:05 danielseow-simplify

@leossmith I use onesignal_flutter: ^2.6.3

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

Danis96 avatar May 24 '21 10:05 Danis96

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

leossmith avatar May 24 '21 11:05 leossmith

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.

danielseow-simplify avatar May 24 '21 13:05 danielseow-simplify

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.

leossmith avatar May 24 '21 14:05 leossmith

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

leossmith avatar May 25 '21 10:05 leossmith

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~!

danielseow-simplify avatar May 26 '21 09:05 danielseow-simplify

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?

leossmith avatar May 26 '21 10:05 leossmith

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

danielseow-simplify avatar May 26 '21 10:05 danielseow-simplify

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

leossmith avatar May 26 '21 12:05 leossmith

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

canturkay avatar May 31 '21 02:05 canturkay

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

danielseow-simplify avatar May 31 '21 09:05 danielseow-simplify

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

ashmitasarkar avatar Jun 02 '21 18:06 ashmitasarkar

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.

leossmith avatar Jun 03 '21 09:06 leossmith