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

[Bug]: java.lang.NoClassDefFoundError encountered in OneSignal Flutter Plugin

Open pawankumar-creator opened this issue 1 year ago • 6 comments

What happened?

Description:

While using the OneSignal Flutter plugin, I encountered a java.lang.NoClassDefFoundError during runtime. This error wasn't observed during compile-time, and I believe it might be related to the plugin's implementation or a potential conflict with other plugins/dependencies.

Stack Trace:

Fatal Exception: java.lang.NoClassDefFoundError: pd.a
   at com.onesignal.flutter.OneSignalNotifications.q(SourceFile)
   at com.onesignal.flutter.OneSignalNotifications.onMethodCall(SourceFile)
   at ng.k$a.a(SourceFile)
   at bg.c.l(SourceFile)
   at bg.c.m(SourceFile)
   at bg.c.i(SourceFile)
   at bg.b.run(SourceFile)
   at android.os.Handler.handleCallback(Handler.java:739)
   at android.os.Handler.dispatchMessage(Handler.java:95)
   at android.os.Looper.loop(Looper.java:145)
   at android.app.ActivityThread.main(ActivityThread.java:6946)
   at java.lang.reflect.Method.invoke(Method.java)
   at java.lang.reflect.Method.invoke(Method.java:372)
   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1404)
   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1199)

flutter doctor

[!] Flutter (Channel stable, 3.13.6, on macOS 14.0 23A344 darwin-arm64, locale en-IN)
    ! Warning: `flutter` on your path resolves to /Users/taiyarikarlo/flutter/bin/flutter, which is not inside your current Flutter SDK checkout
      at /users/taiyarikarlo/flutter. Consider adding /users/taiyarikarlo/flutter/bin to the front of your path.
    ! Warning: `dart` on your path resolves to /Users/taiyarikarlo/flutter/bin/dart, which is not inside your current Flutter SDK checkout at
      /users/taiyarikarlo/flutter. Consider adding /users/taiyarikarlo/flutter/bin to the front of your path.
[✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
[✓] Xcode - develop for iOS and macOS (Xcode 15.0)
[✓] Chrome - develop for the web
[✓] Android Studio (version 2022.2)
[✓] VS Code (version 1.79.0)
[✓] Connected device (3 available)
[✓] Network resources

! Doctor found issues in 1 category.```


### Steps to reproduce?

```Markdown
1. onesignal_flutter:  ^5.0.3 previously I'm using ^3.0.0 

2. changes the code from this 
`OneSignal.shared.setAppId("");
  OneSignal.shared.promptUserForPushNotificationPermission().then((accepted) {
    print("Accepted permission: $accepted");
  });` 
to this at main() 
` OneSignal.initialize("");
  OneSignal.Notifications.requestPermission(true);`

3. flutter clean and flutter pub get completed.

Notification receiving properly, and no errors detected at emulator, but after releasing on production mode at Play Store it's throwing the fatal error and app crashing.

What did you expect to happen?

The plugin should operate without causing any runtime exceptions, especially NoClassDefFoundError

OneSignal Flutter SDK version

Release ^5.0.2

Which platform(s) are affected?

  • [ ] iOS
  • [X] Android

Relevant log output

No response

Code of Conduct

  • [x] I agree to follow this project's Code of Conduct

pawankumar-creator avatar Oct 29 '23 10:10 pawankumar-creator

Hi @pawankumar-creator, thanks for reporting.

NoClassDefFoundError means "The searched-for class definition existed when the currently executing class was compiled, but the definition can no longer be found."

Are you able to reproduce this consistently? And is this with a debug or release build?

Additionally, do you use any code obfuscation tools like Proguard or Dexguard?

nan-li avatar Nov 02 '23 01:11 nan-li

May or may not be related to https://github.com/OneSignal/OneSignal-Cordova-SDK/issues/910

nan-li avatar Nov 02 '23 01:11 nan-li

This might help

https://github.com/OneSignal/OneSignal-Flutter-SDK/issues/713#issuecomment-1692991176

sur2548 avatar Nov 03 '23 13:11 sur2548

Hi @pawankumar-creator, thanks for reporting.

NoClassDefFoundError means "The searched-for class definition existed when the currently executing class was compiled, but the definition can no longer be found."

Are you able to reproduce this consistently? And is this with a debug or release build?

Additionally, do you use any code obfuscation tools like Proguard or Dexguard?

The issue occurs when I use the latest version. It happens with the release build, not in debug. I'm not using any obfuscation tools.

pawankumar-creator avatar Nov 06 '23 03:11 pawankumar-creator

same problem using onesignal_flutter: ^5.0.4 on Android 5.0, 5.1 and 6.0 devices

tehKost avatar Dec 26 '23 00:12 tehKost

I keep getting the same error reported here...

I tried @sur2548 solution linked from the other issue, but for some reason the proguard rule -keep class com.onesignal.** only keeps the classes from onesignal android sdk... The com.onesignal.flutter classes are getting minified.

I performed a build and confirmed through mapping.txt that the Android code from Flutter Plugin keeps getting minified and throwing errors. Captura de Tela 2024-02-01 às 13 15 31

edisonlsm avatar Feb 01 '24 16:02 edisonlsm