Xamarin Firebase不同的google-services,json用于不同的构建配置 [英] Xamarin firebase different google-services,json for different build configurations

查看:82
本文介绍了Xamarin Firebase不同的google-services,json用于不同的构建配置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在xamarin.android项目中,我们有2个构建配置(Basic和Pro)以及不同的Package Name.

在firebase上,我们在同一项目中注册了两个基本版和专业版应用程序.因此,现在我们有两个google-services.json文件.

现在的问题是-如何在不同的构建配置上处理不同的google-services.json文件.

解决方案

已解决: Xamarin firebase针对不同的编译设置使用了不同的google-services.json.

尝试 @SushiHangover 解决方案后,在进行构建时会发生以下异常,如下所示:

无法读取或反序列化GoogleServicesJson文件: google-services.json System.IO.FileNotFoundException:找不到 文件[您的根目录] \ google-services.json".

[您的软件包目录] \ Xamarin.GooglePlayServices.Basement.60.1142.1 \ build \ MonoAndroid80 \ Xamarin.GooglePlayServices.Basement.targets(66,5): 错误:无法读取或反序列化GoogleServicesJson文件: google-services.json.

解决方案:使用构建前事件命令行

1. 在[ProjectDir]上创建包含不同google-services.json文件的文件夹.

示例:

[ProjectDir]/GoogleServices>

google-services-development.json
google-services-production.json
google-services-any.json

其中 [ProjectDir] 是您的项目目录路径.

2..在您的[ProjectDir]级别创建伪造的 google-services.json .

3. 将其包含在您的项目中.

4. 转到属性> Build Action> GoogleServicesJson .

5. 创建构建配置.这是在编译和执行项目并选择对配置进行操作的GoogleServiceJson之前将用于更改配置的内容

转到Build>配置管理器...>活动解决方案配置>新建...

设置配置名称,然后单击确定".

6. 选择刚刚创建的配置(转到Build> Configuration manager ...>活动解决方案配置并选择它,然后关闭)并配置命令以复制文件从您的文件夹 GoogleServices 到预编译事件中的 [ProjectDir] .

转到项目> [您的项目名称]属性...>构建>预构建事件命令行>编辑预构建

7. 添加命令,将指定的文件复制到您的配置中.

生产配置示例:

对于您拥有的每个google-service.json,从5步重复到7步.

用于开发配置的示例命令:

COPY /Y "$(ProjectDir)GoogleServices\google-services-development.json" "$(ProjectDir)google-services.json"

用于生产配置的示例命令:

COPY /Y "$(ProjectDir)GoogleServices\google-services-production.json" "$(ProjectDir)google-services.json"

任何配置的示例命令:

COPY /Y "$(ProjectDir)GoogleServices\google-services-any.json" "$(ProjectDir)google-services.json"

现在,您可以在Build配置之间进行动态切换,以执行所需的json.

有关预构建事件的更多信息 解决方案

Solved: Xamarin firebase different google-services.json for different compilation settings.

After trying @SushiHangover solution, the following exception occurred when doing build, something like this:

Failed to Read or Deserialize GoogleServicesJson file: google-services.json System.IO.FileNotFoundException: Could not find file [your root directory]\google-services.json'.

at

[your packages directory]\Xamarin.GooglePlayServices.Basement.60.1142.1\build\MonoAndroid80\Xamarin.GooglePlayServices.Basement.targets(66,5): error : Failed to Read or Deserialize GoogleServicesJson file: google-services.json.

Solution: Using Pre-Build event command line

1. Create the folder that contains the different google-services.json files at your [ProjectDir].

Example:

[ProjectDir]/GoogleServices >

google-services-development.json
google-services-production.json
google-services-any.json

where [ProjectDir] is your project directory path.

2. Create a fake google-services.json at your [ProjectDir] level.

3. Include that at your project.

4. Go to properties > Build Action> GoogleServicesJson.

5. Create your build configuration. This is what you will use to change the configuration before compiling and executing the project and choosing which GoogleServiceJson will take action with your configuration.

Go to Build> Configuration manager...> Active solution configuration > New...

Set the name of your configuration and click Ok.

6. Select the configuration you just created (Go to Build> Configuration manager...> Active solution configuration and select it, then close) and configure the command to copy the file from your folder GoogleServices to the [ProjectDir] in the pre-compiled event.

Go to Project> [Your project name] properties... > Build > Pre-Build event command line> Edit pre-build

7. Add your command to copy the file specified to your configuration.

Example with production configuration:

Repeat steps from 5 to 7 for each google-service.json you have.

Example command for development configuration:

COPY /Y "$(ProjectDir)GoogleServices\google-services-development.json" "$(ProjectDir)google-services.json"

Example command for production configuration:

COPY /Y "$(ProjectDir)GoogleServices\google-services-production.json" "$(ProjectDir)google-services.json"

Example command for any configuration:

COPY /Y "$(ProjectDir)GoogleServices\google-services-any.json" "$(ProjectDir)google-services.json"

Now you can switch between Build configurations dinamically to execute the json you want.

More information about Pre-build events Here.

这篇关于Xamarin Firebase不同的google-services,json用于不同的构建配置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