2022-12-16 11:03:03 +08:00
|
|
|
|
using HybridCLR.Editor.Installer;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.IO;
|
|
|
|
|
using System.Linq;
|
2023-09-05 17:28:06 +08:00
|
|
|
|
using System.Reflection;
|
2022-12-16 11:03:03 +08:00
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using UnityEditor;
|
|
|
|
|
using UnityEngine;
|
2023-09-05 17:28:06 +08:00
|
|
|
|
using static UnityEngine.Networking.UnityWebRequest;
|
2022-12-16 11:03:03 +08:00
|
|
|
|
|
|
|
|
|
namespace HybridCLR.Editor.Commands
|
|
|
|
|
{
|
|
|
|
|
public static class StripAOTDllCommand
|
|
|
|
|
{
|
|
|
|
|
[MenuItem("HybridCLR/Generate/AOTDlls", priority = 105)]
|
|
|
|
|
public static void GenerateStripedAOTDlls()
|
|
|
|
|
{
|
2023-09-05 16:47:28 +08:00
|
|
|
|
GenerateStripedAOTDlls(EditorUserBuildSettings.activeBuildTarget);
|
2022-12-16 11:03:03 +08:00
|
|
|
|
}
|
|
|
|
|
|
2023-09-05 17:28:06 +08:00
|
|
|
|
static BuildOptions GetBuildPlayerOptions(BuildTarget buildTarget)
|
|
|
|
|
{
|
2023-12-14 12:00:28 +08:00
|
|
|
|
BuildOptions options = BuildOptions.None;
|
2023-09-05 17:28:06 +08:00
|
|
|
|
bool development = EditorUserBuildSettings.development;
|
|
|
|
|
if (development)
|
|
|
|
|
{
|
|
|
|
|
options |= BuildOptions.Development;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (EditorUserBuildSettings.allowDebugging && development)
|
|
|
|
|
{
|
|
|
|
|
options |= BuildOptions.AllowDebugging;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (EditorUserBuildSettings.connectProfiler && (development || buildTarget == BuildTarget.WSAPlayer))
|
|
|
|
|
{
|
|
|
|
|
options |= BuildOptions.ConnectWithProfiler;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (EditorUserBuildSettings.buildWithDeepProfilingSupport && development)
|
|
|
|
|
{
|
|
|
|
|
options |= BuildOptions.EnableDeepProfilingSupport;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#if UNITY_2021_2_OR_NEWER
|
|
|
|
|
options |= BuildOptions.CleanBuildCache;
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
return options;
|
|
|
|
|
}
|
|
|
|
|
|
2022-12-16 11:03:03 +08:00
|
|
|
|
private static string GetLocationPathName(string buildDir, BuildTarget target)
|
|
|
|
|
{
|
|
|
|
|
switch(target)
|
|
|
|
|
{
|
|
|
|
|
case BuildTarget.StandaloneWindows:
|
2024-04-12 00:35:09 +08:00
|
|
|
|
case BuildTarget.StandaloneWindows64: return $"{buildDir}/{PlayerSettings.productName}.exe";
|
2022-12-16 11:03:03 +08:00
|
|
|
|
case BuildTarget.StandaloneOSX: return buildDir;
|
|
|
|
|
case BuildTarget.iOS: return buildDir;
|
|
|
|
|
case BuildTarget.Android: return buildDir;
|
2024-04-12 00:35:09 +08:00
|
|
|
|
case BuildTarget.StandaloneLinux64: return $"{buildDir}/{PlayerSettings.productName}";
|
2022-12-16 11:03:03 +08:00
|
|
|
|
default: return buildDir;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-09-05 16:47:28 +08:00
|
|
|
|
public static void GenerateStripedAOTDlls(BuildTarget target)
|
2022-12-16 11:03:03 +08:00
|
|
|
|
{
|
|
|
|
|
string outputPath = $"{SettingsUtil.HybridCLRDataDir}/StrippedAOTDllsTempProj/{target}";
|
|
|
|
|
BashUtil.RemoveDir(outputPath);
|
|
|
|
|
|
2023-09-05 17:28:06 +08:00
|
|
|
|
var buildOptions = GetBuildPlayerOptions(target);
|
2023-05-03 17:17:40 +08:00
|
|
|
|
#if UNITY_2021_2_OR_NEWER
|
2023-03-13 12:17:39 +08:00
|
|
|
|
buildOptions |= BuildOptions.CleanBuildCache;
|
|
|
|
|
#endif
|
2022-12-16 11:03:03 +08:00
|
|
|
|
|
|
|
|
|
bool oldExportAndroidProj = EditorUserBuildSettings.exportAsGoogleAndroidProject;
|
2022-12-16 11:23:37 +08:00
|
|
|
|
#if UNITY_EDITOR_OSX
|
|
|
|
|
bool oldCreateSolution = UnityEditor.OSXStandalone.UserBuildSettings.createXcodeProject;
|
|
|
|
|
#elif UNITY_EDITOR_WIN
|
|
|
|
|
bool oldCreateSolution = UnityEditor.WindowsStandalone.UserBuildSettings.createSolution;
|
2024-01-04 11:48:30 +08:00
|
|
|
|
#endif
|
2024-04-08 22:25:48 +08:00
|
|
|
|
#if TUANJIE_2022_3_OR_NEWER
|
2024-01-04 11:48:30 +08:00
|
|
|
|
bool oldOpenHarmonyProj = EditorUserBuildSettings.exportAsOpenHarmonyProject;
|
2022-12-16 11:23:37 +08:00
|
|
|
|
#endif
|
2022-12-16 11:03:03 +08:00
|
|
|
|
bool oldBuildScriptsOnly = EditorUserBuildSettings.buildScriptsOnly;
|
|
|
|
|
EditorUserBuildSettings.buildScriptsOnly = true;
|
|
|
|
|
|
2023-12-12 23:23:01 +08:00
|
|
|
|
string location = GetLocationPathName(outputPath, target);
|
|
|
|
|
string oldBuildLocation = EditorUserBuildSettings.GetBuildLocation(target);
|
|
|
|
|
EditorUserBuildSettings.SetBuildLocation(target, location);
|
|
|
|
|
|
2022-12-16 11:03:03 +08:00
|
|
|
|
switch (target)
|
|
|
|
|
{
|
|
|
|
|
case BuildTarget.StandaloneWindows:
|
|
|
|
|
case BuildTarget.StandaloneWindows64:
|
|
|
|
|
{
|
2022-12-16 11:23:37 +08:00
|
|
|
|
#if UNITY_EDITOR_WIN
|
2022-12-16 11:03:03 +08:00
|
|
|
|
UnityEditor.WindowsStandalone.UserBuildSettings.createSolution = true;
|
2022-12-16 11:23:37 +08:00
|
|
|
|
#endif
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case BuildTarget.StandaloneOSX:
|
|
|
|
|
{
|
|
|
|
|
#if UNITY_EDITOR_OSX
|
|
|
|
|
UnityEditor.OSXStandalone.UserBuildSettings.createXcodeProject = true;
|
|
|
|
|
#endif
|
2022-12-16 11:03:03 +08:00
|
|
|
|
break;
|
|
|
|
|
}
|
2024-04-08 22:25:48 +08:00
|
|
|
|
#if TUANJIE_2022_3_OR_NEWER
|
2024-01-04 11:48:30 +08:00
|
|
|
|
case BuildTarget.HMIAndroid:
|
|
|
|
|
#endif
|
2022-12-16 11:03:03 +08:00
|
|
|
|
case BuildTarget.Android:
|
|
|
|
|
{
|
|
|
|
|
EditorUserBuildSettings.exportAsGoogleAndroidProject = true;
|
|
|
|
|
break;
|
|
|
|
|
}
|
2024-04-08 22:25:48 +08:00
|
|
|
|
#if TUANJIE_2022_3_OR_NEWER
|
2024-01-04 11:48:30 +08:00
|
|
|
|
case BuildTarget.OpenHarmony:
|
|
|
|
|
{
|
|
|
|
|
EditorUserBuildSettings.exportAsOpenHarmonyProject = true;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
#endif
|
2022-12-16 11:03:03 +08:00
|
|
|
|
}
|
|
|
|
|
|
2023-09-05 17:28:06 +08:00
|
|
|
|
Debug.Log($"GenerateStripedAOTDlls build option:{buildOptions}");
|
|
|
|
|
|
2022-12-16 11:03:03 +08:00
|
|
|
|
BuildPlayerOptions buildPlayerOptions = new BuildPlayerOptions()
|
|
|
|
|
{
|
|
|
|
|
scenes = EditorBuildSettings.scenes.Where(s => s.enabled).Select(s => s.path).ToArray(),
|
2023-12-12 23:23:01 +08:00
|
|
|
|
locationPathName = location,
|
2022-12-16 11:03:03 +08:00
|
|
|
|
options = buildOptions,
|
|
|
|
|
target = target,
|
2023-09-05 16:47:28 +08:00
|
|
|
|
targetGroup = BuildPipeline.GetBuildTargetGroup(target),
|
2022-12-16 11:03:03 +08:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
var report = BuildPipeline.BuildPlayer(buildPlayerOptions);
|
|
|
|
|
|
|
|
|
|
EditorUserBuildSettings.buildScriptsOnly = oldBuildScriptsOnly;
|
2023-12-12 23:23:01 +08:00
|
|
|
|
EditorUserBuildSettings.SetBuildLocation(target, oldBuildLocation);
|
|
|
|
|
|
2022-12-16 11:03:03 +08:00
|
|
|
|
switch (target)
|
|
|
|
|
{
|
|
|
|
|
case BuildTarget.StandaloneWindows:
|
|
|
|
|
case BuildTarget.StandaloneWindows64:
|
2022-12-16 11:23:37 +08:00
|
|
|
|
{
|
|
|
|
|
#if UNITY_EDITOR_WIN
|
|
|
|
|
UnityEditor.WindowsStandalone.UserBuildSettings.createSolution = oldCreateSolution;
|
|
|
|
|
#endif
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case BuildTarget.StandaloneOSX:
|
|
|
|
|
{
|
|
|
|
|
#if UNITY_EDITOR_OSX
|
|
|
|
|
UnityEditor.OSXStandalone.UserBuildSettings.createXcodeProject = oldCreateSolution;
|
|
|
|
|
#endif
|
|
|
|
|
break;
|
|
|
|
|
}
|
2024-04-08 22:25:48 +08:00
|
|
|
|
#if TUANJIE_2022_3_OR_NEWER
|
2024-01-04 11:48:30 +08:00
|
|
|
|
case BuildTarget.HMIAndroid:
|
|
|
|
|
#endif
|
2022-12-16 11:03:03 +08:00
|
|
|
|
case BuildTarget.Android:
|
|
|
|
|
{
|
|
|
|
|
EditorUserBuildSettings.exportAsGoogleAndroidProject = oldExportAndroidProj;
|
|
|
|
|
break;
|
|
|
|
|
}
|
2024-04-08 22:25:48 +08:00
|
|
|
|
#if TUANJIE_2022_3_OR_NEWER
|
2024-01-04 11:48:30 +08:00
|
|
|
|
case BuildTarget.OpenHarmony:
|
|
|
|
|
{
|
|
|
|
|
EditorUserBuildSettings.exportAsOpenHarmonyProject = oldOpenHarmonyProj;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
#endif
|
2022-12-16 11:03:03 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (report.summary.result != UnityEditor.Build.Reporting.BuildResult.Succeeded)
|
|
|
|
|
{
|
2023-08-30 11:07:12 +08:00
|
|
|
|
throw new Exception("GenerateStripedAOTDlls failed");
|
2022-12-16 11:03:03 +08:00
|
|
|
|
}
|
2023-09-05 16:47:28 +08:00
|
|
|
|
Debug.Log($"GenerateStripedAOTDlls target:{target} path:{outputPath}");
|
2022-12-16 11:03:03 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|