有没有办法在不使用Gradle的情况下使用Maven正确配置Firebase消息传递?
我已将此依赖项添加到pom.xml
<dependency>
<groupId>com.google.firebase</groupId>
<artifactId>firebase-messaging</artifactId>
<version>9.0.2</version>
<type>aar</type>
</dependency>
通过复制位于firebase AAR中的AndroidManifest.xml文件中的配置来修改我的AndroidManifest.xml。我没有找到使用过滤资源或像gradle插件这样的替换插件在maven buld中过滤它们的方法。
<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>
此外,添加了字符串资源(由配置json文件中的gradle插件自动设置)
<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>
运行应用程序后,我有这些日志
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
文档说Firebase会自动请求新令牌,但我从未收到 onTokenRefresh 回调 我错过了什么吗?
P.S:请不要建议使用Gradle ....
感谢任何帮助...... 感谢
答案 0 :(得分:2)
您的自定义实施几乎是正确的。 你错过了这个:
<receiver
android:name="com.google.firebase.iid.FirebaseInstanceIdInternalReceiver"
android:exported="false" />
但是......我必须警告你,手动修改AndroidManifest的方法是非常气馁。由于Gradle是由Gradle自动配置的,因此我们将其视为内部实施细节,而不是官方支持的API。
长话短说:清单配置可能会在任何版本中发生变化,如果您没有相应地更新您的清单,您的应用就会中断。
答案 1 :(得分:0)
问题解决了,谢谢迭戈
我只是想为AndroidManifest.xml添加一些额外的配置给那些将执行相同问题的人
(全部从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>