daily pastebin goal
4%
SHARE
TWEET

Add Embedded Framework Unity3d

a guest Feb 22nd, 2018 260 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. public static void OnPostprocessBuild(BuildTarget target, string projectPath) {
  2.        
  3.     string pbxProjPath = PBXProject.GetPBXProjectPath(projectPath);
  4.     PBXProject pbxProject = new PBXProject();
  5.     pbxProject.ReadFromFile(pbxProjPath);
  6.    
  7.     string targetName = PBXProject.GetUnityTargetName();
  8.     string targetGuidName = pbxProject.TargetGuidByName(targetName);
  9.     pbxProject.WriteToFile(pbxProjPath);
  10.  
  11.     string basePath = Application.dataPath + "/";
  12.     string frameworkPath = "Plugins/iOS/";
  13.     string []arrFrameworks = {"frameworkA.framework", "frameworkB.framework"};
  14.     foreach(string framework in arrFrameworks) {
  15.         AddEmbeddedFramework(ref pbxProject, targetGuidName, basePath + frameworkPath + framework, frameworkPath + framework);
  16.     }
  17.  
  18.     pbxProject.WriteToFile (pbxProjPath);
  19.     foreach(string framework in arrFrameworks) {
  20.         string contents = File.ReadAllText(pbxProjPath);
  21.         string pattern = "(?<=Embed Frameworks)(?:.*)(\\/\\* " + framework + "\\ \\*\\/)(?=; };)";
  22.         string oldText = "/* " + framework + " */";
  23.         string updatedText = "/* " + framework + " */; settings = {ATTRIBUTES = (CodeSignOnCopy, ); }";
  24.         contents = Regex.Replace(contents, pattern, m => m.Value.Replace(oldText, updatedText));
  25.         File.WriteAllText(pbxProjPath, contents);
  26.     }
  27. }
  28.  
  29. public static void AddEmbeddedFramework(ref PBXProject project, string target, string frameworkPath, string frameworkName) {
  30.     string fileGuid = project.AddFile(frameworkPath, "Frameworks/" + frameworkName, PBXSourceTree.Source);
  31.     string embedPhase = project.AddCopyFilesBuildPhase (target, "Embed Frameworks", "", "10");
  32.     project.AddFileToBuildSection (target, embedPhase, fileGuid);
  33.     PBXProjectExtensions.AddFileToEmbedFrameworks(project, target, fileGuid);
  34.     project.AddBuildProperty(target, "LD_RUNPATH_SEARCH_PATHS", "$(inherited) @executable_path/Frameworks");
  35.     project.AddBuildProperty(target, "FRAMEWORK_SEARCH_PATHS", "$(SRCROOT)/PATH_TO_FRAMEWORK/");
  36. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top