Android: fcm in the library module

I ran into the strange problem of integrating Firebase Cloud Messaging in a library module. I am working on a library project in which I need to process notifications coming from the FCM server from the library itself. I do not know if this is possible or not.

Sequence of steps:

  • I created Project on the Firebase Console.
  • Inside the project, I created an application with a package similar to my library package.
  • I downloaded and placed google-services.jsonin the library module.
  • I applied the dependency in the gradle library module.
  • Now I have initialized my library module in the application module. I also get a log of the generated device token from FirebaseInstanceIdService.

Problem: When I try to send push from the Firebase Console, I do not receive any notifications.

Has anyone encountered such a problem and could help me?

+8
source share
5 answers

So, after repeated trial and error, I managed to get notifications.

It should be noted:

  • You cannot simply integrate Firebase Cloud Notifications into the library module.
  • The client application module that will use this library module will have a google-services.jsonfile in its directory, and not in the library module directory.
  • The gradle client application module will be below the line in it, and not in the gradle library module:

: 'com.google.gms.google-services'

, , .

+10

FCM Android 2.3 , Google Play Store Android 2.3 API Google.

, , API Google .

0

FCM Android Studio , , → > Firebase → > → > . → Firebase cloud messaging.

1,2,3. , Firebase, .

0

FCM "google_services.json". :

  • FCM
  • , Gradle ( google_services.json init. ):

    apply plugin: 'com.google.gms.google-services'
    
  • Firebase :

    implementation 'com.google.firebase:firebase-core:XX.X.X'  
    implementation 'com.google.firebase:firebase-messaging:XX.X.X'
    
  • . : res/values /strings.xml

    <string name="google_app_id" translatable="false">X:XXXXXXXXXX:android:XXXXXXXXXXXXX</string>
    
  • init FCM :

    public static void start(Context context){
        FirebaseOptions options = new FirebaseOptions.Builder()
                .setApplicationId("X:XXXXXXXXXX:android:XXXXXXXXXXXXX") // Required for Analytics.
                .setApiKey("XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX") // Required for Auth.
                .build();
        FirebaseApp.initializeApp(context, options);        
    }
    
  • ! , Application. onCreate() .

    LibName.start(getApplicationContext());
    

( , , , . , - .)

!

0
source

Check out this answer, please: fooobar.com/questions/6345825 / ... . Follow all the steps and it will work

0
source

Source: https://habr.com/ru/post/1016455/


All Articles