You need to enable JavaScript to run this app.
最新活动
大模型
产品
解决方案
定价
生态与合作
支持与服务
开发者
了解我们

Unity集成Firebase FCM与Facebook插件后FCM回调失效求助

Firebase FCM Callbacks Not Triggered After Adding Facebook Unity Plugin 7.10.1

Let's break down the issue you're facing: your Firebase FCM setup worked perfectly in isolation, but once you added the Facebook Unity Plugin 7.10.1, even though FCM initializes successfully, you're not getting OnMessageReceived and OnTokenReceived callbacks. You suspect the com.google.firebase.MessagingUnityPlayerActivity isn't receiving events, even though your Android Manifest looks unchanged.

First, let's reference your provided manifest:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" package="${applicationId}" android:versionCode="1" android:versionName="1.0">
<application android:label="@string/app_name" android:icon="@drawable/app_icon">
<!-- The MessagingUnityPlayerActivity is a class that extends UnityPlayerActivity to work around a known issue when receiving notification data payloads in the background. -->
<activity android:name="com.google.firebase.MessagingUnityPlayerActivity" android:label="@string/app_name" android:icon="@drawable/app_icon" android:configChanges="fontScale|keyboard|keyboardHidden|locale|mnc|mcc|navigation|orientation|screenLayout|screenSize|smallestScreenSize|uiMode|touchscreen">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<meta-data android:name="unityplayer.UnityActivity" android:value="true" />
</activity>
<service android:name="com.google.firebase.messaging.MessageForwardingService" android:exported="false" />
<activity android:name="com.facebook.unity.FBUnityLoginActivity" android:configChanges="fontScale|keyboard|keyboardHidden|locale|mnc|mcc|navigation|orientation|screenLayout|screenSize|smallestScreenSize|uiMode|touchscreen" android:theme="@android:style/Theme.Translucent.NoTitleBar.Fullscreen" />
<activity android:name="com.facebook.unity.FBUnityDialogsActivity" android:configChanges="fontScale|keyboard|keyboardHidden|locale|mnc|mcc|navigation|orientation|screenLayout|screenSize|smallestScreenSize|uiMode|touchscreen" android:theme="@android:style/Theme.Translucent.NoTitleBar.Fullscreen" />
<activity android:name="com.facebook.unity.FBUnityAppLinkActivity" android:exported="true" />
<activity android:name="com.facebook.unity.FBUnityDeepLinkingActivity" android:exported="true" />
<activity android:name="com.facebook.unity.FBUnityGameRequestActivity" />
<activity android:name="com.facebook.unity.FBUnityCreateGameGroupActivity" />
<activity android:name="com.facebook.unity.FBUnityJoinGameGroupActivity" />
<activity android:name="com.facebook.unity.AppInviteDialogActivity" />
<meta-data android:name="com.facebook.sdk.ApplicationId" android:value="fb11111111111111" />
<provider android:name="com.facebook.FacebookContentProvider" android:authorities="com.facebook.app.FacebookContentProvider233093877143960" android:exported="true" />
</application>
</manifest>

Here are actionable steps to troubleshoot and fix this:

1. Confirm the Correct Launch Activity is Active

Even though your manifest marks MessagingUnityPlayerActivity as the LAUNCHER activity, Unity sometimes overrides this in Player Settings. Double-check:

  • Go to Edit > Project Settings > Player > Android > Resolution and Presentation
  • Under Launch Activity, ensure it's explicitly set to com.google.firebase.MessagingUnityPlayerActivity (not the default com.unity3d.player.UnityPlayerActivity or a Facebook-related activity)

2. Enforce Manifest Priority with tools:replace

Facebook's plugin might merge a secondary manifest that tries to set a different default activity. Add tools:replace="android:name" to your application tag to force your specified activity to take precedence:

<application 
    android:label="@string/app_name" 
    android:icon="@drawable/app_icon"
    tools:replace="android:name">

3. Verify the MessageForwardingService is Uninterrupted

This service is critical for forwarding FCM events to the Unity activity. Do these checks:

  • Ensure the service name is exactly com.google.firebase.messaging.MessageForwardingService (no typos)
  • Inspect the merged manifest generated by Unity during build (found in Temp/StagingArea/AndroidManifest.xml) to confirm no Facebook plugin services are conflicting or intercepting FCM events

4. Check Version Compatibility

Facebook Unity Plugin 7.10.1 is quite outdated (released around 2018), which may clash with newer Firebase SDK versions. Try:

  • Upgrading the Facebook Unity Plugin to a recent version that's compatible with your Firebase version
  • If upgrading isn't feasible, downgrade your Firebase SDK to a 5.x series release (the active branch around 2018)

5. Debug Activity Lifecycle

Add logging to MessagingUnityPlayerActivity to confirm it's launching and receiving events. Create a custom subclass and override key lifecycle methods:

public class CustomMessagingActivity extends com.google.firebase.MessagingUnityPlayerActivity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        android.util.Log.d("FCM_DEBUG", "MessagingUnityPlayerActivity initialized");
    }

    @Override
    protected void onNewIntent(Intent intent) {
        super.onNewIntent(intent);
        android.util.Log.d("FCM_DEBUG", "New FCM intent received: " + intent.getExtras());
    }
}

Update your manifest to use this custom activity, then check Logcat for these messages when launching the app and sending FCM test messages.

6. Adjust Initialization Order

Conflicts can arise if Firebase initializes before Facebook. Delay FCM setup until after Facebook finishes initializing in your Unity code:

void Start() {
    // Wait for Facebook to complete initialization first
    FB.Init(() => {
        // Now initialize Firebase FCM
        Firebase.FirebaseApp.CheckAndFixDependenciesAsync().ContinueWith(task => {
            var dependencyStatus = task.Result;
            if (dependencyStatus == Firebase.DependencyStatus.Available) {
                Firebase.Messaging.FirebaseMessaging.MessageReceived += OnMessageReceived;
                Firebase.Messaging.FirebaseMessaging.TokenReceived += OnTokenReceived;
                // Rest of your FCM setup logic
            }
        });
    });
}

Give these steps a try—they should help narrow down whether the issue stems from manifest merging, activity priority, or initialization order.

内容的提问来源于stack exchange,提问作者gaming Mohammed

火山引擎 最新活动