firebase / firebase/quickstart-unity

Able to generate google-services.xml properly if Application Id is changed right before building.

Open
#768 1 comment 1 reaction 0 assignees View on GitHub
api: core type: feature request
Dominant language
C#
Stars
923
Forks
456
PR merge metrics
No merged PRs in 30d

Description

Based on https://github.com/googlesamples/unity-jar-resolver/issues/365

The user request to be able to generate `google-services.xml` properly if they try to change application Id right before building.
Ex.
```
using UnityEditor;

public class Build
{
[MenuItem("Tools/Build/Debug")]
public static void BuildDebug()
{
PlayerSettings.productName = "debug";
PlayerSettings.SetApplicationIdentifier(BuildTargetGroup.Android, "com.firebaseExample.debug");
BuildPipeline.BuildPlayer(new[] { "Assets/Scenes/SampleScene.unity" }, "debug.apk", EditorUserBuildSettings.activeBuildTarget, BuildOptions.None);
}

[MenuItem("Tools/Build/Release")]
public static void BuildRelease()
{
PlayerSettings.productName = "release";
PlayerSettings.SetApplicationIdentifier(BuildTargetGroup.Android, "com.firebaseExample2.release");
BuildPipeline.BuildPlayer(new[] { "Assets/Scenes/SampleScene.unity" }, "release.apk", EditorUserBuildSettings.activeBuildTarget, BuildOptions.None);
}
}
```

Currently `GenerateXmlFromGoogleServicesJson.cs` (in Firebase.Editor.dll) relies on `PlayServicesResolver.BundleIdChanged` event to change `google-services.xml` when application id change. However, the event only triggered in the next update from the main thread.
https://github.com/googlesamples/unity-jar-resolver/blob/825901fa297065d651709fdc34cc5433410c8869/source/AndroidResolver/src/PlayServicesResolver.cs#L1370

@master-lincoln came up with a workaround to utilize reflection to force trigger this event
```
Type type = Type.GetType("Firebase.Editor.GenerateXmlFromGoogleServicesJson, Firebase.Editor");
var method = type.GetMethod("OnBundleIdChanged", BindingFlags.Public | BindingFlags.NonPublic| BindingFlags.Static);
method.Invoke(null, new[] {
(object)null,
new PlayServicesResolver.BundleIdChangedEventArgs
{
BundleId = newAppId,
PreviousBundleId = oldAppId
}
});
```

However, there should be a better way to support such case.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.