diff --git a/Editor/PostProcess.meta b/Editor/PostProcess.meta new file mode 100644 index 0000000..4b40464 --- /dev/null +++ b/Editor/PostProcess.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 9707190b56774bf98ead95dd04616789 +timeCreated: 1718605024 \ No newline at end of file diff --git a/Editor/PostProcess/MolocoPostProcessBuildiOS.cs b/Editor/PostProcess/MolocoPostProcessBuildiOS.cs new file mode 100644 index 0000000..6e918ad --- /dev/null +++ b/Editor/PostProcess/MolocoPostProcessBuildiOS.cs @@ -0,0 +1,91 @@ +#if UNITY_IOS|| UNITY_IPHONE + +namespace Guru.Editor +{ + using System.Collections.Generic; + using System.IO; + using UnityEditor; + using UnityEditor.Callbacks; + using UnityEditor.iOS.Xcode; + using UnityEditor.iOS.Xcode.Extensions; + + public class MolocoPostProcessBuildiOS + { +#if !UNITY_2019_3_OR_NEWER + private const string UnityMainTargetName = "Unity-iPhone"; +#endif + + private static readonly List DynamicLibrariesToEmbed = new List + { + "MolocoSDK.xcframework", + "MolocoCustomAdapter.xcframework" + }; + + private static void EmbedDynamicLibrariesIfNeeded(string buildPath, PBXProject project, string targetGuid) + { + // Check that the Pods directory exists (it might not if a publisher is building with Generate Podfile setting disabled in EDM). + var podsDirectory = Path.Combine(buildPath, "Pods"); + if (!Directory.Exists(podsDirectory)) return; + + var dynamicLibraryPathsPresentInProject = new List(); + foreach (var dynamicLibraryToSearch in DynamicLibrariesToEmbed) + { + // both .framework and .xcframework are directories, not files + var directories = + Directory.GetDirectories(podsDirectory, dynamicLibraryToSearch, SearchOption.AllDirectories); + if (directories.Length <= 0) continue; + + var dynamicLibraryAbsolutePath = directories[0]; + var index = dynamicLibraryAbsolutePath.LastIndexOf("Pods"); + var relativePath = dynamicLibraryAbsolutePath.Substring(index); + dynamicLibraryPathsPresentInProject.Add(relativePath); + } + + if (dynamicLibraryPathsPresentInProject.Count <= 0) return; + +#if UNITY_2019_3_OR_NEWER + foreach (var dynamicLibraryPath in dynamicLibraryPathsPresentInProject) + { + var fileGuid = project.AddFile(dynamicLibraryPath, dynamicLibraryPath); + project.AddFileToEmbedFrameworks(targetGuid, fileGuid); + } +#else + string runpathSearchPaths; +#if UNITY_2018_2_OR_NEWER + runpathSearchPaths = project.GetBuildPropertyForAnyConfig(targetGuid, "LD_RUNPATH_SEARCH_PATHS"); +#else + runpathSearchPaths = "$(inherited)"; +#endif + runpathSearchPaths += string.IsNullOrEmpty(runpathSearchPaths) ? "" : " "; + + // Check if runtime search paths already contains the required search paths for dynamic libraries. + if (runpathSearchPaths.Contains("@executable_path/Frameworks")) + return; + + runpathSearchPaths += "@executable_path/Frameworks"; + project.SetBuildProperty(targetGuid, "LD_RUNPATH_SEARCH_PATHS", runpathSearchPaths); +#endif + } + + [PostProcessBuild(int.MaxValue)] + public static void MolocoPostProcessPbxProject(BuildTarget buildTarget, string buildPath) + { + var projectPath = PBXProject.GetPBXProjectPath(buildPath); + var project = new PBXProject(); + project.ReadFromFile(projectPath); + +#if UNITY_2019_3_OR_NEWER + var unityMainTargetGuid = project.GetUnityMainTargetGuid(); + var unityFrameworkTargetGuid = project.GetUnityFrameworkTargetGuid(); +#else + var unityMainTargetGuid = project.TargetGuidByName(UnityMainTargetName); + var unityFrameworkTargetGuid = project.TargetGuidByName(UnityMainTargetName); +#endif + EmbedDynamicLibrariesIfNeeded(buildPath, project, unityMainTargetGuid); + project.WriteToFile(projectPath); + } + } + +} + +#endif \ No newline at end of file diff --git a/Editor/PostProcess/MolocoPostProcessBuildiOS.cs.meta b/Editor/PostProcess/MolocoPostProcessBuildiOS.cs.meta new file mode 100644 index 0000000..0e0c20a --- /dev/null +++ b/Editor/PostProcess/MolocoPostProcessBuildiOS.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 936e2d412b5342df98345c07fdf68c66 +timeCreated: 1718605026 \ No newline at end of file diff --git a/Moloco.meta b/Moloco.meta deleted file mode 100644 index 9671811..0000000 --- a/Moloco.meta +++ /dev/null @@ -1,8 +0,0 @@ -fileFormatVersion: 2 -guid: e1f46a63334734c8481955bddc4b6d1c -folderAsset: yes -DefaultImporter: - externalObjects: {} - userData: - assetBundleName: - assetBundleVariant: