/// <summary>
        /// Builds an Android App Bundle at a location specified in a file save dialog.
        /// The AAB will include asset packs configured in Asset Delivery Settings.
        /// </summary>
        public static void Build()
        {
            // Check that we're ready to build before displaying the file save dialog.
            var appBundleBuilder = CreateAppBundleBuilder();

            if (!appBundleBuilder.Initialize(new BuildToolLogger()))
            {
                return;
            }

            var aabFilePath = EditorUtility.SaveFilePanel("Create Android App Bundle", null, null, "aab");

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

            var buildSettings = new AppBundleBuildSettings
            {
                buildPlayerOptions = AndroidBuildHelper.CreateBuildPlayerOptions(aabFilePath),
                assetPackConfig    = AssetPackConfigSerializer.LoadConfig()
            };

            Build(appBundleBuilder, buildSettings);
        }
Esempio n. 2
0
        /// <summary>
        /// Emulates Unity's File -> Build And Run menu option.
        /// </summary>
        private static void EmulateUnityBuildAndRun()
        {
            var androidSdk         = new AndroidSdk();
            var androidSdkPlatform = new AndroidSdkPlatform(androidSdk);
            var androidBuildTools  = new AndroidBuildTools(androidSdk);
            var javaUtils          = new JavaUtils();
            var apkSigner          = new ApkSigner(androidBuildTools, javaUtils);
            var androidBuilder     = new AndroidBuilder(androidSdkPlatform, apkSigner);
            var buildToolLogger    = new BuildToolLogger();

            if (!androidBuilder.Initialize(buildToolLogger))
            {
                return;
            }

            if (EditorUserBuildSettings.androidBuildSystem == AndroidBuildSystem.Gradle)
            {
                EditorUserBuildSettings.exportAsGoogleAndroidProject = false;
            }

            var artifactName       = AndroidAppBundle.IsNativeBuildEnabled() ? "temp.aab" : "temp.apk";
            var artifactPath       = Path.Combine(Path.GetTempPath(), artifactName);
            var buildPlayerOptions = AndroidBuildHelper.CreateBuildPlayerOptions(artifactPath);

            buildPlayerOptions.options |= BuildOptions.AutoRunPlayer;
            androidBuilder.Build(buildPlayerOptions);
        }
Esempio n. 3
0
        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.LabelField("Scenes in Build", EditorStyles.boldLabel);
            EditorGUILayout.LabelField(
                string.Format(
                    "Note: the following settings affect APKs and app bundles built using the \"{0}\" menu's " +
                    "build actions, but not apps built using the \"File\" menu's build actions.",
                    GoogleEditorMenu.MainMenuName), descriptionTextStyle);
            EditorGUILayout.Space();

            EditorGUILayout.LabelField(
                "The scenes in the build are selected via Unity's \"Build Settings\" window.", descriptionTextStyle);
            EditorGUILayout.Space();
            EditorGUILayout.BeginHorizontal();
            var enabledScenes = string.Join(", ", AndroidBuildHelper.GetEditorBuildEnabledScenes());

            EditorGUILayout.LabelField(string.Format("Scenes: {0}", enabledScenes), EditorStyles.wordWrappedLabel);
            if (GUILayout.Button("Update", GUILayout.Width(100)))
            {
                GetWindow(Type.GetType("UnityEditor.BuildPlayerWindow,UnityEditor"), true);
            }

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

            EditorGUILayout.LabelField(
                "If you use AssetBundles, provide the path to your AssetBundle Manifest file below to ensure that " +
                "required engine components are not stripped during the build process.", descriptionTextStyle);
            EditorGUILayout.Space();
            _assetBundleManifestPath =
                GetLabelAndTextField("AssetBundle Manifest (Optional)", _assetBundleManifestPath);
            EditorGUILayout.Space();

            // Disable the Save button unless one of the fields has changed.
            GUI.enabled = IsAnyFieldChanged();

            if (GUILayout.Button("Save"))
            {
                SaveConfiguration();
            }

            GUI.enabled = true;
        }
 /// <summary>
 /// Sets the instant build type. If true, changes the build type to instant and creates a "PLAY_INSTANT"
 /// scripting define symbol. If false, removes the "PLAY_INSTANT" scripting define symbol.
 /// This setting only affects builds started through <see cref="Bundletool"/> or the "Google" Editor menu.
 /// This method can only be called on the Editor's main thread.
 /// </summary>
 public static void SetInstantBuildType(bool instantBuild)
 {
     if (instantBuild)
     {
         AndroidBuildHelper.AddScriptingDefineSymbol(PlayInstantScriptingDefineSymbol);
     }
     else
     {
         AndroidBuildHelper.RemoveScriptingDefineSymbol(PlayInstantScriptingDefineSymbol);
     }
 }
