DEV Community

Samuel Schumacher
Samuel Schumacher

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

3 1

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:

Hostinger image

Get n8n VPS hosting 3x cheaper than a cloud solution

Get fast, easy, secure n8n VPS hosting from $4.99/mo at Hostinger. Automate any workflow using a pre-installed n8n application and no-code customization.

Start now

Top comments (1)

Collapse
 
buddyreno profile image
Buddy Reno

Great write up Samuel!

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

👋 Kindness is contagious

Engage with a wealth of insights in this thoughtful article, valued within the supportive DEV Community. Coders of every background are welcome to join in and add to our collective wisdom.

A sincere "thank you" often brightens someone’s day. Share your gratitude in the comments below!

On DEV, the act of sharing knowledge eases our journey and fortifies our community ties. Found value in this? A quick thank you to the author can make a significant impact.

Okay