PreProcessBuild_iOS.cs 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. #if UNITY_IOS
  2. #if UNITY_2018_1_OR_NEWER
  3. #define UNITY_SUPPORTS_BUILD_REPORT
  4. #endif
  5. using System.Collections;
  6. using System.Collections.Generic;
  7. using System.IO;
  8. using UnityEngine;
  9. using UnityEditor;
  10. using UnityEngine.Rendering;
  11. using UnityEditor.Build;
  12. #if UNITY_SUPPORTS_BUILD_REPORT
  13. using UnityEditor.Build.Reporting;
  14. #endif
  15. //-----------------------------------------------------------------------------
  16. // Copyright 2012-2022 RenderHeads Ltd. All rights reserved.
  17. //-----------------------------------------------------------------------------
  18. namespace RenderHeads.Media.AVProMovieCapture.Editor
  19. {
  20. public class PreProcessBuild_iOS :
  21. #if UNITY_SUPPORTS_BUILD_REPORT
  22. IPreprocessBuildWithReport
  23. #else
  24. IPreprocessBuild
  25. #endif
  26. {
  27. public int callbackOrder { get { return 0; } }
  28. #if UNITY_SUPPORTS_BUILD_REPORT
  29. public void OnPreprocessBuild(BuildReport report)
  30. {
  31. OnPreprocessBuild(report.summary.platform, report.summary.outputPath);
  32. }
  33. #endif
  34. public void OnPreprocessBuild(BuildTarget target, string path)
  35. {
  36. if (target != BuildTarget.iOS)
  37. return;
  38. FindAndRemoveStaticLib();
  39. }
  40. private void FindAndRemoveStaticLib()
  41. {
  42. // Find all assets whose name begins "libAVProMovieCapture"
  43. string libAVProMovieCapture = "libAVProMovieCapture";
  44. string[] guids = AssetDatabase.FindAssets(libAVProMovieCapture);
  45. if (guids.Length == 0)
  46. return;
  47. // Get the paths to those assets, discarding those who aren't a complete match
  48. List<string> paths = new List<string>();
  49. foreach (string guid in guids)
  50. {
  51. string path = AssetDatabase.GUIDToAssetPath(guid);
  52. string filename = Path.GetFileNameWithoutExtension(path);
  53. if (filename == libAVProMovieCapture)
  54. paths.Add(path);
  55. }
  56. if (paths.Count == 0)
  57. return;
  58. // We need to delete some files
  59. Debug.LogWarning("libAVProMovieCapture.a is no longer required and will be removed from your project.");
  60. Debug.Log("If you selected 'Append' your project will not build in Xcode this time. Please select 'Replace' to refresh the project files.");
  61. foreach (string path in paths)
  62. {
  63. Debug.Log("Deleting: " + path);
  64. System.IO.File.Delete(path);
  65. System.IO.File.Delete(path + ".meta");
  66. }
  67. }
  68. }
  69. }
  70. #endif // UNITY_IOS