Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Question Android Notifications Not Working On Release Build

Discussion in 'Android' started by soulcryy, Feb 22, 2022.

  1. soulcryy

    soulcryy

    Joined:
    Sep 15, 2020
    Posts:
    9
    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.
     
    Last edited: Feb 23, 2022
  2. Aurimas-Cernius

    Aurimas-Cernius

    Unity Technologies

    Joined:
    Jul 31, 2013
    Posts:
    3,637
    You mean everything works in development build but not in release?
    What are you minification settings?
     
  3. soulcryy

    soulcryy

    Joined:
    Sep 15, 2020
    Posts:
    9
    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.
    Code (CSharp):
    1. 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:
    https://github.com/Unity-Technologies/NotificationsSamples/issues/30

    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
    Code (CSharp):
    1. -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.
     
    Last edited: Feb 23, 2022
  4. Felicionato

    Felicionato

    Joined:
    Nov 9, 2015
    Posts:
    4
    I'm using Mobile Notfications 2.0.2, and had this issue, solution worked for me
     
  5. Cuisor

    Cuisor

    Joined:
    Feb 19, 2015
    Posts:
    4
    This worked for me. Thanks for sharing!