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); } }
internal void SetupSymbolsUpload(string unityProjectPath, string gradleProjectPath) { var options = _getOptions(); var logger = options?.DiagnosticLogger ?? new UnityLogger(new SentryUnityOptions()); if (_scriptingImplementation != ScriptingImplementation.IL2CPP) { logger.LogDebug("Automated symbols upload requires the IL2CPP scripting backend."); return; } var sentryCliOptions = _getSentryCliOptions(); if (sentryCliOptions is null) { logger.LogWarning("Failed to load sentry-cli options - Skipping symbols upload."); return; } if (!sentryCliOptions.IsValid(logger, _isDevelopmentBuild)) { return; } try { var symbolsPath = DebugSymbolUpload.GetSymbolsPath( unityProjectPath, gradleProjectPath, EditorUserBuildSettings.exportAsGoogleAndroidProject); var sentryCliPath = SentryCli.SetupSentryCli(); SentryCli.CreateSentryProperties(gradleProjectPath, sentryCliOptions); DebugSymbolUpload.AppendUploadToGradleFile(sentryCliPath, gradleProjectPath, symbolsPath); } catch (Exception e) { logger.LogError("Failed to add the automatic symbols upload to the gradle project", e); } }
public void CreateSentryProperties_PropertyFileCreatedAndContainsSentryCliOptions() { var propertiesDirectory = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString()); Directory.CreateDirectory(propertiesDirectory); var sentryCliTestOptions = ScriptableObject.CreateInstance <SentryCliOptions>(); sentryCliTestOptions.Auth = Guid.NewGuid().ToString(); sentryCliTestOptions.Organization = Guid.NewGuid().ToString(); sentryCliTestOptions.Project = Guid.NewGuid().ToString(); SentryCli.CreateSentryProperties(propertiesDirectory, sentryCliTestOptions); var properties = File.ReadAllText(Path.Combine(propertiesDirectory, "sentry.properties")); StringAssert.Contains(sentryCliTestOptions.Auth, properties); StringAssert.Contains(sentryCliTestOptions.Organization, properties); StringAssert.Contains(sentryCliTestOptions.Project, properties); Directory.Delete(propertiesDirectory, true); }