public static SentryXcodeProject Open(string path) { var xcodeProject = new SentryXcodeProject(path); xcodeProject.ReadFromProjectFile(); return(xcodeProject); }
public static void OnPostProcessBuild(BuildTarget target, string pathToProject) { if (target != BuildTarget.iOS) { return; } var options = ScriptableSentryUnityOptions.LoadSentryUnityOptions(BuildPipeline.isBuildingPlayer); var logger = options?.DiagnosticLogger ?? new UnityLogger(new SentryUnityOptions()); try { // Unity doesn't allow an appending builds when switching iOS SDK versions and this will make sure we always copy the correct version of the Sentry.framework var frameworkDirectory = PlayerSettings.iOS.sdkVersion == iOSSdkVersion.DeviceSDK ? "Device" : "Simulator"; var frameworkPath = Path.GetFullPath(Path.Combine("Packages", SentryPackageInfo.GetName(), "Plugins", "iOS", frameworkDirectory, "Sentry.framework")); CopyFramework(frameworkPath, Path.Combine(pathToProject, "Frameworks", "Sentry.framework"), options?.DiagnosticLogger); var nativeBridgePath = Path.GetFullPath(Path.Combine("Packages", SentryPackageInfo.GetName(), "Plugins", "iOS", "SentryNativeBridge.m")); CopyFile(nativeBridgePath, Path.Combine(pathToProject, "Libraries", SentryPackageInfo.GetName(), "SentryNativeBridge.m"), options?.DiagnosticLogger); using var sentryXcodeProject = SentryXcodeProject.Open(pathToProject); sentryXcodeProject.AddSentryFramework(); sentryXcodeProject.AddSentryNativeBridge(); if (options?.IsValid() is not true) { logger.LogWarning("Failed to validate Sentry Options. Native support disabled."); return; } if (!options.IosNativeSupportEnabled) { logger.LogDebug("iOS Native support disabled through the options."); return; } sentryXcodeProject.AddNativeOptions(options); sentryXcodeProject.AddSentryToMain(options); var sentryCliOptions = SentryCliOptions.LoadCliOptions(); if (sentryCliOptions.IsValid(logger)) { SentryCli.CreateSentryProperties(pathToProject, sentryCliOptions); SentryCli.AddExecutableToXcodeProject(pathToProject, logger); sentryXcodeProject.AddBuildPhaseSymbolUpload(logger); } } catch (Exception e) { logger.LogError("Failed to add the Sentry framework to the generated Xcode project", e); } }