Exemplo n.º 1
0
        /// <summary>
        /// Configures the project to prepare for building the specified scenes in an instant app.
        /// </summary>
        public static void ConfigureProject(string[] scenesInBuild)
        {
            var requiredPolicies = PlayInstantSettingPolicy.GetRequiredPolicies();

            foreach (var policy in requiredPolicies)
            {
                var policyChangeCompleted = policy.ChangeState();
                if (!policyChangeCompleted)
                {
                    throw new Exception(string.Format("Failed to change policy: {0}", policy.Name));
                }
            }

            SetTargetArchitectures();

            var manifestUpdater = AndroidManifestHelper.GetAndroidManifestUpdater();
            var errorMessage    = manifestUpdater.SwitchToInstant(null);

            if (errorMessage != null)
            {
                throw new Exception(string.Format("Error updating AndroidManifest.xml: {0}", errorMessage));
            }

            PlayInstantBuildConfiguration.AddScriptingDefineSymbol(
                PlaySignatureVerifier.SkipVerifyGooglePlayServicesScriptingDefineSymbol);
            PlayInstantBuildConfiguration.SaveConfiguration("", scenesInBuild, "");
            PlayInstantBuildConfiguration.SetInstantBuildType();
        }
        /// <summary>
        /// Builds a Play Instant APK or AAB based on the specified options.
        /// Displays warning/error dialogs if there are issues during the build.
        /// </summary>
        /// <returns>True if the build succeeded, false if it failed or was cancelled.</returns>
        public static bool Build(BuildPlayerOptions buildPlayerOptions)
        {
            var checkInstantManifestResult = AndroidManifestHelper.GetAndroidManifestUpdater().CheckInstantManifest();

            if (checkInstantManifestResult != null)
            {
                DisplayBuildError(string.Format("Failed to update manifest: {0}", checkInstantManifestResult));
                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:
                DisplayBuildError(string.Format("Build failed with {0} error(s)", buildReport.summary.totalErrors));
                return(false);

            default:
                DisplayBuildError("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
            {
                DisplayBuildError(buildReport);
            }

            return(false);
#endif
        }