#if UNITY_IOS using System.Linq; using System.Text.RegularExpressions; using UnityEditor; using UnityEditor.Callbacks; using UnityEditor.iOS.Xcode; namespace TowerDevil.Editor { internal static class AdMobBuild { [PostProcessBuild(1002)] public static void Configure(BuildTarget target, string path) { if (target != BuildTarget.iOS) return; string file = PBXProject.GetPBXProjectPath(path); var project = new PBXProject(); project.ReadFromFile(file); string framework = project.GetUnityFrameworkTargetGuid(); // Unity exposes add operations for Swift packages but no lookup. Inspect its // canonical serialization so an Append build can reuse the existing references. var objects = Regex.Matches(project.WriteToString(), @"^\t\t(?[0-9A-Fa-f]{24}) /\*[^\r\n]*?\*/ = \{\r?\n(?.*?)^\t\t\};", RegexOptions.Multiline | RegexOptions.Singleline) .Cast().ToDictionary(m => m.Groups["id"].Value, m => m.Groups["body"].Value); string links = objects[project.GetFrameworksBuildPhaseByTarget(framework)]; void Link(string repository, string product, string version) { if (links.Contains("/* " + product + " in Frameworks */")) return; string url = "https://github.com/googleads/" + repository + ".git"; string package = objects.FirstOrDefault(entry => entry.Value.Contains("isa = XCRemoteSwiftPackageReference;") && entry.Value.Contains("repositoryURL = \"" + url + "\";")).Key; package = package ?? project.AddRemotePackageReferenceAtVersion(url, version); project.AddRemotePackageFrameworkToProject(framework, product, package, false); } Link("swift-package-manager-google-mobile-ads", "GoogleMobileAds", "13.9.0"); Link("swift-package-manager-google-user-messaging-platform", "GoogleUserMessagingPlatform", "3.1.0"); project.AddFrameworkToProject(framework, "JavaScriptCore.framework", false); project.WriteToFile(file); } } } #endif