【问题标题】:Unity in android: failed to read firebase options from the app's resourcesandroid中的Unity:无法从应用程序的资源中读取firebase选项
【发布时间】:2019-11-26 03:43:42
【问题描述】:

我在 Unity 中使用 Firebase 包。当我在 Unity 编辑器中运行游戏时,它运行得非常好,但是,当我为 Android 构建游戏时,我得到了这个错误:

无法从应用的资源中读取 firebase 选项 确保 google-services.json 包含在您的构建中或指定选项 直接

我已经在 Assets 文件夹中有 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.
            }
        });
    }

谢谢!

【问题讨论】:

  • 尝试强制播放服务解析器运行。请参阅:medium.com/firebase-developers/… 关注此视频也可能会有所帮助:youtu.be/A6du3DUTIPI 如果您仍然遇到问题,请尝试为播放服务解析器启用详细日志记录并发布任何可能出现的消息。还要尽量避免使用任何特殊的文件夹名称,如果可以修复它,请发布更新:docs.unity3d.com/Manual/SpecialFolders.html(显然它必须在 Assets 中,但例如避免使用“Editor”)。

标签: c# android firebase unity3d


【解决方案1】:

这为我解决了这个问题,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

【讨论】:

  • 这对我使用 Unity 2020.2.2f1 有效。
【解决方案2】:

在您的 mainTemplate 文件中,您需要在底部添加它

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

【讨论】:

  • 使用 Unity 2020.1.17f1 为我工作
猜你喜欢
  • 1970-01-01
  • 2022-09-24
  • 1970-01-01
  • 1970-01-01
  • 2020-01-23
  • 1970-01-01
  • 1970-01-01
  • 2012-11-06
  • 1970-01-01
相关资源
最近更新 更多