/// <summary>
        /// Displays an error or warning dialog if there is an issue that would prevent a build from succeeding.
        /// This method performs the checks from <see cref="CheckBuildPrerequisites"/>, but also performs checks
        /// relevant to builds intended for publishing on Play Console.
        /// </summary>
        /// <returns>True if all prerequisites are met, or false if one failed.</returns>
        public static bool CheckBuildAndPublishPrerequisites()
        {
            if (!CheckBuildPrerequisites())
            {
                return(false);
            }

            // This is a warning that can be skipped, so it should be checked last.
            // BuildTargetGroup.Unknown is used when checking the project's "Default Icon".
            if (!HasIconForTargetGroup(BuildTargetGroup.Unknown) && !HasIconForTargetGroup(BuildTargetGroup.Android))
            {
                if (WindowUtils.IsHeadlessMode())
                {
                    Debug.LogError("Build failure: the project is missing an application icon.");
                    return(false);
                }

                var message = "Failed to locate a Default Icon or an Android Icon for this project. Prior to " +
                              "publishing it's strongly recommended that the project have a custom icon, or " +
                              "devices running Android Oreo or later will display the Unity application icon.\n\n" +
                              "Click \"Continue\" to continue with the build, or \"Cancel\" to abort the build.";
                if (!EditorUtility.DisplayDialog("Build Warning", message, "Continue", WindowUtils.CancelButtonText))
                {
                    return(false);
                }
            }

            return(true);
        }
예제 #2
0
 private static void DisplayProgress(string info, float progress)
 {
     Debug.LogFormat("{0}...", info);
     if (!WindowUtils.IsHeadlessMode())
     {
         EditorUtility.DisplayProgressBar("Building App Bundle", info, progress);
     }
 }
예제 #3
0
        private static void DisplayBuildError(string errorType, string errorMessage)
        {
            if (!WindowUtils.IsHeadlessMode())
            {
                EditorUtility.ClearProgressBar();
            }

            PlayInstantBuilder.DisplayBuildError(string.Format("{0} failed: {1}", errorType, errorMessage));
        }
        /// <summary>
        /// Displays the specified message indicating that a build error occurred.
        /// </summary>
        public static void DisplayBuildError(string message)
        {
            Debug.LogErrorFormat("Build error: {0}", message);

            if (!WindowUtils.IsHeadlessMode())
            {
                EditorUtility.DisplayDialog(BuildErrorTitle, message, WindowUtils.OkButtonText);
            }
        }
        /// <summary>
        /// Displays the specified message indicating that a build error occurred. Displays an "OK" button that can
        /// be used to indicate that the user wants to perform a followup action, e.g. fixing a build setting.
        /// </summary>
        /// <returns>True if the user clicks "OK", otherwise false.</returns>
        public static bool DisplayBuildErrorDialog(string message)
        {
            if (WindowUtils.IsHeadlessMode())
            {
                // During a headless build it isn't possible to prompt to fix the issue, so always return false.
                Debug.LogErrorFormat("Build error in headless mode: {0}", message);
                return(false);
            }

            return(EditorUtility.DisplayDialog(
                       BuildErrorTitle, message, WindowUtils.OkButtonText, WindowUtils.CancelButtonText));
        }
        private void OnGUI()
        {
            GUI.enabled = _versionCheckRequest == null && _pluginDownloadRequest == null;

            EditorGUILayout.Space();
            EditorGUILayout.LabelField(string.Format(
                                           "This dialog checks for the latest released version of this plugin. " +
                                           "Click the \"{0}\" button to open the GitHub page with a list of all plugin versions.",
                                           PluginReleasesButtonText), EditorStyles.wordWrappedLabel);
            EditorGUILayout.Space();
            WindowUtils.CreateRightAlignedButton(PluginReleasesButtonText,
                                                 () => { Application.OpenURL("https://github.com/google/play-instant-unity-plugin/releases"); });

            EditorGUILayout.Space();
            EditorGUILayout.Space();

            EditorGUILayout.LabelField(string.Format("Current version: {0}", GooglePlayInstantUtils.PluginVersion));
            EditorGUILayout.LabelField(string.Format("Latest version:  {0}",
                                                     GetNormalizedVersion(_latestReleaseVersion) ?? "unknown"));
            EditorGUILayout.LabelField(string.Format("Latest package:  {0}",
                                                     GetLatestReleasePluginFileName() ?? "unknown"), EditorStyles.wordWrappedLabel);
            EditorGUILayout.Space();
            WindowUtils.CreateRightAlignedButton(CheckReleasesButtonText, StartVersionCheck);

            EditorGUILayout.Space();
            EditorGUILayout.Space();

            GUI.enabled &= _latestReleaseVersion != null;

            EditorGUILayout.LabelField("Download options", EditorStyles.boldLabel);
            EditorGUILayout.Space();
            EditorGUILayout.LabelField(string.Format(
                                           "Either click \"{0}\" to download and save the latest plugin to disk, " +
                                           " or click \"{1}\" to download and install the latest plugin.",
                                           DownloadAndSaveButtonText, DownloadAndInstallButtonText), EditorStyles.wordWrappedLabel);
            EditorGUILayout.Space();
            WindowUtils.CreateRightAlignedButton(DownloadAndSaveButtonText, StartPluginDownloadAndSave);
            EditorGUILayout.Space();
            WindowUtils.CreateRightAlignedButton(DownloadAndInstallButtonText, StartPluginDownloadAndInstall);

            GUI.enabled = true;
        }
