You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

.NET Android中Firebase Messaging初始化失败、无法获取Token求助

Fixes for Firebase Messaging Token Issue in .NET Android Migration

1. Ensure google-services.json has the correct Build Action

  • Right-click google-services.json in Solution Explorer → Properties
  • Set Build Action to GoogleServicesJson (this ensures the file is processed by the google-services plugin)

2. Add the google-services Gradle plugin reference

Edit your project's .csproj file and add this entry to directly resolve the plugin application error:

<ItemGroup>
  <GradlePluginReference Include="com.google.gms.google-services" Version="4.4.1" />
</ItemGroup>

3. Remove manual FirebaseApp.InitializeApp call

Newer Firebase versions automatically initialize via FirebaseInitProvider. Delete the FirebaseApp.InitializeApp(this); line from your OnCreate method—manual calls can conflict with automatic initialization.

4. Update outdated AndroidManifest receiver entries

The FirebaseInstanceIdReceiver and FirebaseInstanceIdInternalReceiver are deprecated. Replace your existing receiver entries in AndroidManifest.xml with:

<receiver android:name="com.google.firebase.messaging.FirebaseMessagingReceiver" android:exported="true" android:permission="com.google.android.c2dm.permission.SEND">
    <intent-filter>
        <action android:name="com.google.android.c2dm.intent.RECEIVE" />
        <category android:name="${applicationId}" />
    </intent-filter>
</receiver>

5. Verify package name consistency

  • Confirm the package_name field in google-services.json exactly matches your project's Application ID (found in Project Properties → Android Manifest → Package name)
  • Mismatched names will block Firebase from loading the correct configuration.

6. Clean and rebuild the project

  • Delete the bin and obj folders from your project directory
  • Clean the solution (Build → Clean Solution)
  • Rebuild the solution (Build → Rebuild Solution)
    This clears cached build artifacts that may cause conflicts.

7. Align all Firebase NuGet package versions

Ensure all Firebase-related NuGet packages (e.g., Xamarin.Firebase.Core, Xamarin.Firebase.Messaging) are on the same version. Mismatched versions often lead to initialization failures.

After applying these steps, run the app again. You should see the OnNewToken log output once the token is successfully generated.

内容的提问来源于stack exchange,提问作者Balint Fodor

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.09 06:17:25