Search code examples
androidunity-game-enginefirebase-cloud-messaging

Unable To Change Firebase Push Notification Icon in Unity


I want to Change the default Firebase Icon that is displayed when sending Push Notification (Firebase Cloud Messaging), but I'm not able to do so in Unity, I tried Many methods available on Google and StackOverFlow, But None of Them Worked. Please Help me with Your Solutions...

I tried adding res folder to Assets\Plugins\Android but it shows OBSOLETE - Providing Android resources in Assets/Plugins/Android/res was removed, I also tried using .aar method but it shows

> Could not resolve all files for configuration ':unityLibrary:releaseCompileClasspath'.
   > Failed to transform ic_stat_sb-.aar (:ic_stat_sb:) to match attributes {artifactType=android-classes-jar, org.gradle.status=integration, org.gradle.usage=java-api}.

Solution

  • The solution to this is to build an AAR library that contains your icons. Here's how you can do it with Android Studio.

    • After installing Android Studio, start a fresh empty project, or use an existing one, the project doesn't matter.
    • Click on File => New => New Module...
    • Change the name to what you want (ex: NotificationIcon)
    • I've selected Java and min sdk of 26 to match my unity settings, if you have higher/lower sdk version setup in unity I would suggest using the same one. New Module
    • Click Next and you will see your library in the explorer window of android Studio, if it doesn't show up right away, wait a minute it might be creating it.
    • Inside the library files you will find manifests folder, open it and change the AndroidManifest.xml to this
        <?xml version="1.0" encoding="utf-8"?>
        <manifest xmlns:android="http://schemas.android.com/apk/res/android">
           <application>
               <meta-data
                
        android:name="com.google.firebase.messaging.default_notification_icon"
                    android:resource="@drawable/ic_stat_card_giftcard" />
            </application>
        </manifest>
    
    • Make sure to change the name of the icon ic_stat_card_giftcard to what your icon name is.
    • At this point you will get an error that the res folder doesn't exist and Android studio will suggest to generate it with an xml file inside.
    • Generate the res folder, delete the xml file and paste your icons inside the res folder, you should have a file structure like this, given that your icons were each in its own folder per resolution. PS: if you are unable to paste directly in Android Studio, right click the res folder, open In => Explorer and you can paste normally there.

    enter image description here

    • Last step is to build this library now, click on Gradle, its either on left or right panels, first button top left (Execute Gradle Task) and type in build click Enter.

    enter image description here

    • Gradle should start the build and once done you can find your .aar file in the same directory as your application under MyApplication<YourLibraryName>\build\outputs\aar

    • Take that aar file and copy it into Unity assets/Plugins/Android and build your game.

    You should be able to see the icon once you receive a notification from firebase!