From 7f4beb6e3f4565c3f652fd697cb6a88eb456bb92 Mon Sep 17 00:00:00 2001 From: huyufei Date: Thu, 30 May 2024 13:13:51 +0800 Subject: [PATCH] =?UTF-8?q?update=EF=BC=9A=20=E6=96=B0=E5=A2=9E=20Firebase?= =?UTF-8?q?=20=E4=BE=9D=E8=B5=96=E4=BF=AE=E5=A4=8D=E5=B7=A5=E5=85=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: huyufei --- .../IOSPostBuild.Firebase.VersionFix.cs | 121 ++++++++++++++++++ .../IOSPostBuild.Firebase.VersionFix.cs.meta | 3 + 2 files changed, 124 insertions(+) create mode 100644 Editor/GuruBuildSuit/IOS_POST_FIREBASE/IOSPostBuild.Firebase.VersionFix.cs create mode 100644 Editor/GuruBuildSuit/IOS_POST_FIREBASE/IOSPostBuild.Firebase.VersionFix.cs.meta diff --git a/Editor/GuruBuildSuit/IOS_POST_FIREBASE/IOSPostBuild.Firebase.VersionFix.cs b/Editor/GuruBuildSuit/IOS_POST_FIREBASE/IOSPostBuild.Firebase.VersionFix.cs new file mode 100644 index 0000000..a0bdb57 --- /dev/null +++ b/Editor/GuruBuildSuit/IOS_POST_FIREBASE/IOSPostBuild.Firebase.VersionFix.cs @@ -0,0 +1,121 @@ +using System.Collections.Generic; +using System.Linq; +using UnityEngine; + +#if UNITY_IOS + +namespace Guru.Editor +{ + using UnityEditor; + using System; + using System.IO; + using UnityEditor.Callbacks; + + + public class IOSPostBuild_Firebase_VersionFix + { + + + private static string[] fixedLibs = new string[] + { + "Firebase/Core", + "Firebase/Firestore", + "Firebase/Analytics", + "Firebase/Storage", + "Firebase/Auth", + "Firebase/Messaging", + "Firebase/Crashlytics", + "Firebase/DynamicLinks", + "Firebase/RemoteConfig", + }; + + private static string[] additionLibs = new string[] + { + "FirebaseFirestoreInternal", + }; + + private static string fixedVersion = "10.22.0"; + private static string minTargetSdk = "8.0"; + + // + + + + + [PostProcessBuild(45)] // MAX POD Process Order + public static void PostBuildFixPodDeps(BuildTarget target, string projPath) + { + if (target != BuildTarget.iOS) return; + + string podfile = Path.Combine(projPath, "Podfile"); + if (!File.Exists(podfile)) return; + + FixFirebasePodVersion(podfile); + } + + + private static void FixFirebasePodVersion(string podfile) + { + var lines = File.ReadAllLines(podfile).ToList(); + string line = ""; + int idx = 0; + bool isDirty = false; + List needAdded = new List(additionLibs); + for (int i = 0; i < lines.Count; i++) + { + line = lines[i]; + + if (line.Contains("pod '")) + { + idx = i; + } + + foreach (var libName in fixedLibs) + { + if (line.Contains(libName)) + { + lines[i] = FixOneFirebaseLibVersion(line, fixedVersion, minTargetSdk); + isDirty = true; + } + } + + foreach (var libName in additionLibs) + { + if (line.Contains(libName)) + { + needAdded.Remove(libName); + lines[i] = FixOneFirebaseLibVersion(line, fixedVersion, minTargetSdk); + isDirty = true; + } + } + + if (needAdded.Count > 0) + { + // pod 'Firebase/DynamicLinks', '10.20.0' + foreach (var libName in needAdded) + { + idx++; + idx = Mathf.Min(idx, lines.Count - 1); + lines.Insert(idx, $"\tpod '{libName}', '{fixedVersion}'"); + isDirty = true; + } + } + } + if(isDirty) File.WriteAllLines(podfile, lines); + } + + private static string FixOneFirebaseLibVersion(string line, string fixedVersion, string minTargetSdk) + { + line = line.Replace("version =", "version="); + string fixedLine = ""; + + fixedLine = line.Substring(line.IndexOf("version=") + 9) + $"\"{fixedVersion}\" minTargetSdk=\"{minTargetSdk}\""; + + return fixedLine; + } + } +} + + + +#endif \ No newline at end of file diff --git a/Editor/GuruBuildSuit/IOS_POST_FIREBASE/IOSPostBuild.Firebase.VersionFix.cs.meta b/Editor/GuruBuildSuit/IOS_POST_FIREBASE/IOSPostBuild.Firebase.VersionFix.cs.meta new file mode 100644 index 0000000..6445cc4 --- /dev/null +++ b/Editor/GuruBuildSuit/IOS_POST_FIREBASE/IOSPostBuild.Firebase.VersionFix.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 2aab28d86c8346e581c650a86cad060f +timeCreated: 1717039005 \ No newline at end of file