我创建了一个Android库,用于在我的内部项目中实现FCM。我创建了一个类来扩展FirebaseMessagingService (.services.MyFirebaseMessagingService
),另一个类来扩展FirebaseInstanceIdService (.services.MyFirebaseInstanceIDService
)。
我在库的AndroidManifest.xml文件中定义了如下内容:
<!-- [START firebase_service] -->
<service
android:name=".services.MyFirebaseMessagingService"
android:exported="true">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT" />
</intent-filter>
</service>
<!-- [END firebase_service] -->
<!-- [START firebase_iid_service] -->
<service android:name=".services.MyFirebaseInstanceIDService">
<intent-filter>
<action android:name="com.google.firebase.INSTANCE_ID_EVENT" />
</intent-filter>
</service>
<!-- [END firebase_iid_service] -->
当我在我的应用程序中将所有库源代码作为模块引入时,一切正常,但当我仅包含生成的AAR文件时,在运行应用程序时收到以下错误消息:
java.lang.RuntimeException: Unable to instantiate service com.example.lib.services.MyFirebaseMessagingService: java.lang.ClassNotFoundException: com.example.lib.services.MyFirebaseMessagingService
at android.app.ActivityThread.handleCreateService(ActivityThread.java:2380)
at android.app.ActivityThread.access$1600(ActivityThread.java:138)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1286)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4905)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:790)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:557)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.ClassNotFoundException: com.example.lib.services.MyFirebaseMessagingService
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:61)
at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
at android.app.ActivityThread.handleCreateService(ActivityThread.java:2377)
at android.app.ActivityThread.access$1600(ActivityThread.java:138)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1286)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4905)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:790)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:557)
at dalvik.system.NativeStart.main(Native Method)
服务com.example.lib.services.MyFirebaseInstanceIDService工作正常。
我需要做什么才能让生成的AAR库正常工作?
com.google.firebase:firebase-messaging:9.8.0
,那么我就不需要在应用程序依赖项中再次包含它。 - davips