OneSignal / OneSignal-Android-SDK

OneSignal is a free push notification service for mobile apps. This plugin makes it easy to integrate your native Android or Amazon app with OneSignal. https://onesignal.com
Other
591 stars 368 forks source link

[Bug]: INotificationServiceExtension not call in release apk, but work in debug mode #2044

Closed welcome14 closed 1 week ago

welcome14 commented 2 months ago

What happened?

the service INotificationServiceExtension is called when i use a debug mode, but when i create a build in release mode, the service not work.

minSdkVersion 21 targetSdkVersion 34 compileSdk 34 buildToolsVersion '35.0.0 rc2'

implementation 'com.onesignal:OneSignal:5.1.7'

Gradle 8.7

write in java language

Steps to reproduce?

send notification with app in background.

What did you expect to happen?

null

OneSignal Android SDK version

34

Android version

13

Specific Android models

No response

Relevant log output

null

Code of Conduct

jkasten2 commented 2 months ago

@welcome14 we need a bit more information to investigate:

  1. Can you add @Keep to your class the implements INotificationServiceExtension?
    • This will make sure your class is not renamed or removed due to minification setting you may have on release
  2. Do you get any errors in the logcat?
    • Enable OneSignal Verbose logging if you are not seeing any errors.
  3. Can you try disabling all minification in your release build?
    • Progurd, R8, etc.
welcome14 commented 2 months ago

i have disable the minification, and it works!

buildTypes { release { minifyEnabled true } }

jkasten2 commented 2 months ago

@welcome14 does adding @Keep to your class also solve the problem? As it is recommended to use minification in release builds.

AroundPixels commented 3 weeks ago

Same problem here, but solved with @Keep.

Setting minifyEnabled false worked for release app, so as @jkasten2 said I added @Keep to my implementation of OneSignal.OSRemoteNotificationReceivedHandler (I'm still in OneSignal 4.8) and it worked!

I think the problem is related to the upgrade of AGP from v7 to v8, this will make that the minify goes too far away...