Skip to content

Commit a08a6c1

Browse files
feat: Copy analytics_win.dll for Windows Build and Play Mode
This change addresses an issue where `analytics_win.dll` was not being included in Windows builds or available during Play Mode when the Firebase Analytics module was present. The following modifications were made: - Modified `editor/app/src/DllLocationPatcher.cs`: - Added logic to `OnPostProcessBuild` to copy `analytics_win.dll` from the project root to the build's plugin directory (`<project_name>_Data/Plugins/`) when building for StandaloneWindows or StandaloneWindows64, but only if the Firebase Analytics module is detected and the DLL exists. - Created `editor/app/src/AnalyticsPlayModeSetup.cs`: - This new editor script subscribes to `EditorApplication.playModeStateChanged`. - When entering Play Mode on a Windows editor, it checks for the Firebase Analytics module and the existence of `analytics_win.dll` in the project root. - If both conditions are met, it copies `analytics_win.dll` to `Assets/Plugins/` to make it available during Play Mode. These changes ensure that `analytics_win.dll` is correctly placed for both Windows builds and Play Mode sessions, facilitating proper Firebase Analytics functionality on the Windows platform.
1 parent 8bc7cf9 commit a08a6c1

File tree

2 files changed

+65
-0
lines changed

2 files changed

+65
-0
lines changed
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
using System;
2+
using System.IO;
3+
using UnityEditor;
4+
using UnityEngine;
5+
6+
namespace Firebase.Editor {
7+
8+
[InitializeOnLoad]
9+
internal static class AnalyticsPlayModeSetup {
10+
private const string SourceDllPath = "./analytics_win.dll";
11+
private const string DestinationDir = "Assets/Plugins/";
12+
private const string DestinationDllName = "analytics_win.dll";
13+
14+
static AnalyticsPlayModeSetup() {
15+
EditorApplication.playModeStateChanged += OnPlayModeStateChanged;
16+
}
17+
18+
private static void OnPlayModeStateChanged(PlayModeStateChange state) {
19+
if (state == PlayModeStateChange.EnteredPlayMode) {
20+
if (Application.platform == RuntimePlatform.WindowsEditor) {
21+
Type firebaseAnalyticsType = Type.GetType("Firebase.Analytics.FirebaseAnalytics, Firebase.Analytics");
22+
if (firebaseAnalyticsType != null) {
23+
if (File.Exists(SourceDllPath)) {
24+
try {
25+
Directory.CreateDirectory(DestinationDir);
26+
string destinationDllPath = Path.Combine(DestinationDir, DestinationDllName);
27+
File.Copy(SourceDllPath, destinationDllPath, true);
28+
Debug.Log("Firebase Analytics: Copied " + DestinationDllName + " to " + DestinationDir + " for Play Mode.");
29+
AssetDatabase.Refresh();
30+
} catch (Exception e) {
31+
Debug.LogError("Firebase Analytics: Error copying " + DestinationDllName + " for Play Mode: " + e.Message);
32+
}
33+
} else {
34+
// Optional: Log if source DLL is not found, as it might be expected if Analytics is not used.
35+
// Debug.LogWarning("Firebase Analytics: Source DLL " + SourceDllPath + " not found. Skipping Play Mode setup.");
36+
}
37+
}
38+
}
39+
}
40+
}
41+
}
42+
43+
} // namespace Firebase.Editor

editor/app/src/DllLocationPatcher.cs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,28 @@ internal static void OnPostProcessDllLocation(
9191
}
9292
}
9393

94+
[PostProcessBuildAttribute(BUILD_ORDER_PATCH_PROJECT)]
95+
internal static void OnPostProcessBuildWindowsAnalytics(
96+
BuildTarget buildTarget, string pathToBuiltProject) {
97+
if (buildTarget == BuildTarget.StandaloneWindows ||
98+
buildTarget == BuildTarget.StandaloneWindows64) {
99+
Type firebaseAnalyticsType = Type.GetType("Firebase.Analytics.FirebaseAnalytics, Firebase.Analytics");
100+
if (firebaseAnalyticsType != null) {
101+
string sourceDllPath = "./analytics_win.dll";
102+
if (System.IO.File.Exists(sourceDllPath)) {
103+
string destinationDirectory = Path.Combine(
104+
Path.GetDirectoryName(pathToBuiltProject),
105+
Path.GetFileNameWithoutExtension(pathToBuiltProject) + "_Data",
106+
"Plugins");
107+
System.IO.Directory.CreateDirectory(destinationDirectory);
108+
string destinationDllPath = Path.Combine(destinationDirectory, "analytics_win.dll");
109+
System.IO.File.Copy(sourceDllPath, destinationDllPath, true);
110+
Debug.Log("Firebase Analytics: Copied analytics_win.dll to build plugins directory.");
111+
}
112+
}
113+
}
114+
}
115+
94116
internal static void CopyLibrary(
95117
string srcFolder, string dstFolder, string prefix, string extension) {
96118
Debug.Log("Post process to patch App." + extension + "'s location");

0 commit comments

Comments
 (0)