TobiasBuchholz / Plugin.Firebase

Wrapper around the native Android and iOS Firebase Xamarin SDKs
MIT License
220 stars 49 forks source link

Bundle Resource is not available on MAUI, and what if bundle_id and package_name are different #89

Closed DavidShochet closed 2 years ago

DavidShochet commented 2 years ago

The 4) of Basic Setup section says:

Set [GoogleService-Info.plist|google-services.json] build action behaviour to [Bundle Resource|GoogleServicesJson] by Right clicking/Build Action.

But in MAUI projects, Bundle Resource is just not available in the list. And I found out that even if entered manually in the .proj file, it would not work. What is the right way to deal with it for iOS?

The ".NET MAUI support" section says,

Ensure the ApplicationId in your .csproj file matches the bundle_id and package_name inside of the [GoogleService-Info.plist|google-services.json] files...

But our iOS and Android versions of the app have different bundle_id and package_name, and they cannot be changed. How should I deal with this?

TobiasBuchholz commented 2 years ago

But in MAUI projects, Bundle Resource is just not available in the list. And I found out that even if entered manually in the .proj file, it would not work. What is the right way to deal with it for iOS?

Add the references to the GoogleService-Info.plist and google-services.json to your .csproj file like this:

...
<ItemGroup Condition="'$(TargetFramework)' == 'net6.0-android'">
    <GoogleServicesJson Include="google-services.json" />
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'net6.0-ios'">
    <BundleResource Include="GoogleService-Info.plist" />
</ItemGroup>
...

Make sure the files are located in the root of your project. You can take a look at the .csproj file of the sample project for further details.

But our iOS and Android versions of the app have different bundle_id and package_name, and they cannot be changed. How should I deal with this?

In this case I believe you should remove the ApplicationId tag from your .csproj file and add the bundleId directly into your iOS project's Info.plist file and the android package name into your AndroidManifest.xml file.

Info.plist:

...
<key>CFBundleIdentifier</key>
<string>your.bundle.id</string>
...

AndroidManifest.xml:

...
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="your.package.name">
...