Android Notifications Not Working On Release Build

Well, I got stuck again and open to any advice. My problem is, when I built my game in release mode, there is a problem on sending notifications. I want to debug it, build a development version with script debugging, this time there is no problem and everything is working perfectly.

In the end, I can not debug the problem. Any advice? What exactly Unity is doing in release builds?

Testing Device: Samsung S10+ (Android 12)
Unity Editor:2021.2.12f1
Mobile Notifications:1.4.2

Edit: Removed lines of code to make the topic shorter, as it’s no longer related. See my second post in this topic for the solution I have found.

You mean everything works in development build but not in release?
What are you minification settings?

First of all thank you for the reply. By luck, I was able to detect exception message on unity cloud system. I’m on mobile and will edit my post in detail when on desktop but as summary, I had to generate custom proguard settings, and add a line to it. I found the solution to my problem on github discussion of unity technologies/notification sample.

As I said, I will update this reply in detail in case someone else is having a similiar problem.

Ps. As you said, the problem was only happening only on release build (due to proguard removing some unity component as far as i understand).

Edit:
As promised, here are the exact problem and solution.

In Unity Gaming Services β†’ DevOps β†’ Cloud Diagnostic β†’ Crash and Exception Reporting I was able to see below exception.

AndroidJavaException: java.lang.NoSuchMethodError: no static method with name='getNotificationManagerImpl' signature='(Landroid.app.Application;Lcom.unity3d.player.UnityPlayerActivity;)Ljava/lang/Object;' in class Ljava.lang.Object;

When I searched google I found below topic:

As suggested under this topic, in my build options I enabled custom proguard file (Player Settings β†’ Publishing Settings β†’ Custom Proguard File) and in Assets/Plugins/Android/proguard-user.txt I added following line

-keep class com.unity.** { *; }

And this was the solution to my problem with Unity Mobile Notification on android. I hope this can help also other people.

6 Likes

I’m using Mobile Notfications 2.0.2, and had this issue, solution worked for me

This worked for me. Thanks for sharing!