DEV Community

Samuel Schumacher
Samuel Schumacher

Posted on • Edited on • Originally published at samuelschumacher.dev

Xamarin: Using Multiple Firebase Configuration Files in Android and iOS Projects

Need to use different Firebase projects depending on the current build configuration of your Xamarin app? Google has some basic documentation on this use case, but it didn't quite cut it for me. Hopefully this quick rundown of an MSBuild config helps you out!

To get started, you will need to download any Android (google-services.json) or iOS (GoogleService-Info.plist) project config files from your Firebase console.

Android Configuration

First, copy each Firebase project's google-services.json file into the root of your Android Xamarin project. Rename each file to match the environment it corresponds to, e.g. google-services.release.json (you may use whatever file naming pattern you wish).

Example project structure:

MyApp.Android/
-- google-services.debug.json
-- google-services.release.json
-- ...

Next, unload the project and open its configuration file in a text editor. Replace all "google-services" related Include items with the following lines:

<GoogleServicesJson Include="google-services.release.json" LogicalName="google-services.json" Condition=" '$(Configuration)' == 'Release' " />
<GoogleServicesJson Include="google-services.debug.json" LogicalName="google-services.json" Condition=" '$(Configuration)' != 'Release' " />

Make sure to update the filename inside of Include if you are using a different naming convention.

iOS Config

The setup for iOS is very similar.

First, copy each Firebase project's GoogleService-Info.plist file into the root of your iOS Xamarin project. Rename each file to match the environment it corresponds to, e.g. GoogleService-Info.release.plist (you may use whatever file naming pattern you wish).

Example project structure:

App.iOS/
-- GoogleService-Info.debug.plist
-- GoogleService-Info.release.plist
-- ...

Next, unload the project and open its configuration file in a text editor. Replace all "GoogleService-Info" related Include items with the following lines:

<BundleResource Include="GoogleService-Info.release.plist" LogicalName="GoogleService-Info.plist" Condition=" '$(Configuration)' == 'Release' " />
<BundleResource Include="GoogleService-Info.debug.plist" LogicalName="GoogleService-Info.plist" Condition=" '$(Configuration)' != 'Release' " />

How Does it Work?

By setting the LogicalName property on each file, we are effectively telling MSBuild to use the required name of the file that Firebase counts on - even if we have multiple copies in the same directory.

Setting a Condition for each file allows us to selectively import the specific file we need for the current configuration.

Bookmarks:

Top comments (1)

Collapse
 
buddyreno profile image
Buddy Reno

Great write up Samuel!