0

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 onTokenRefresh callback Is there anything I missed?

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

Any help is appreciated... Thanks

3
  • you must login with firebase Commented Jul 20, 2016 at 11:15
  • It looks like the FirebaseApp is initializing, but not pulling in some of its (normally transitive) dependencies. That doesn't have to be a problem. For the onTokenRefresh() part: not that this method will only be called when the token is refreshed. If you added the code after the token was generated, it won't get called. To test if this is the case, log the value of ` FirebaseInstanceId.getInstance().getToken()` somewhere to see if your device/app has a token. Commented Jul 20, 2016 at 14:40
  • Cross-post: groups.google.com/forum/#!topic/firebase-talk/PlH-tKo6dL8 Commented Jul 21, 2016 at 1:24

2 Answers 2

2

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 highly discouraged. Since the manifest is automatically configured by Gradle we consider it as an internal implementation details 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.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for help. It worked! But I don't use Gradle, this is only Maven implementation
0

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> 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.