예제 #7
0
        private void OnGUI()
        {
            GUI.enabled = _downloadRequest == null;

            EditorGUILayout.Space();
            EditorGUILayout.LabelField(
                "Bundletool is a command line java program used for creating Android App Bundles (.aab files). " +
                "Bundletool is also used to generate a set of APKs from an .aab file.", EditorStyles.wordWrappedLabel);
            EditorGUILayout.Space();
            WindowUtils.CreateRightAlignedButton("Learn more",
                                                 () => { Application.OpenURL("https://developer.android.com/studio/command-line/bundletool"); });

            EditorGUILayout.Space();
            EditorGUILayout.Space();
            EditorGUILayout.Space();

            EditorGUILayout.LabelField(string.Format("Click \"Download\" to download bundletool version {0}.",
                                                     Bundletool.BundletoolVersion), EditorStyles.wordWrappedLabel);
            EditorGUILayout.Space();
            WindowUtils.CreateRightAlignedButton("Download", StartDownload);

            GUI.enabled = true;
        }
예제 #8
0
        /// <summary>
        /// Build an app bundle at the specified path, overwriting an existing file if one exists.
        /// </summary>
        /// <returns>True if the build succeeded, false if it failed or was cancelled.</returns>
        public static bool Build(string aabFilePath)
        {
            var binaryFormatFilePath = Path.GetTempFileName();

            Debug.LogFormat("Building Package: {0}", binaryFormatFilePath);

            // Do not use BuildAndSign since this signature won't be used.
            if (!PlayInstantBuilder.Build(
                    PlayInstantBuilder.CreateBuildPlayerOptions(binaryFormatFilePath, BuildOptions.None)))
            {
                // Do not log here. The method we called was responsible for logging.
                return(false);
            }

            // TODO: currently all processing is synchronous; consider moving to a separate thread
            try
            {
                DisplayProgress("Running aapt2", 0.2f);
                var workingDirectory = new DirectoryInfo(Path.Combine(Path.GetTempPath(), "play-instant-unity"));
                if (workingDirectory.Exists)
                {
                    workingDirectory.Delete(true);
                }

                workingDirectory.Create();
                var sourceDirectoryInfo      = workingDirectory.CreateSubdirectory("source");
                var destinationDirectoryInfo = workingDirectory.CreateSubdirectory("destination");

                var protoFormatFileName = Path.GetRandomFileName();
                var protoFormatFilePath = Path.Combine(sourceDirectoryInfo.FullName, protoFormatFileName);
                var aaptResult          = AndroidAssetPackagingTool.Convert(binaryFormatFilePath, protoFormatFilePath);
                if (aaptResult != null)
                {
                    DisplayBuildError("aapt2", aaptResult);
                    return(false);
                }

                DisplayProgress("Creating base module", 0.4f);
                var unzipFileResult = ZipUtils.UnzipFile(protoFormatFileName, sourceDirectoryInfo.FullName);
                if (unzipFileResult != null)
                {
                    DisplayBuildError("Unzip", unzipFileResult);
                    return(false);
                }

                File.Delete(protoFormatFilePath);

                ArrangeFiles(sourceDirectoryInfo, destinationDirectoryInfo);
                var baseModuleZip = Path.Combine(workingDirectory.FullName, BaseModuleZipFileName);
                var zipFileResult = ZipUtils.CreateZipFile(baseModuleZip, destinationDirectoryInfo.FullName, ".");
                if (zipFileResult != null)
                {
                    DisplayBuildError("Zip creation", zipFileResult);
                    return(false);
                }

                // If the .aab file exists, EditorUtility.SaveFilePanel() has already prompted for whether to overwrite.
                // Therefore, prevent Bundletool from throwing an IllegalArgumentException that "File already exists."
                File.Delete(aabFilePath);

                DisplayProgress("Running bundletool", 0.6f);
                var buildBundleResult = Bundletool.BuildBundle(baseModuleZip, aabFilePath);
                if (buildBundleResult != null)
                {
                    DisplayBuildError("bundletool", buildBundleResult);
                    return(false);
                }

                DisplayProgress("Signing bundle", 0.8f);
                var signingResult = ApkSigner.SignZip(aabFilePath);
                if (signingResult != null)
                {
                    DisplayBuildError("Signing", signingResult);
                    return(false);
                }
            }
            finally
            {
                if (!WindowUtils.IsHeadlessMode())
                {
                    EditorUtility.ClearProgressBar();
                }
            }

            return(true);
        }