2026-06-23 11:27:51 +08:00
|
|
|
using UnityEditor;
|
|
|
|
|
using UnityEditor.Callbacks;
|
2026-07-06 16:49:18 +08:00
|
|
|
using UnityEditor.iOS.Xcode;
|
2026-06-23 11:27:51 +08:00
|
|
|
using System.IO;
|
|
|
|
|
using System.Text.RegularExpressions;
|
2026-07-06 15:42:29 +08:00
|
|
|
using UnityEngine;
|
2026-06-23 11:27:51 +08:00
|
|
|
|
|
|
|
|
public class iOSFixDuplicateShellScript
|
|
|
|
|
{
|
2026-07-06 15:42:29 +08:00
|
|
|
[PostProcessBuild(999)]
|
2026-06-23 11:27:51 +08:00
|
|
|
public static void OnPostProcessBuild(BuildTarget target, string pathToBuiltProject)
|
|
|
|
|
{
|
|
|
|
|
if (target != BuildTarget.iOS) return;
|
|
|
|
|
|
2026-07-06 15:42:29 +08:00
|
|
|
FixDuplicateShellScript(pathToBuiltProject);
|
|
|
|
|
FixPodfile(pathToBuiltProject);
|
2026-07-06 16:49:18 +08:00
|
|
|
AddNetworkExtensionFramework(pathToBuiltProject);
|
2026-07-06 15:42:29 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static void FixDuplicateShellScript(string pathToBuiltProject)
|
|
|
|
|
{
|
2026-06-23 11:27:51 +08:00
|
|
|
string projPath = Path.Combine(pathToBuiltProject, "Unity-iPhone.xcodeproj/project.pbxproj");
|
2026-07-06 15:42:29 +08:00
|
|
|
if (!File.Exists(projPath))
|
|
|
|
|
{
|
2026-07-06 16:49:18 +08:00
|
|
|
Debug.LogWarning("[PostProcess] pbxproj not found: " + projPath);
|
2026-07-06 15:42:29 +08:00
|
|
|
return;
|
|
|
|
|
}
|
2026-06-23 11:27:51 +08:00
|
|
|
|
|
|
|
|
string content = File.ReadAllText(projPath);
|
|
|
|
|
|
2026-07-06 15:42:29 +08:00
|
|
|
string pattern = @"(\t+([A-F0-9]+) /\* ShellScript \*/,)\r?\n\t+\2 /\* ShellScript \*,/";
|
|
|
|
|
string newContent = Regex.Replace(content, pattern, "$1");
|
|
|
|
|
|
|
|
|
|
if (newContent != content)
|
|
|
|
|
{
|
|
|
|
|
File.WriteAllText(projPath, newContent);
|
2026-07-06 16:49:18 +08:00
|
|
|
Debug.Log("[PostProcess] Removed duplicate ShellScript from GameAssembly target");
|
2026-07-06 15:42:29 +08:00
|
|
|
}
|
2026-07-06 16:49:18 +08:00
|
|
|
|
|
|
|
|
// 修复光子矩阵 app 大小写
|
|
|
|
|
newContent = newContent.Replace("photonmatrix.app", "PhotonMatrix.app");
|
|
|
|
|
|
|
|
|
|
File.WriteAllText(projPath, newContent);
|
2026-07-06 15:42:29 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static void FixPodfile(string pathToBuiltProject)
|
|
|
|
|
{
|
|
|
|
|
string podfilePath = Path.Combine(pathToBuiltProject, "Podfile");
|
|
|
|
|
if (!File.Exists(podfilePath))
|
|
|
|
|
{
|
2026-07-06 16:49:18 +08:00
|
|
|
Debug.LogWarning("[PostProcess] Podfile not found");
|
2026-07-06 15:42:29 +08:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
string content = File.ReadAllText(podfilePath);
|
|
|
|
|
bool modified = false;
|
|
|
|
|
|
|
|
|
|
if (content.Contains("Firebase/Analytics"))
|
|
|
|
|
{
|
|
|
|
|
content = Regex.Replace(content, @"\s*pod\s+'Firebase/Analytics'[^\n]*\n?", "\n");
|
|
|
|
|
modified = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (content.Contains("12.4.0"))
|
|
|
|
|
{
|
|
|
|
|
content = content.Replace("12.4.0", "12.14.0");
|
|
|
|
|
modified = true;
|
|
|
|
|
}
|
2026-06-23 11:27:51 +08:00
|
|
|
|
2026-07-06 15:42:29 +08:00
|
|
|
if (modified)
|
|
|
|
|
{
|
|
|
|
|
File.WriteAllText(podfilePath, content);
|
2026-07-06 16:49:18 +08:00
|
|
|
Debug.Log("[PostProcess] Cleaned up Podfile");
|
2026-07-06 15:42:29 +08:00
|
|
|
}
|
2026-07-06 16:49:18 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static void AddNetworkExtensionFramework(string pathToBuiltProject)
|
|
|
|
|
{
|
|
|
|
|
string projPath = PBXProject.GetPBXProjectPath(pathToBuiltProject);
|
|
|
|
|
PBXProject proj = new PBXProject();
|
|
|
|
|
proj.ReadFromString(File.ReadAllText(projPath));
|
|
|
|
|
|
|
|
|
|
string unityFrameworkGuid = proj.GetUnityFrameworkTargetGuid();
|
|
|
|
|
bool added = proj.AddFrameworkToProject(unityFrameworkGuid, "NetworkExtension.framework", false);
|
|
|
|
|
|
|
|
|
|
if (added)
|
2026-07-06 15:42:29 +08:00
|
|
|
{
|
2026-07-06 16:49:18 +08:00
|
|
|
File.WriteAllText(projPath, proj.WriteToString());
|
|
|
|
|
Debug.Log("[PostProcess] Added NetworkExtension.framework");
|
2026-07-06 15:42:29 +08:00
|
|
|
}
|
2026-06-23 11:27:51 +08:00
|
|
|
}
|
|
|
|
|
}
|