问题描述
所以我有一个要求,我的项目应在Android/iOS上使用不同的GoogleServices文件,同时使用不同的配置,例如在使用调试配置时,它应使用文件的调试版本,而在发行版中,它应使用使用发行版.
So I have a requirement where my project should use different GoogleServices files for Android/iOS while using different configurations like for eg while I am using the debug configuration it should use the debug version of the file and in the release, it should use the release version.
类似于 Xamarin firebase不同的google-services,用于不同构建配置的json
当我按照接受的答案回答时,我会得到一个编译时错误,提示
When I follow the accepted the answer I get a compile-time error saying
我尝试了清理构建和清理bin/obj的操作.
I tried clean build and cleaning bin/obj nothing changed.
因此,我尝试了此处提到的另一种解决方案,结果是GoogleServices文件(所有文件)都从项目中排除了,如果我构建并运行该文件,则不会发生任何事情.我不确定这是否行得通.
So I tried the other solution mentioned here and what happens is the GoogleServices files(all of them) are excluded from the project and nothing happens if I build and run. I am unsure if this is even working or not.
我在csproj中添加了以下几行,分别用于发布和调试
I have added the following lines in my csproj for release and debug respectively
<ItemGroup Condition="'$(Configuration)'=='Debug'">
<GoogleServicesJson Include="Dev\google-services.json">
<Link>google-services.json</Link>
</GoogleServicesJson>
</ItemGroup>
<ItemGroup Condition="'$(Configuration)'=='Release'">
<GoogleServicesJson Include="Prod\google-services.json">
<Link>google-services.json</Link>
</GoogleServicesJson>
</ItemGroup>
dev和prod是本机android项目中的根文件夹
Where dev and prod are root folders in my native android project
欢迎提出任何建议.
推荐答案
您必须编辑* .csproj文件.
You have to edit *.csproj file.
使用使用多个Info.plist (LogicalName标记)和条件标记,您可以随心所欲地播放任何其他文件.
Using a solution to use multiple Info.plist (LogicalName tag) and Condition tag you can play with any other files all you want.
对于Android,我将两个* .json文件添加到Resources文件夹中,并将此代码段添加到我的* .csproj文件中:
For Android I added two *.json files to Resources folder and added this snippet to my *.csproj file:
<ItemGroup Condition=" '$(Configuration)' != 'Release' ">
<GoogleServicesJson Include="Resources\dev-google-services.json">
<LogicalName>Resources\google-services.json</LogicalName>
</GoogleServicesJson>
</ItemGroup>
<ItemGroup Condition=" '$(Configuration)' == 'Release' ">
<GoogleServicesJson Include="Resources\release-google-services.json">
<LogicalName>Resources\google-services.json</LogicalName>
</GoogleServicesJson>
</ItemGroup>
在此示例中,我将release-google-services.json用于发布"构建配置,并将dev-google-services.json用于任何其他配置.
In this example I use release-google-services.json for the "Release" build configuration, and dev-google-services.json for any other configurations.
与iOS相同.我在根文件夹中添加了两个* .plist文件,并将此代码段添加到了我的* .csproj文件中:
Same for iOS. I added two *.plist files to root folder and added this snippet to my *.csproj file:
<ItemGroup Condition=" '$(Configuration)' != 'AppStore' ">
<BundleResource Include="Dev-GoogleService-Info.plist">
<LogicalName>GoogleService-Info.plist</LogicalName>
</BundleResource>
</ItemGroup>
<ItemGroup Condition=" '$(Configuration)' == 'AppStore' ">
<BundleResource Include="Release-GoogleService-Info.plist">
<LogicalName>GoogleService-Info.plist</LogicalName>
</BundleResource>
</ItemGroup>
这种方法对我有用.我想您将这些文件放在何处以及如何命名都没有关系.只需使用所需的LogicalName.
This approach works for me. I guess it doesn't matter where you put these files and how you name them. Just use the LogicalName that you need.
此外,您可以将其与其他变量组合以组成更复杂的条件.例如,为了在Release配置中使用不同的* .json文件构建两个* .apk,您可以:
Also, you can combine it with other variables to compose more complicated conditions. For example, in order to build two *.apk in Release configuration with different *.json files you can:
<ItemGroup Condition=" '$(Configuration)|$(DynamicConstants)' != 'Release|' ">
<GoogleServicesJson Include="Resources\dev-google-services.json">
<LogicalName>Resources\google-services.json</LogicalName>
</GoogleServicesJson>
</ItemGroup>
<ItemGroup Condition=" '$(Configuration)|$(DynamicConstants)' == 'Release|' ">
<GoogleServicesJson Include="Resources\release-google-services.json">
<LogicalName>Resources\google-services.json</LogicalName>
</GoogleServicesJson>
</ItemGroup>
像这样构建您的项目:
msbuild MobileApp.sln /p:Configuration=Release /p:DynamicConstants=DEBUG
使用DEBUG参数时,将使用dev-google-services.json构建Release apk.
When you use DEBUG parameter you build Release apk with dev-google-services.json.
省略DEBUG参数时,将使用release-google-services.json构建Release apk.
When you omit DEBUG parameter you build Release apk with release-google-services.json.
这篇关于基于Xamarin中的构建配置,适用于iOS/Android项目的不同的google-services.json/GoogleService-Info.plist`的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!