BuildProcessor.cs 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. using UnityEditor;
  2. using UnityEditor.Build;
  3. using UnityEditor.Build.Reporting;
  4. using UnityEngine;
  5. namespace Unity.WebRTC.Editor
  6. {
  7. /// <summary>
  8. /// This type express a return value of "PlayerSettings.GetArchitecture(BuildTargetGroup.iOS)"
  9. /// </summary>
  10. enum iOSArchitecture
  11. {
  12. ARMv7 = 0,
  13. ARM64 = 1,
  14. Universal = 2
  15. }
  16. /// <summary>
  17. ///
  18. /// </summary>
  19. class PreprocessBuild : IPreprocessBuildWithReport
  20. {
  21. /// <summary>
  22. ///
  23. /// </summary>
  24. int IOrderedCallback.callbackOrder => 1;
  25. /// <summary>
  26. ///
  27. /// </summary>
  28. #if UNITY_2021_1_OR_NEWER
  29. public const AndroidSdkVersions RequiredAndroidSdkVersion = AndroidSdkVersions.AndroidApiLevel22;
  30. #else
  31. public const AndroidSdkVersions RequiredAndroidSdkVersion = AndroidSdkVersions.AndroidApiLevel21;
  32. #endif
  33. /// <summary>
  34. ///
  35. /// </summary>
  36. public const AndroidArchitecture RequiredAndroidArchitectures = AndroidArchitecture.ARM64;
  37. /// <summary>
  38. ///
  39. /// </summary>
  40. public const iOSArchitecture RequiredIOSArchitectures = iOSArchitecture.ARM64;
  41. /// <summary>
  42. ///
  43. /// </summary>
  44. /// <param name="report"></param>
  45. void IPreprocessBuildWithReport.OnPreprocessBuild(BuildReport report)
  46. {
  47. switch (report.summary.platform)
  48. {
  49. case BuildTarget.Android:
  50. EnsureAndroidSdkVersion();
  51. EnsureAndroidArchitecture();
  52. EnsureAndroidInternetPermission();
  53. break;
  54. case BuildTarget.iOS:
  55. EnsureIOSArchitecture();
  56. break;
  57. case BuildTarget.StandaloneOSX:
  58. EnsureOSXArchitecture();
  59. break;
  60. case BuildTarget.StandaloneWindows:
  61. throw new BuildFailedException(
  62. "Windows 32bit(x86) architecture is not supported by WebRTC package.");
  63. }
  64. }
  65. /// <summary>
  66. ///
  67. /// </summary>
  68. static void EnsureAndroidSdkVersion()
  69. {
  70. if ((int)PlayerSettings.Android.minSdkVersion < (int)RequiredAndroidSdkVersion)
  71. {
  72. Debug.LogWarning(
  73. $"WebRTC apps require a minimum SDK version of {RequiredAndroidSdkVersion}. " +
  74. $"Currently set to {PlayerSettings.Android.minSdkVersion}");
  75. }
  76. }
  77. /// <summary>
  78. ///
  79. /// </summary>
  80. static void EnsureAndroidArchitecture()
  81. {
  82. if (PlayerSettings.Android.targetArchitectures != AndroidArchitecture.ARM64)
  83. {
  84. Debug.LogWarning(
  85. $"WebRTC apps require a target architecture to be set {RequiredAndroidArchitectures}. " +
  86. $"Currently set to {PlayerSettings.Android.targetArchitectures}");
  87. }
  88. }
  89. static void EnsureAndroidInternetPermission()
  90. {
  91. if (!PlayerSettings.Android.forceInternetPermission)
  92. {
  93. Debug.LogWarning(
  94. $"WebRTC apps require a internet permission on Android devices." +
  95. "Please check the \"Internet Access\" on your Build Settings.");
  96. }
  97. }
  98. /// <summary>
  99. ///
  100. /// </summary>
  101. static void EnsureIOSArchitecture()
  102. {
  103. // Architecture value is ignored when using SimulatorSDK
  104. if (PlayerSettings.iOS.sdkVersion == iOSSdkVersion.SimulatorSDK)
  105. return;
  106. var architecture = (iOSArchitecture)PlayerSettings.GetArchitecture(BuildTargetGroup.iOS);
  107. if(architecture != iOSArchitecture.ARM64)
  108. {
  109. Debug.LogWarning(
  110. $"WebRTC apps require a target architecture to be set {RequiredIOSArchitectures}. " +
  111. $"Currently set to {architecture}");
  112. }
  113. }
  114. /// <summary>
  115. ///
  116. /// </summary>
  117. static void EnsureOSXArchitecture()
  118. {
  119. }
  120. }
  121. }