Android 中的 Unity:无法从应用资源中读取 Firebase 选项



我在Unity中使用Firebase包。当我在 Unity 编辑器中运行游戏时,它运行良好,但是,当我为 Android 构建游戏时,我收到此错误:

无法从应用的资源中读取 Firebase 选项,也无法使 确保Google-Services.json包含在您的构建中或指定选项 径直

我已经在资产文件夹中有google-services.json文件,我按照此处的建议添加了以下代码块(https://firebase.google.com/docs/unity/setup(:

private void ConfirmGooglePlayerServicesRequirements()
{
Firebase.FirebaseApp.CheckAndFixDependenciesAsync().ContinueWith(task => {
var dependencyStatus = task.Result;
if (dependencyStatus == Firebase.DependencyStatus.Available)
{
// Create and hold a reference to your FirebaseApp,
// where app is a Firebase.FirebaseApp property of your application class.
app = Firebase.FirebaseApp.DefaultInstance;
// Set a flag here to indicate whether Firebase is ready to use by your app.
firebaseIsReadyToBeUsed = true;
}
else
{
Debug.LogError(System.String.Format(
"Could not resolve all Firebase dependencies: {0}", dependencyStatus));
// Firebase Unity SDK is not safe to use here.
}
});
}

谢谢!

这为我解决了,2020 版,看这里:

为了支持无法自定义 Gradle 构建的 Unity 版本,Firebase 编辑器工具会生成 Assets/Plugins/Android/Firebase/res/values/google-services.xml作为要打包到 Android 版本中的 Android 资源,以便 Firebase SDK 可以使用它来初始化默认的 FirebaseApp 实例。

在 Unity 2020 中,所有 Android 资源都必须位于带有 .androidlib 后缀的目录中。如果您的项目使用的是生成 Assets/Plugins/Android/Firebase 目录的 Firebase SDK,请将其重命名为 Assets/Plugins/Android/Firebase.androidlib。确保它包含AndroidManifest.xml,project.properties和res/values/google-services.xml。

来源: https://firebase.google.com/docs/unity/setup#missing_firebase_android_config_file_in_unity_2020

在你的 mainTemplate 文件中,你需要在底部添加这个:

android {
sourceSets {
main {
def unityProjectPath = $/file:///**DIR_UNITYPROJECT**/$.replace("\", "/")
res.srcDirs += (unityProjectPath + '/Assets/Plugins/Android/Firebase/res/values/google-services.xml')
}
}
}

我在 Unity 2022 中遇到了同样的问题。 操作系统 : 视窗 , 目标 : 安卓

Firebase.Editor.dll 无法正常工作,因为它找不到 Xcode 插件。 解决方案:在Windows上安装iOS构建支持。它神奇地解决了与所有谷歌产品(Admob ,Analytics,Crashlytics(相关的所有错误 奇怪但有效!

最新更新