Skip to content

Commit 67766e7

Browse files
committed
feat(xcode): 支持自动执行 pod install
Podfile 处理完毕后自动运行 pod install,默认开启。 新增 podInstall 配置项,设为 false 可跳过(如 CI 单独执行场景)。
1 parent 10776a0 commit 67766e7

3 files changed

Lines changed: 52 additions & 0 deletions

File tree

Editor/PostProcessBuildHelper.PodFile.cs

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,50 @@ private static void AddPodsForTarget(string path, string targetName, Hashtable p
186186
File.WriteAllLines(podfilePath, lines.ToArray());
187187
LogHelper.Log($"[Pods] 已为 {targetName} 添加 {podLines.Count} 个 pod 依赖");
188188
}
189+
190+
private static void RunPodInstall(string path)
191+
{
192+
var podfilePath = path + "/Podfile";
193+
if (!File.Exists(podfilePath))
194+
{
195+
LogHelper.Log("[PodInstall] Podfile 不存在,跳过 pod install");
196+
return;
197+
}
198+
199+
LogHelper.Log("[PodInstall] 开始执行 pod install...");
200+
201+
var process = new System.Diagnostics.Process();
202+
process.StartInfo.FileName = "pod";
203+
process.StartInfo.Arguments = "install";
204+
process.StartInfo.WorkingDirectory = path;
205+
process.StartInfo.UseShellExecute = false;
206+
process.StartInfo.RedirectStandardOutput = true;
207+
process.StartInfo.RedirectStandardError = true;
208+
process.StartInfo.CreateNoWindow = true;
209+
210+
process.Start();
211+
string output = process.StandardOutput.ReadToEnd();
212+
string error = process.StandardError.ReadToEnd();
213+
process.WaitForExit();
214+
215+
if (!string.IsNullOrEmpty(output))
216+
{
217+
LogHelper.Log($"[PodInstall] {output}");
218+
}
219+
220+
if (process.ExitCode != 0)
221+
{
222+
LogHelper.Error($"[PodInstall] pod install 失败 (退出码: {process.ExitCode}): {error}");
223+
return;
224+
}
225+
226+
if (!string.IsNullOrEmpty(error))
227+
{
228+
LogHelper.Warning($"[PodInstall] {error}");
229+
}
230+
231+
LogHelper.Log("[PodInstall] pod install 完成");
232+
}
189233
}
190234
}
191235
#endif

Editor/PostProcessBuildHelper.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,13 @@ public static void OnPostProcessBuild(BuildTarget target, string path)
147147
AddPodsForTarget(path, "UnityFramework", frameworkPods);
148148
}
149149
}
150+
151+
// Podfile 处理完毕后执行 pod install(默认开启,配置 podInstall: false 可跳过)
152+
bool podInstall = !finalConfig.ContainsKey("podInstall") || finalConfig.Get<bool>("podInstall");
153+
if (podInstall)
154+
{
155+
RunPodInstall(path);
156+
}
150157
}
151158
catch (Exception e)
152159
{

Editor/XCodeConfigDemo.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@
9090
"https://mirrors.tuna.tsinghua.edu.cn/git/CocoaPods/Specs.git"
9191
],
9292
"podfile": "",
93+
"podInstall": true,
9394
"capabilities": {
9495
"inAppPurchase": true,
9596
"gameCenter": false,

0 commit comments

Comments
 (0)