Unity集成Firebase/FB SDK导出Android Studio构建报错:客户端不匹配
Let’s break down what’s happening here: That error pops up because the package name specified in your google-services.json file doesn’t match the actual package name your Android project is using. The com.google.firebase.unity value is the default test package name from the Firebase Unity SDK—so your project isn’t correctly passing your app’s real package name through to the build pipeline.
Here’s how to fix this step by step:
First, lock in your Unity project’s package name
Open Unity, go toEdit > Project Settings > Player, switch to the Android tab, and check theIdentification > Package Namefield. Make sure this is set to your app’s actual package name (e.g.,com.yourcompany.yourgame)—not the default test value. This is the foundation of fixing the mismatch.Download a fresh, correct
google-services.json
Head to the Firebase Console, navigate to your project, and go to Project Settings. In the "Apps" section:- If you already have an Android app registered, confirm its package name matches what you set in Unity.
- If not, add a new Android app using your Unity package name.
- Download the updated
google-services.jsonfile, and replace the old one in your Unity project’sAssets/Plugins/Androidfolder.
Clean up Unity’s build cache and reconfigure Firebase
- Make sure you’re using the latest stable version of the Firebase Unity SDK—outdated versions can cause package name sync issues.
- If you manually edited any AndroidManifest.xml or Gradle files in Unity, revert those changes. Let Unity handle generating the correct build config automatically.
- Run
File > Build Settings > Clean Buildto wipe old build artifacts that might be holding onto the wrong package name.
Export to Android Studio correctly
When exporting from Unity:- Check the "Export Project" option.
- Don’t tweak package name settings in the export wizard—let Unity pass through the package name you set in the Player Settings.
- Once exported, open the project in Android Studio.
Final checks in Android Studio
- Open
app/build.gradleand verify theapplicationIdmatches your app’s package name. - Confirm the
google-services.jsonfile is in theappdirectory (Unity should place it there automatically, but double-check). - Run
File > Sync Project with Gradle Filesto ensure all configs are aligned, then try building again.
- Open
A quick heads-up if you’re also using Facebook SDK: Make sure your Facebook app dashboard’s package name matches your Unity project’s package name too—mismatches here can cause secondary build conflicts.
内容的提问来源于stack exchange,提问作者cooltogo




