update: 添加 Moloco 的构建管线逻辑
							parent
							
								
									f7d0451cd4
								
							
						
					
					
						commit
						abab35c2a5
					
				|  | @ -0,0 +1,3 @@ | ||||||
|  | fileFormatVersion: 2 | ||||||
|  | guid: 9707190b56774bf98ead95dd04616789 | ||||||
|  | timeCreated: 1718605024 | ||||||
|  | @ -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<string> DynamicLibrariesToEmbed = new List<string> | ||||||
|  |         { | ||||||
|  |             "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<string>(); | ||||||
|  |             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 | ||||||
|  | @ -0,0 +1,3 @@ | ||||||
|  | fileFormatVersion: 2 | ||||||
|  | guid: 936e2d412b5342df98345c07fdf68c66 | ||||||
|  | timeCreated: 1718605026 | ||||||
|  | @ -1,8 +0,0 @@ | ||||||
| fileFormatVersion: 2 |  | ||||||
| guid: e1f46a63334734c8481955bddc4b6d1c |  | ||||||
| folderAsset: yes |  | ||||||
| DefaultImporter: |  | ||||||
|   externalObjects: {} |  | ||||||
|   userData:  |  | ||||||
|   assetBundleName:  |  | ||||||
|   assetBundleVariant:  |  | ||||||
		Loading…
	
		Reference in New Issue