Skip to content

Copy GA DLL for Windows Build and Play Mode if it exists #1271

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 6 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 49 additions & 0 deletions editor/app/src/AnalyticsPlayModeSetup.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
using System;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file needs to be added to the editor/app/CMakeLists.txt

using System.IO;
using UnityEditor;
using UnityEngine;

namespace Firebase.Editor {

[InitializeOnLoad]
internal static class AnalyticsPlayModeSetup {
private const string DestinationDir = "./";

static AnalyticsPlayModeSetup() {
EditorApplication.playModeStateChanged += OnPlayModeStateChanged;
}

private static void OnPlayModeStateChanged(PlayModeStateChange state) {
if (state == PlayModeStateChange.EnteredPlayMode) {
if (Application.platform == RuntimePlatform.WindowsEditor) {
Type firebaseAnalyticsType = Type.GetType("Firebase.Analytics.FirebaseAnalytics, Firebase.Analytics");
if (firebaseAnalyticsType != null) {
if (File.Exists("./analytics_win.dll")) {
string fullSourcePath = Path.GetFullPath("./analytics_win.dll");
// string destinationDirectory = "./"; // This is DestinationDir
string fullDestinationPath = Path.GetFullPath(Path.Combine(DestinationDir, "analytics_win.dll"));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nothing ever changes DestinationDir afaik, so this will always be ./analytics_win.dll, which will be the same as the fullSourcePath above. I'm not clear what it is trying to do here.


if (fullSourcePath.Equals(fullDestinationPath, StringComparison.OrdinalIgnoreCase)) {
Debug.Log("Firebase Analytics: analytics_win.dll is already in the project root. No copy needed for Play Mode.");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We probably don't want to log if nothing is being done, cause that'll be pretty spammy.

return;
}

try {
Directory.CreateDirectory(DestinationDir); // Should be benign for "./"
string destinationDllPath = Path.Combine(DestinationDir, "analytics_win.dll");
File.Copy("./analytics_win.dll", destinationDllPath, true);
Debug.Log("Firebase Analytics: Copied analytics_win.dll to project root for Play Mode.");
} catch (Exception e) {
Debug.LogError("Firebase Analytics: Error copying analytics_win.dll for Play Mode: " + e.Message);
}
} else {
// Optional: Log if source DLL is not found, as it might be expected if Analytics is not used.
// Debug.LogWarning("Firebase Analytics: Source DLL ./analytics_win.dll not found. Skipping Play Mode setup.");
}
}
}
}
}
}

} // namespace Firebase.Editor
26 changes: 26 additions & 0 deletions editor/app/src/DllLocationPatcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,32 @@ internal static void OnPostProcessDllLocation(
}
}

[PostProcessBuildAttribute(BUILD_ORDER_PATCH_PROJECT)]
internal static void OnPostProcessBuildWindowsAnalytics(
BuildTarget buildTarget, string pathToBuiltProject) {
if (buildTarget == BuildTarget.StandaloneWindows ||
buildTarget == BuildTarget.StandaloneWindows64) {
Type firebaseAnalyticsType = Type.GetType("Firebase.Analytics.FirebaseAnalytics, Firebase.Analytics");
if (firebaseAnalyticsType != null) {
string sourceDllPath = "./analytics_win.dll";
if (System.IO.File.Exists(sourceDllPath)) {
try {
string destinationDirectory = Path.Combine(
Path.GetDirectoryName(pathToBuiltProject),
Path.GetFileNameWithoutExtension(pathToBuiltProject) + "_Data",
"Plugins");
System.IO.Directory.CreateDirectory(destinationDirectory);
string destinationDllPath = Path.Combine(destinationDirectory, "analytics_win.dll");
System.IO.File.Copy(sourceDllPath, destinationDllPath, true);
Debug.Log("Firebase Analytics: Copied analytics_win.dll to build plugins directory.");
} catch (System.Exception e) {
Debug.LogError("Firebase Analytics: Error copying analytics_win.dll for build: " + e.Message);
}
}
}
}
}

internal static void CopyLibrary(
string srcFolder, string dstFolder, string prefix, string extension) {
Debug.Log("Post process to patch App." + extension + "'s location");
Expand Down
Loading