123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103 |
- #if UNITY_IPHONE || UNITY_STANDALONE_OSX
- using System.IO;
- using UnityEditor;
- using UnityEditor.Callbacks;
- #if UNITY_IPHONE
- using UnityEditor.iOS.Xcode;
- using UnityEditor.iOS.Xcode.Extensions;
- #endif
- public class BL_BuildPostProcess
- {
- [PostProcessBuild]
- public static void OnPostprocessBuild(BuildTarget buildTarget, string path)
- {
- if (buildTarget == BuildTarget.iOS)
- {
- #if UNITY_IPHONE
- LinkLibraries(path);
- UpdatePermission(path + "/Info.plist");
- #endif
- }
- }
- #if UNITY_IPHONE
- static string GetTargetGuid(PBXProject proj)
- {
- #if UNITY_2019_3_OR_NEWER
- return proj.GetUnityFrameworkTargetGuid();
- #else
- return proj.TargetGuidByName("Unity-iPhone");
- #endif
- }
- // The followings are the addtional frameworks to add to the project
- static string[] ProjectFrameworks = new string[] {
- "Accelerate.framework",
- "CoreTelephony.framework",
- "CoreText.framework",
- "CoreML.framework",
- "Metal.framework",
- "VideoToolbox.framework",
- "libiPhone-lib.a",
- "libresolv.tbd",
- };
- public static void LinkLibraries(string path)
- {
- string projPath = path + "/Unity-iPhone.xcodeproj/project.pbxproj";
- PBXProject proj = new PBXProject();
- proj.ReadFromFile(projPath);
- string target = GetTargetGuid(proj);
- // embedded frameworks
- #if UNITY_2019_3_OR_NEWER
- target = proj.GetUnityMainTargetGuid();
- #endif
- const string defaultLocationInProj = "AgoraEngine/Plugins/iOS";
- const string AgoraRtcKitFrameworkName = "AgoraRtcKit.framework";
- const string AgorafdkaacFrameworkName = "Agorafdkaac.framework";
- const string AgoraSoundTouchFrameworkName = "AgoraSoundTouch.framework";
- const string AgoraCoreFrameworkName = "AgoraCore.framework";
- const string AgoraAIDenoiseExtensionFrameworkName = "AgoraAIDenoiseExtension.framework";
- string AgoraRtcKitFrameworkPath = Path.Combine(defaultLocationInProj, AgoraRtcKitFrameworkName);
- string AgorafdkaacFrameworkPath = Path.Combine(defaultLocationInProj, AgorafdkaacFrameworkName);
- string AgoraSoundTouchFrameworkPath = Path.Combine(defaultLocationInProj, AgoraSoundTouchFrameworkName);
- string AgoraCoreFrameworkPath = Path.Combine(defaultLocationInProj, AgoraCoreFrameworkName);
- string AgoraAIDenoiseExtensionFrameworkPath = Path.Combine(defaultLocationInProj, AgoraAIDenoiseExtensionFrameworkName);
- string fileGuid = proj.AddFile(AgoraRtcKitFrameworkPath, "Frameworks/" + AgoraRtcKitFrameworkPath, PBXSourceTree.Sdk);
- PBXProjectExtensions.AddFileToEmbedFrameworks(proj, target, fileGuid);
- fileGuid = proj.AddFile(AgorafdkaacFrameworkPath, "Frameworks/" + AgorafdkaacFrameworkPath, PBXSourceTree.Sdk);
- PBXProjectExtensions.AddFileToEmbedFrameworks(proj, target, fileGuid);
- fileGuid = proj.AddFile(AgoraSoundTouchFrameworkPath, "Frameworks/" + AgoraSoundTouchFrameworkPath, PBXSourceTree.Sdk);
- PBXProjectExtensions.AddFileToEmbedFrameworks(proj, target, fileGuid);
- fileGuid = proj.AddFile(AgoraCoreFrameworkPath, "Frameworks/" + AgoraCoreFrameworkPath, PBXSourceTree.Sdk);
- PBXProjectExtensions.AddFileToEmbedFrameworks(proj, target, fileGuid);
- fileGuid = proj.AddFile(AgoraAIDenoiseExtensionFrameworkPath, "Frameworks/" + AgoraAIDenoiseExtensionFrameworkPath, PBXSourceTree.Sdk);
- PBXProjectExtensions.AddFileToEmbedFrameworks(proj, target, fileGuid);
- proj.SetBuildProperty(target, "LD_RUNPATH_SEARCH_PATHS", "$(inherited) @executable_path/Frameworks");
- // done, write to the project file
- File.WriteAllText(projPath, proj.WriteToString());
- }
- #endif
- /// <summary>
- /// Update the permission
- /// </summary>
- /// <param name="pListPath">path to the Info.plist file</param>
- static void UpdatePermission(string pListPath)
- {
- #if UNITY_IPHONE
- PlistDocument plist = new PlistDocument();
- plist.ReadFromString(File.ReadAllText(pListPath));
- PlistElementDict rootDic = plist.root;
- var micPermission = "NSMicrophoneUsageDescription";
- rootDic.SetString(micPermission, "Voice call need to user mic");
- File.WriteAllText(pListPath, plist.WriteToString());
- #endif
- }
- }
- #endif
|