1

I'm trying to add Google FCM push notification function to Unity project. I'm surprised that there are no resources about Google FCM for Unity. There are only old Google GCM resources. This is my step-by-step progress below.

  1. Make Android Studio project and register it to a FCM console project
  2. Add google-service.json to '/app' and configure build.gradle (project and module)
  3. Add MyFirebaseInstanceIDService, MyFirebaseMessagingService java classes and onTokenRefresh, sendRegistrationToServer, onMessageReceived, sendNotification methods according to sample example in FCM document
  4. Add services for the classes to AndroidManifest.xml

    After that, I tested the Android Studio project on mobile, and FCM console push notification works well. Then, I started to configure the Android Studio project for Unity.

  5. Change 'application' to 'library' in build.gradle (module) and add deleteOldJar, exportJar for AndroidPlugin.jar
  6. Add classes.jar of Unity to Android Studio library and module setting
  7. Remove 'android:icon ...', 'android:theme ...' in AndroidManifest.xml
  8. Export jar and add AndroidPlugin.jar, AndroidManifest.xml to 'Plugins/Android' in Unity

    Then, I tested the Unity project on mobile. It is built without exception, but FCM console push notification didn't work. (I made test log for confirming that the Android Studio libray is well plugined for Unity, the log worked well)

Maybe, there are somethings to add to 'Plugins/Android' except AndroidManifest.xml and AndroidPlugin.jar like references below.

Google firebase analytics plugin for unity - StackOverflow
http://joxi.ru/Q2KeQD7C3zdYrj

But, I couldn't find my answer. Please let me know what I have to do or add. Sorry for bad english and long explanation. Many thanks :)

Community
  • 1
  • 1
USUM
  • 63
  • 9

2 Answers2

0

I used Unity SDK in OneSignal.
It is very simple, easy, and cool SDK for push notification.

Reference link below.
https://onesignal.com/

USUM
  • 63
  • 9
0

This approach will not be feasible.

Jar files do not contain resources, and as such, the json file will be missing from the jar build. Alternatively, aar files, which would in theory contain the resources, are interpreted by Unity3D as pure plugin and ignores the resources or at least some, specially when using gradle. But Unity is getting better at it.

Try https://firebase.google.com/docs/unity/setup. It's new and I got the sample project to work already.

Just to add: the new Plugin of Firebase for Unity3D worked liked a charm. Use cases like pure system try notification don't need a single line of additional programming on the client side. Data Messages are very easily implemented as well.

hfcgII
  • 1
  • 1
  • The only problem with FCM unity plugin is that you will not get data messages when app is in background. – Ashwin Apr 10 '19 at 15:11