using System; using System.IO; using System.Linq; using UnityEditor; using UnityEditor.Build; using UnityEditor.Build.Reporting; using UnityEditor.Compilation; using UnityEditor.SceneManagement; using UnityEngine; public static class AppRuntimesPackageValidation { public static void Run() { var package = UnityEditor.PackageManager.PackageInfo.FindForAssembly(typeof(AppRuntimes).Assembly); Require(package != null && package.name == "come.app.runtimes" && package.displayName == "AppRuntimes", "Package identity"); if (Environment.GetCommandLineArgs().Contains("-appRuntimesPackageOnly")) { var dependencies = Newtonsoft.Json.Linq.JObject.Parse(File.ReadAllText("Packages/manifest.json"))["dependencies"]; Require(dependencies.Count() == 1 && dependencies["come.app.runtimes"] != null, "Clean project installs only AppRuntimes"); } Require(!CompilationPipeline.GetAssemblies().Any(a => a.name.Contains("DOTween")), "No DOTween assembly"); Require(typeof(IAPWrapper).Assembly == typeof(AppRuntimes).Assembly, "IAP wrapper is compiled into AppRuntimes"); foreach (string relative in new[] { "ThirdParty/FacebookSDK/Plugins/Android/Facebook.Unity.Android.dll", "ThirdParty/FacebookSDK/Plugins/Android/libs/facebook-android-wrapper-18.1.0.aar", "ThirdParty/UniWebView/Plugins/Android/UniWebView.aar", "ThirdParty/ExternalDependencyManager/Editor/1.2.187/Google.JarResolver.dll", "ThirdParty/ExternalDependencyManager/Editor/1.2.187/Google.IOSResolver.dll", "Runtime/IAP/IAPAndroidImpl.cs", "ThirdParty/IAPiOS/IAP/Editor/iOS/FBSDKUnityStoreKit.storekit" }) Require(File.Exists(Path.Combine(package.resolvedPath, relative)), "Platform SDK retained: " + relative); Require(!File.Exists(Path.Combine(package.resolvedPath, "Runtime/Resources/AppSettings.asset")), "Templates stay outside runtime Resources"); var loading = Resources.Load("Loading"); Require(loading != null && loading.GetComponentsInChildren(true).All(c => c != null), "Loading prefab and GUID references"); AppRuntimesSettingsValidation.VerifyStartup(); foreach (string module in new[] { "FBAEMKit", "FBSDKCoreKit_Basics", "FBSDKCoreKit", "FBSDKLoginKit", "FBSDKShareKit", "FBSDKGamingServicesKit" }) { var importer = AssetImporter.GetAtPath(package.assetPath + "/ThirdParty/FacebookSDK/Plugins/iOS/XCFrameworks/" + module + ".xcframework") as PluginImporter; Require(importer != null && importer.GetCompatibleWithPlatform(BuildTarget.iOS), "iOS framework importer: " + module); } foreach (string source in new[] { "IAPUnityInterface.mm", "IAPSK1.mm", "Swift/IAPSK2.swift" }) { var importer = AssetImporter.GetAtPath(package.assetPath + "/ThirdParty/IAPiOS/IAP/Editor/iOS/" + source) as PluginImporter; Require(importer != null && importer.GetCompatibleWithPlatform(BuildTarget.iOS), "IAP iOS importer: " + source); } foreach (string file in new[] { "meta.mp4", "meta-logo.png" }) { Require(File.Exists(AppRuntimesStreamingAssets.GetPath(file)), "StreamingAssets editor path: " + file); Require(!File.Exists(Path.Combine(Application.streamingAssetsPath, file)), "No host copy of package StreamingAssets: " + file); } bool rejectedTraversal = false; try { AppRuntimesStreamingAssets.GetPath("../package.json"); } catch (ArgumentException) { rejectedTraversal = true; } Require(rejectedTraversal, "StreamingAssets path stays relative"); var scene = EditorSceneManager.NewScene(NewSceneSetup.EmptyScene, NewSceneMode.Single); new GameObject("AppRuntimes validation").AddComponent(); new GameObject("IAP validation").AddComponent(); const string scenePath = "Assets/AppRuntimesValidation.unity"; EditorSceneManager.SaveScene(scene, scenePath); // GUPS discovers scene references through EditorBuildSettings, including explicit BuildPlayer scenes. EditorBuildSettings.scenes = new[] { new EditorBuildSettingsScene(scenePath, true) }; PlayerSettings.SetApplicationIdentifier(NamedBuildTarget.iOS, "come.app.runtimes.validation"); PlayerSettings.SetScriptingBackend(NamedBuildTarget.iOS, ScriptingImplementation.IL2CPP); PlayerSettings.SetManagedStrippingLevel(NamedBuildTarget.iOS, ManagedStrippingLevel.High); AppRuntimesGupsValidation.BeforeBuild(); bool obfuscationSkipped = false; Application.LogCallback checkObfuscation = (message, stack, type) => { if (message.Contains("Obfuscation is deactivated")) obfuscationSkipped = true; }; BuildReport report; Application.logMessageReceived += checkObfuscation; try { report = BuildPipeline.BuildPlayer(new BuildPlayerOptions { scenes = new[] { scenePath }, target = BuildTarget.iOS, locationPathName = "Build/iOS", options = BuildOptions.None }); } finally { Application.logMessageReceived -= checkObfuscation; } Require(report != null && report.summary.result == BuildResult.Succeeded, "iOS build export"); Require(report.summary.totalErrors == 0, "iOS build has no reported errors"); if (Environment.GetCommandLineArgs().Contains("-appRuntimesPackageOnly")) Require(!obfuscationSkipped, "GUPS obfuscation was not skipped"); AppRuntimesGupsValidation.AfterBuild(); AppRuntimesXcodeLayoutValidation.Verify("Build/iOS"); var project = new UnityEditor.iOS.Xcode.PBXProject(); project.ReadFromFile("Build/iOS/Unity-iPhone.xcodeproj/project.pbxproj"); var bridge = project.GetRealPathsOfAllFiles(UnityEditor.iOS.Xcode.PBXSourceTree.Source) .FirstOrDefault(p => Path.GetFileName(p) == "FacebookDynamicCredentials.m"); Require(bridge != null, "Package native bridge exported"); var bridgeGuid = project.FindFileGuidByRealPath(bridge, UnityEditor.iOS.Xcode.PBXSourceTree.Source); Require(project.GetCompileFlagsForFile(project.GetUnityFrameworkTargetGuid(), bridgeGuid).Contains("-fobjc-arc"), "Package bridge ARC flag"); Require(Directory.GetFiles("Build/iOS/FacebookSDKResources", "PrivacyInfo.xcprivacy", SearchOption.AllDirectories).Length == 5, "Facebook privacy manifests exported"); string projectText = File.ReadAllText("Build/iOS/Unity-iPhone.xcodeproj/project.pbxproj"); foreach (string file in new[] { "IAPUnityInterface.mm", "IAPSK1.mm", "IAPSK2.swift" }) { string exportedPath = project.GetRealPathsOfAllFiles(UnityEditor.iOS.Xcode.PBXSourceTree.Source) .SingleOrDefault(p => Path.GetFileName(p) == file); Require(exportedPath != null && File.Exists(Path.Combine("Build/iOS", exportedPath)) && projectText.Contains(file + " in Sources"), "IAP native source exported and registered for compilation: " + file); } foreach (string file in new[] { "meta.mp4", "meta-logo.png" }) { string exportedPath = "Build/iOS/Data/Raw/" + file; Require(File.Exists(exportedPath) && File.ReadAllBytes(exportedPath).SequenceEqual(File.ReadAllBytes(AppRuntimesStreamingAssets.GetPath(file))), "StreamingAssets exported unchanged: " + file); Require(!File.Exists(Path.Combine(Application.streamingAssetsPath, file)), "Build leaves host Assets unchanged: " + file); } Require(!Directory.GetFiles("Build/iOS/Data/Raw", "*.meta", SearchOption.AllDirectories).Any(), "StreamingAssets metadata excluded from export"); Debug.Log("APP_RUNTIMES_IOS_VALIDATION_PASS"); } private static void Require(bool condition, string check) { if (!condition) throw new Exception("AppRuntimes validation failed: " + check); Debug.Log("APP_RUNTIMES_CHECK_PASS " + check); } }