IronSourceBuildPostprocessor.cs 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. using UnityEngine;
  2. using UnityEditor;
  3. using UnityEditor.Callbacks;
  4. using UnityEditor.iOS.Xcode;
  5. using System;
  6. using System.IO;
  7. using System.Linq;
  8. using System.Text.RegularExpressions;
  9. using System.Reflection;
  10. namespace IronSource.Editor
  11. {
  12. public class IronSourceBuildPostprocessor
  13. {
  14. [PostProcessBuild]
  15. public static void OnPostprocessBuild (BuildTarget buildTarget, string buildPath)
  16. {
  17. if (buildTarget == BuildTarget.iOS) {
  18. string projectPath = buildPath + "/Unity-iPhone.xcodeproj/project.pbxproj";
  19. string dirpath = Application.dataPath + "/IronSource/Editor/";
  20. string currentNamespace = MethodBase.GetCurrentMethod().DeclaringType.Namespace;
  21. updateProject (buildTarget, projectPath);
  22. if (Directory.Exists (dirpath)) {
  23. //Match the classes that has "Settings" in their name, and don't start with "I"
  24. var files = Directory.GetFiles (dirpath, "*.cs", SearchOption.TopDirectoryOnly).Where (file => Regex.IsMatch (Path.GetFileName (file), "^(?!I).+Settings.*$"));
  25. //Go over all the adapter settings classes, and call their updateProject method
  26. foreach (string file in files) {
  27. string classname = Path.GetFileNameWithoutExtension (file);
  28. if (!String.IsNullOrEmpty (classname)) {
  29. IAdapterSettings adapter = (IAdapterSettings)Activator.CreateInstance (Type.GetType (currentNamespace + "." + classname));
  30. adapter.updateProject (buildTarget, projectPath);
  31. }
  32. }
  33. }
  34. }
  35. Debug.Log ("IronSource build postprocessor finished");
  36. }
  37. private static void updateProject (BuildTarget buildTarget, string projectPath)
  38. {
  39. Debug.Log ("IronSource - Update project for IronSource");
  40. PBXProject project = new PBXProject ();
  41. project.ReadFromString (File.ReadAllText (projectPath));
  42. string targetId = project.TargetGuidByName (PBXProject.GetUnityTargetName ());
  43. // Required System Frameworks
  44. project.AddFrameworkToProject (targetId, "Foundation.framework", false);
  45. project.AddFrameworkToProject (targetId, "AVFoundation.framework", false);
  46. project.AddFrameworkToProject (targetId, "Security.framework", false);
  47. project.AddFrameworkToProject (targetId, "WebKit.framework", false);
  48. project.AddFrameworkToProject (targetId, "StoreKit.framework", false);
  49. project.AddFrameworkToProject (targetId, "AdSupport.framework", false);
  50. project.AddFrameworkToProject (targetId, "CoreMedia.framework", false);
  51. project.AddFrameworkToProject (targetId, "CoreVideo.framework", false);
  52. project.AddFrameworkToProject (targetId, "CoreLocation.framework", false);
  53. project.AddFrameworkToProject (targetId, "CoreTelephony.framework", false);
  54. project.AddFrameworkToProject (targetId, "CoreGraphics.framework", false);
  55. project.AddFrameworkToProject (targetId, "QuartzCore.framework", false);
  56. project.AddFrameworkToProject (targetId, "SystemConfiguration.framework", false);
  57. project.AddFrameworkToProject (targetId, "CFNetwork.framework", false);
  58. project.AddFrameworkToProject (targetId, "MobileCoreServices.framework", false);
  59. project.AddFrameworkToProject (targetId, "AudioToolbox.framework", false);
  60. project.AddFileToBuild (targetId, project.AddFile ("usr/lib/libz.tbd", "Frameworks/libz.tbd", PBXSourceTree.Sdk));
  61. // Custom Link Flag
  62. project.AddBuildProperty (targetId, "OTHER_LDFLAGS", "-ObjC");
  63. File.WriteAllText (projectPath, project.WriteToString ());
  64. }
  65. }
  66. }