5

I'm currently trying to implement push notifications in our application.

So we have three modules.

  • App 1
  • Logic
  • App 2

I gave them obviously names. App 1 and 2 have a dependency on the logic module. This module contains ALL the logic for both apps. Now I want App specific notifications to users that are logged in on App 1 OR App 2.

Problem:

I can't put the firebase logic into the Logic module since this module is configured as a lib module and isn't configured as an App. Now I have to put the firebase logic in App 1 and 2, but I can't access this logic from the Logic module since App 1 and 2 have a dependency on the Logic module and not the other way around.

Firebase requires a google-services.json for every app connected, this file is required to generate a user specific pushtoken.

Is there a way to configure this so that I can generate user specific tokens for push notifications? So after a user logs in a pushtoken has to be generated according to the App and user so this user can get a notifcation on said device which he/she is logged in.

I hope this is clear enough.

sunadorer
  • 3,855
  • 34
  • 42
Jordi
  • 53
  • 1
  • 4
  • sorry, it's not clear enough, what is app 1 and app 2? two separated applications? – mayosk Feb 06 '17 at 16:16
  • Two separated applications who use the logic from the module Logic. But in the Logic module there are certain behaviors that are different for each App. – Jordi Feb 06 '17 at 16:22
  • you can't do that this way, firebase does not require google-services.json, but google play services itself (lib), you need to do that manually – mayosk Feb 06 '17 at 16:24
  • But don't the firebase dependencies require the google play services lib? Or can I just compile the firebase dependency in the Logic module? – Jordi Feb 06 '17 at 16:28
  • exactly, firebase lib need google play services plugin, that's why you need to do it manually – mayosk Feb 06 '17 at 16:31

2 Answers2

3

There should be nothing stopping you from implementing what you're describing.

You can still add Firebase SDK dependencies to a library module. You just can't use the google-services plugin on it - that belongs only on application modules.

Doug Stevenson
  • 297,357
  • 32
  • 422
  • 441
  • Ahh yes, i've tried this and it works indeed. Thanks! – Jordi Feb 07 '17 at 09:09
  • I have a similar problem where I added the firebase sdk to my library module and applied the plugin to the app module. But its giving me a collision saying : `'com.google.android.gms:play-services-base' has different version for the compile (9.0.0) and runtime (11.4.0) classpath. You should manually set the same version via DependencyResolution` Any tips on how to fix this? – Naveed Oct 05 '17 at 05:32
  • @Naveed did you found an answer for your question? I've some trouble with the same scenario. – Tobonaut Nov 26 '17 at 16:09
  • Make sure you are using the latest version of play services. That was the problem I was having. Check your top level gradle to ensure play services version: `com.google.gms:google-services:3.1.1` – Naveed Nov 27 '17 at 17:54
  • I am facing the same issue and not sure how to fix this. Can you please share the steps to fix this issue? – abdulH Aug 19 '18 at 17:56
  • Guys whats is the solution exactly? – Pedro Massango Mar 29 '19 at 12:59
0

A more updated answer: You CAN create a module of Firebase Cloud Notifications separated from an app client To make it work you have to:

On Module (Library):

  • Add implementation 'com.google.firebase:firebase-messaging:17.6.0' in module gradle file
  • Add

    <service android:name=".firebase.YourNotificationService"> <intent-filter> <action android:name="com.google.firebase.MESSAGING_EVENT" /> </intent-filter> </service>

in the Android Manifest file.

On your app client:

  • Add apply plugin: 'com.google.gms.google-services' on the last line in your module gradle file
  • Add implementation 'com.google.firebase:firebase-core:16.0.8' in your module gradle file
  • Add implementation'com.google.firebase:firebase-messaging:17.6.0' in your module gradle file
  • Add classpath 'com.google.gms:google-services:4.2.0' inside "dependencies" block of your project gradle file
  • Add your "google-services.json" file inside your "app" folder

And that's it. That will work.

Dan Ponce
  • 636
  • 1
  • 8
  • 24