Esempio n. 5
0
        /// <summary>
        /// Builds an Android App Bundle to a temp directory and then runs it on device.
        /// </summary>
        public static void BuildAndRun()
        {
            var buildSettings = new AppBundleBuildSettings
            {
                requirePrerequisiteChecks = true,
                runOnDevice = true
            };

            var appBundleBuilder   = CreateAppBundleBuilder();
            var tempOutputFilePath = Path.Combine(appBundleBuilder.WorkingDirectoryPath, "temp.aab");
            var buildPlayerOptions = AndroidBuildHelper.CreateBuildPlayerOptions(tempOutputFilePath);
            var assetPackConfig    = AssetPackConfigSerializer.LoadConfig();

            Build(appBundleBuilder, buildPlayerOptions, assetPackConfig, buildSettings);
        }
Esempio n. 6
0
        public static void Build()
        {
            if (!DisplayDeletionWarning("Build Asset Delivery Demo"))
            {
                return;
            }

            var assetPackConfig    = CreateAssetPackConfig();
            var buildPlayerOptions = AndroidBuildHelper.CreateBuildPlayerOptions(AabFilePath);

            buildPlayerOptions.scenes = new[] { AssetDatabase.GUIDToAssetPath(DemoSceneGuid) };
            if (!Bundletool.BuildBundle(buildPlayerOptions, assetPackConfig))
            {
                throw new Exception("Asset Delivery Demo build failed");
            }
        }
Esempio n. 7
0
        /// <summary>
        /// Emulates Unity's File -> Build And Run menu option.
        /// </summary>
        private static void EmulateUnityBuildAndRun()
        {
            var androidSdk         = new AndroidSdk();
            var androidSdkPlatform = new AndroidSdkPlatform(androidSdk);
            var androidBuilder     = new AndroidBuilder(androidSdkPlatform);
            var buildToolLogger    = new BuildToolLogger();

            if (!androidBuilder.Initialize(buildToolLogger))
            {
                return;
            }

            var artifactName       = EditorUserBuildSettings.buildAppBundle ? "temp.aab" : "temp.apk";
            var artifactPath       = Path.Combine(Path.GetTempPath(), artifactName);
            var buildPlayerOptions = AndroidBuildHelper.CreateBuildPlayerOptions(artifactPath);

            buildPlayerOptions.options |= BuildOptions.AutoRunPlayer;
            androidBuilder.Build(buildPlayerOptions);
        }
        /// <summary>
        /// Builds an Android App Bundle to a temp directory and then runs it on device.
        /// The AAB will include asset packs configured in Asset Delivery Settings.
        /// </summary>
        public static void BuildAndRun()
        {
            var appBundleBuilder = CreateAppBundleBuilder();

            if (!appBundleBuilder.Initialize(new BuildToolLogger()))
            {
                return;
            }

            var tempOutputFilePath = Path.Combine(appBundleBuilder.WorkingDirectoryPath, "temp.aab");
            var buildSettings      = new AppBundleBuildSettings
            {
                buildPlayerOptions = AndroidBuildHelper.CreateBuildPlayerOptions(tempOutputFilePath),
                assetPackConfig    = AssetPackConfigSerializer.LoadConfig(),
                runOnDevice        = true
            };

            Build(appBundleBuilder, buildSettings);
        }
        /// <summary>
        /// Builds an APK to a temporary location, then installs and runs it using ia.jar
        /// </summary>
        private static void BuildAndRunApk(BuildToolLogger buildToolLogger)
        {
            var androidSdk             = new AndroidSdk();
            var androidSdkPlatform     = new AndroidSdkPlatform(androidSdk);
            var androidBuildTools      = new AndroidBuildTools(androidSdk);
            var javaUtils              = new JavaUtils();
            var apkSigner              = new ApkSigner(androidBuildTools, javaUtils);
            var androidBuilder         = new AndroidBuilder(androidSdkPlatform, apkSigner);
            var playInstantBuildHelper = new PlayInstantBuildHelper(isInstantRequired: true);

            if (!androidBuilder.Initialize(buildToolLogger) ||
                !playInstantBuildHelper.Initialize(buildToolLogger) ||
                !javaUtils.Initialize(buildToolLogger))
            {
                return;
            }

            var jarPath = IaJarPath;

            if (jarPath == null)
            {
                buildToolLogger.DisplayErrorDialog("Build and Run failed to locate ia.jar file");
                return;
            }

            AndroidAppBundle.DisableNativeBuild();

            var apkPath = Path.Combine(Path.GetTempPath(), "temp.apk");

            Debug.LogFormat("Build and Run package location: {0}", apkPath);

            var buildPlayerOptions = AndroidBuildHelper.CreateBuildPlayerOptions(apkPath);

            if (!androidBuilder.BuildAndSign(buildPlayerOptions))
            {
                // Do not log here. The method we called was responsible for logging.
                return;
            }

            InstallInstantApp(jarPath, apkPath, androidSdk, javaUtils);
        }
Esempio n. 10
0
 /// <summary>
 /// Returns true if the currently selected build type is "Instant" or false if "Installed".
 /// This method can only be called on the Editor's main thread.
 /// </summary>
 public static bool IsInstantBuildType()
 {
     return(AndroidBuildHelper.IsScriptingSymbolDefined(PlayInstantScriptingDefineSymbol));
 }