32955

Configure Firebase push messages with Maven Android project

Question:

Is there a way to properly configure Firebase messaging with Maven without using Gradle?

I've added this dependency to pom.xml

<dependency> <groupId>com.google.firebase</groupId> <artifactId>firebase-messaging</artifactId> <version>9.0.2</version> <type>aar</type> </dependency>

And modified my AndroidManifest.xml by copying configs from AndroidManifest.xml file located in firebase AAR. I didn't find the way to filter them during maven buld using filtering resources or replacer plugin like gradle plugin do.

<uses-permission android:name="android.permission.WAKE_LOCK" /> <uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" /> <permission android:name="<MY_APP_PACKAGE>.permission.C2D_MESSAGE" android:protectionLevel="signature" /> <uses-permission android:name="<MY_APP_PACKAGE>.permission.C2D_MESSAGE" /> <!-- copied from firebase common module to be able to set <MY_APP_PACKAGE> (that is set during compilation with gradle plugin) --> <provider android:authorities="<MY_APP_PACKAGE>.firebaseinitprovider" android:name="com.google.firebase.provider.FirebaseInitProvider" android:exported="false" android:initOrder="99" /> <!-- copied from firebase iid module to be able to set <MY_APP_PACKAGE> (that is set during compilation with gradle plugin) --> <receiver android:name="com.google.firebase.iid.FirebaseInstanceIdReceiver" android:exported="true" android:permission="com.google.android.c2dm.permission.SEND" > <intent-filter> <action android:name="com.google.android.c2dm.intent.RECEIVE" /> <action android:name="com.google.android.c2dm.intent.REGISTRATION" /> <category android:name="<MY_APP_PACKAGE>" /> </intent-filter> </receiver> <service android:name=".service.PushMessageService"> <intent-filter> <action android:name="com.google.firebase.MESSAGING_EVENT" /> </intent-filter> </service> <service android:name=".service.GoogleIDService"> <intent-filter> <action android:name="com.google.firebase.INSTANCE_ID_EVENT" /> </intent-filter> </service>

Also, added string resources (that auto set by gradle plugin from config json file)

<string name="google_app_id" translatable="false">...</string> <string name="google_api_key" translatable="false">...</string> <string name="firebase_database_url" translatable="false">...</string> <string name="ga_trackingId" translatable="false">...</string> <string name="gcm_defaultSenderId" translatable="false">...</string> <string name="google_storage_bucket" translatable="false">...</string>

After running the app I had these logs

D/FirebaseApp﹕ com.google.firebase.auth.FirebaseAuth is not linked. Skipping initialization. D/FirebaseApp﹕ Initialized class com.google.firebase.iid.FirebaseInstanceId. D/FirebaseApp﹕ com.google.firebase.crash.FirebaseCrash is not linked. Skipping initialization. D/FirebaseApp﹕ com.google.android.gms.measurement.AppMeasurement is not linked. Skipping initialization. I/FirebaseInitProvider﹕ FirebaseApp initialization successful

The docs says Firebase will request new token automatically but I never receive <strong>onTokenRefresh</strong> callback Is there anything I missed?

P.S: Please don't suggest using Gradle....

Any help is appreciated... Thanks

Answer1:

Your custom implementation is almost correct. You are missing this:

<receiver android:name="com.google.firebase.iid.FirebaseInstanceIdInternalReceiver" android:exported="false" />

BUT.. I have to warn you that the approach of manually modifying the AndroidManifest is <strong>highly discouraged</strong>. Since the manifest is automatically configured by Gradle we consider it as an <strong>internal implementation details</strong> and not officially supported API.

Long story short: the manifest configuration could change at any release, and your app would break if you don't update your manifest accordingly.

Answer2:

The issue resolved, thanks Diego

I just wanted to add some additional configs to AndroidManifest.xml for someone who will perform same issue

(all copied from firebase AndroidManifest.xml

<!-- Internal (not exported) receiver used by the app to start its own exported services without risk of being spoofed. --> <receiver android:name="com.google.firebase.iid.FirebaseInstanceIdInternalReceiver" android:exported="false" /> <!-- FirebaseInstanceIdService performs security checks at runtime, no need for explicit permissions despite exported="true" --> <service android:name="com.google.firebase.iid.FirebaseInstanceIdService" android:exported="true"> <intent-filter android:priority="-500"> <action android:name="com.google.firebase.INSTANCE_ID_EVENT" /> </intent-filter> </service> <!-- FirebaseMessagingService performs security checks at runtime, no need for explicit permissions despite exported="true" --> <service android:name="com.google.firebase.messaging.FirebaseMessagingService" android:exported="true"> <intent-filter android:priority="-500"> <action android:name="com.google.firebase.MESSAGING_EVENT" /> </intent-filter> </service>

Recommend

  • Python execution speed: laptop vs desktop
  • Client Function Not getting called SignalR
  • How unique a 5-digit mt_rand() number is?
  • Why is tzset() a lot slower after forking on Mac OS X?
  • error inserting values to db with psycopg2 module
  • Passing cookies in Response.Redirect in ASP.NET
  • How to generate strong-naming SNK key file with .net libraries
  • What makes the FederatedAuthentication.SessionAuthenticationModule return NULL?
  • No dimensions set for key window
  • Does IntelliJ start processes with Administrator rights?
  • In PHP, what is a binary string (b'xxxx')?
  • In Laravel, is there a way to find out whether `firstOrCreate` created or if it found the row?
  • A better online editor for GitHub.com and GitHub Pages?
  • Closing a connection in a loop
  • Camera2 Set Fixed Resolution
  • Continuous colorbar with contour levels
  • Set cookies with Javascript to remember show state by click
  • Why is ftp_nlist returning an empty array for a non-empty directory?
  • How to start camel even if the MQTT server is not reachable
  • show Custom Message at Table area in jqGrid
  • Find indices of 2D arrays using conditional statement in Python
  • redirect external url in browser
  • bulk collect …for all usage
  • pt-table-sync, Strange Issues regarding Hostname
  • A glow around a circular image with CSS on hover
  • Using HTML POST to upload file via PHP
  • Java Regex Finding digits in a String
  • pyodbc fails without error
  • InternetExplorer.Application with -nomerge switch?
  • How do you maintain page number after redirect in CakePHP?
  • FirebaseAnimatedList change content in real time
  • How to implement JQuery confirm dialog with JSF