/// <summary> /// Displays an error dialog if there is an issue that would prevent a build from succeeding. /// </summary> /// <returns>True if all prerequisites are met, or false if one failed.</returns> public static bool CheckBuildPrerequisites() { if (!Directory.Exists(AndroidSdkManager.AndroidSdkRoot)) { DisplayBuildError( "Failed to locate the Android SDK. Check Preferences -> External Tools to set the path."); return(false); } try { var ignored = JavaUtilities.JavaBinaryPath; } catch (JavaUtilities.ToolNotFoundException) { DisplayBuildError( "Failed to locate the Java JDK. Check Preferences -> External Tools to set the path."); return(false); } if (!PlayInstantBuildConfiguration.IsInstantBuildType()) { Debug.LogError("Build halted since selected build type is \"Installed\""); var message = string.Format( "The currently selected Android build type is \"Installed\".\n\n" + "Click \"{0}\" to open the \"{1}\" window where the build type can be changed to \"Instant\".", WindowUtils.OkButtonText, BuildSettingsWindow.WindowTitle); if (DisplayBuildErrorDialog(message)) { BuildSettingsWindow.ShowWindow(); } return(false); } var failedPolicies = new List <string>(PlayInstantSettingPolicy.GetRequiredPolicies() .Where(policy => !policy.IsCorrectState()) .Select(policy => policy.Name)); if (failedPolicies.Count > 0) { Debug.LogErrorFormat("Build halted due to incompatible settings: {0}", string.Join(", ", failedPolicies.ToArray())); var message = string.Format( "{0}\n\nClick \"{1}\" to open the settings window and make required changes.", string.Join("\n\n", failedPolicies.ToArray()), WindowUtils.OkButtonText); if (DisplayBuildErrorDialog(message)) { PlayerSettingsWindow.ShowWindow(); } return(false); } return(true); }
private static bool Build(BuildPlayerOptions buildPlayerOptions) { if (!PlayInstantBuildConfiguration.IsInstantBuildType()) { Debug.LogError("Build halted since selected build type is \"Installed\""); var message = string.Format( "The currently selected Android build type is \"Installed\".\n\n" + "Click \"OK\" to open the \"{0}\" window where the build type can be changed to \"Instant\".", BuildSettingsWindow.WindowTitle); if (DisplayBuildErrorDialog(message)) { BuildSettingsWindow.ShowWindow(); } return(false); } var failedPolicies = new List <string>(PlayInstantSettingPolicy.GetRequiredPolicies() .Where(policy => !policy.IsCorrectState()) .Select(policy => policy.Name)); if (failedPolicies.Count > 0) { Debug.LogErrorFormat("Build halted due to incompatible settings: {0}", string.Join(", ", failedPolicies.ToArray())); var message = string.Format( "{0}\n\nClick \"OK\" to open the settings window and make required changes.", string.Join("\n\n", failedPolicies.ToArray())); if (DisplayBuildErrorDialog(message)) { PlayerSettingsWindow.ShowWindow(); } return(false); } var buildReport = BuildPipeline.BuildPlayer(buildPlayerOptions); #if UNITY_2018_1_OR_NEWER switch (buildReport.summary.result) { case BuildResult.Cancelled: Debug.Log("Build cancelled"); return(false); case BuildResult.Succeeded: // BuildPlayer can fail and still return BuildResult.Succeeded so detect by checking totalErrors. if (buildReport.summary.totalErrors > 0) { // No need to display a message since Unity will already have done this. return(false); } // Actual success. return(true); case BuildResult.Failed: LogError(string.Format("Build failed with {0} error(s)", buildReport.summary.totalErrors)); return(false); default: LogError("Build failed with unknown error"); return(false); } #else if (string.IsNullOrEmpty(buildReport)) { return(true); } // Check for intended build cancellation. if (buildReport == "Building Player was cancelled") { Debug.Log(buildReport); } else { LogError(buildReport); } return(false); #endif }
private void OnGUI() { // Edge case that takes place when the plugin code gets re-compiled while this window is open. if (_windowInstance == null) { _windowInstance = this; } var descriptionTextStyle = new GUIStyle(GUI.skin.label) { fontStyle = FontStyle.Italic, wordWrap = true }; EditorGUILayout.Space(); EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField("Android Build Type", EditorStyles.boldLabel, GUILayout.Width(FieldWidth)); var index = EditorGUILayout.Popup(_isInstant ? 1 : 0, PlatformOptions); _isInstant = index == 1; EditorGUILayout.EndHorizontal(); EditorGUILayout.Space(); if (_isInstant) { _instantUrl = GetLabelAndTextField("Instant Apps URL (Optional)", _instantUrl); var packageName = PlayerSettings.GetApplicationIdentifier(BuildTargetGroup.Android) ?? "package-name"; EditorGUILayout.LabelField( "Instant apps are launched from web search, advertisements, etc via a URL. Specify the URL here " + "and configure Digital Asset Links. Or, leave the URL blank and one will automatically be " + "provided at:", descriptionTextStyle); EditorGUILayout.SelectableLabel(string.Format( "https://{0}/{1}", InstantAppsHostName, packageName), descriptionTextStyle); EditorGUILayout.Space(); EditorGUILayout.Space(); EditorGUILayout.LabelField("Scenes in Build", EditorStyles.boldLabel); EditorGUILayout.Space(); EditorGUILayout.LabelField( "The scenes in the build are selected via Unity's \"Build Settings\" window. " + "This can be overridden by specifying a comma separated scene list below.", descriptionTextStyle); EditorGUILayout.Space(); EditorGUILayout.BeginHorizontal(); var defaultScenes = string.IsNullOrEmpty(_scenesInBuild) ? string.Join(", ", PlayInstantBuilder.GetEditorBuildEnabledScenes()) : "(overridden)"; EditorGUILayout.LabelField( string.Format("\"Build Settings\" Scenes: {0}", defaultScenes), EditorStyles.wordWrappedLabel); if (GUILayout.Button("Update", GUILayout.Width(100))) { GetWindow(Type.GetType("UnityEditor.BuildPlayerWindow,UnityEditor"), true); } EditorGUILayout.EndHorizontal(); EditorGUILayout.Space(); _scenesInBuild = GetLabelAndTextField("Override Scenes (Optional)", _scenesInBuild); _assetBundleManifestPath = GetLabelAndTextField("AssetBundle Manifest (Optional)", _assetBundleManifestPath); EditorGUILayout.LabelField( "If you use AssetBundles, provide the path to your AssetBundle Manifest file to ensure that " + "required types are not stripped during the build process.", descriptionTextStyle); } else { EditorGUILayout.LabelField( "The \"Installed\" build type is used when creating a traditional installed APK. " + "Select \"Instant\" to build a Google Play Instant APK.", descriptionTextStyle); } EditorGUILayout.Space(); EditorGUILayout.Space(); // Disable the Save button unless one of the fields has changed. GUI.enabled = IsAnyFieldChanged(); if (GUILayout.Button("Save")) { if (_isInstant) { SelectPlatformInstant(); } else { SelectPlatformInstalled(); } } GUI.enabled = true; }
private void OnDestroy() { _windowInstance = null; }
/// <summary> /// Displays this window, creating it if necessary. /// </summary> public static void ShowWindow() { _windowInstance = (BuildSettingsWindow)GetWindow(typeof(BuildSettingsWindow), true, WindowTitle); _windowInstance.minSize = new Vector2(WindowMinWidth, WindowMinHeight); }
private static void OpenEditorSettings() { BuildSettingsWindow.ShowWindow(); }
/// <summary> /// Displays this window, creating it if necessary. /// </summary> public static void ShowWindow() { _windowInstance = GetWindow(typeof(BuildSettingsWindow), true, WindowTitle) as BuildSettingsWindow; }