Exemple #1
0
        /// <summary>
        /// Checks the latest version of Android SDK Build-Tools that is installed, prompting to upgrade if necessary.
        /// Returns true if the latest version of Android SDK Build-Tools supports the "aapt2 convert" command,
        /// and false otherwise.
        /// </summary>
        public static bool CheckConvert()
        {
            var newestBuildToolsVersion = AndroidBuildTools.GetNewestBuildToolsVersion();

            if (newestBuildToolsVersion == null)
            {
                PlayInstantBuilder.DisplayBuildError(string.Format("Failed to locate {0}", BuildToolsDisplayName));
                return(false);
            }

            if (AndroidBuildTools.IsBuildToolsVersionAtLeast(newestBuildToolsVersion, BuildToolsMinimumVersion))
            {
                return(true);
            }

            var message = string.Format(
                "App Bundle creation requires {0} version {1} or later.\n\nClick \"OK\" to install {0} version {2}.",
                BuildToolsDisplayName, BuildToolsMinimumVersion, BuildToolsLatestVersion);

            if (PlayInstantBuilder.DisplayBuildErrorDialog(message))
            {
                AndroidSdkPackageInstaller.InstallPackage(BuildToolsPackageName, BuildToolsDisplayName);
            }

            return(false);
        }
Exemple #2
0
        private static void DisplayBuildError(string errorType, string errorMessage)
        {
            if (!WindowUtils.IsHeadlessMode())
            {
                EditorUtility.ClearProgressBar();
            }

            PlayInstantBuilder.DisplayBuildError(string.Format("{0} failed: {1}", errorType, errorMessage));
        }
        /// <summary>
        /// Builds an APK and stores it in a user specified ZIP file.
        /// </summary>
        public static void Build()
        {
            if (!PlayInstantBuilder.CheckBuildAndPublishPrerequisites())
            {
                return;
            }

            var zipFilePath = EditorUtility.SaveFilePanel("Create APK in ZIP File", null, null, "zip");

            if (string.IsNullOrEmpty(zipFilePath))
            {
                // Assume cancelled.
                return;
            }

#if UNITY_2018_3_OR_NEWER
            EditorUserBuildSettings.buildAppBundle = false;
#endif

            var baseApkDirectory = Path.GetTempPath();
            var baseApkPath      = Path.Combine(baseApkDirectory, BaseApkFileName);
            Debug.LogFormat("Building APK: {0}", baseApkPath);
            var buildPlayerOptions = PlayInstantBuilder.CreateBuildPlayerOptions(baseApkPath, BuildOptions.None);
            if (!PlayInstantBuilder.BuildAndSign(buildPlayerOptions))
            {
                // Do not log here. The method we called was responsible for logging.
                return;
            }

            // Zip creation is fast enough so call jar synchronously rather than wait for post build AppDomain reset.
            var zipFileResult = ZipUtils.CreateZipFile(zipFilePath, baseApkDirectory, BaseApkFileName);
            if (zipFileResult == null)
            {
                Debug.LogFormat("Created ZIP file: {0}", zipFilePath);
            }
            else
            {
                PlayInstantBuilder.DisplayBuildError(string.Format("Zip creation failed: {0}", zipFileResult));
            }
        }