创建一个 MAUI 应用程序并尝试将其连接到 Firestore。我按照此处的建议下载服务帐户 JSON 文件并设置GOOGLE_APPLICATION_CREDENTIALS环境变量。
我从我的 firebase 项目在线下载了我的服务文件,将其重命名为GoogleAppCredentials.json,然后使用构建操作“MauiAsset”将其包含在我的 MAUI 项目中,如下所示:
然后我的 cs 文件引用该文件:
string path = "GoogleAppCredentials.json";
Environment.SetEnvironmentVariable("GOOGLE_APPLICATION_CREDENTIALS", path);
Run Code Online (Sandbox Code Playgroud)
但是当我在 Android 模拟器上运行该应用程序时,出现以下错误:
System.AggregateException
Message=One or more errors occurred. (Error reading credential file from location GoogleAppCredentials.json: Could not find file '/GoogleAppCredentials.json'.
Please check the value of the Environment Variable GOOGLE_APPLICATION_CREDENTIALS)
Run Code Online (Sandbox Code Playgroud)
在 Windows 机器上...
System.AggregateException
Message=One or more errors occurred. (Error reading credential file from location GoogleAppCredentials.json: Could not find file 'C:\WINDOWS\system32\GoogleAppCredentials.json'.
Please …Run Code Online (Sandbox Code Playgroud)