using UnityEditor; using UnityEditor.Build; using UnityEditor.Build.Reporting; using UnityEngine; namespace Unity.WebRTC.Editor { /// /// This type express a return value of "PlayerSettings.GetArchitecture(BuildTargetGroup.iOS)" /// enum iOSArchitecture { ARMv7 = 0, ARM64 = 1, Universal = 2 } /// /// /// class PreprocessBuild : IPreprocessBuildWithReport { /// /// /// int IOrderedCallback.callbackOrder => 1; /// /// /// #if UNITY_2021_1_OR_NEWER public const AndroidSdkVersions RequiredAndroidSdkVersion = AndroidSdkVersions.AndroidApiLevel22; #else public const AndroidSdkVersions RequiredAndroidSdkVersion = AndroidSdkVersions.AndroidApiLevel21; #endif /// /// /// public const AndroidArchitecture RequiredAndroidArchitectures = AndroidArchitecture.ARM64; /// /// /// public const iOSArchitecture RequiredIOSArchitectures = iOSArchitecture.ARM64; /// /// /// /// void IPreprocessBuildWithReport.OnPreprocessBuild(BuildReport report) { switch (report.summary.platform) { case BuildTarget.Android: EnsureAndroidSdkVersion(); EnsureAndroidArchitecture(); EnsureAndroidInternetPermission(); break; case BuildTarget.iOS: EnsureIOSArchitecture(); break; case BuildTarget.StandaloneOSX: EnsureOSXArchitecture(); break; case BuildTarget.StandaloneWindows: throw new BuildFailedException( "Windows 32bit(x86) architecture is not supported by WebRTC package."); } } /// /// /// static void EnsureAndroidSdkVersion() { if ((int)PlayerSettings.Android.minSdkVersion < (int)RequiredAndroidSdkVersion) { Debug.LogWarning( $"WebRTC apps require a minimum SDK version of {RequiredAndroidSdkVersion}. " + $"Currently set to {PlayerSettings.Android.minSdkVersion}"); } } /// /// /// static void EnsureAndroidArchitecture() { if (PlayerSettings.Android.targetArchitectures != AndroidArchitecture.ARM64) { Debug.LogWarning( $"WebRTC apps require a target architecture to be set {RequiredAndroidArchitectures}. " + $"Currently set to {PlayerSettings.Android.targetArchitectures}"); } } static void EnsureAndroidInternetPermission() { if (!PlayerSettings.Android.forceInternetPermission) { Debug.LogWarning( $"WebRTC apps require a internet permission on Android devices." + "Please check the \"Internet Access\" on your Build Settings."); } } /// /// /// static void EnsureIOSArchitecture() { // Architecture value is ignored when using SimulatorSDK if (PlayerSettings.iOS.sdkVersion == iOSSdkVersion.SimulatorSDK) return; var architecture = (iOSArchitecture)PlayerSettings.GetArchitecture(BuildTargetGroup.iOS); if(architecture != iOSArchitecture.ARM64) { Debug.LogWarning( $"WebRTC apps require a target architecture to be set {RequiredIOSArchitectures}. " + $"Currently set to {architecture}"); } } /// /// /// static void EnsureOSXArchitecture() { } } }