예제 #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);
        }
예제 #2
0
        /// <summary>
        /// Builds an APK to a temporary location using the scenes selected in Unity's main Build Settings.
        /// </summary>
        public static void BuildAndRun()
        {
            if (!PlayInstantBuilder.CheckBuildPrerequisites())
            {
                return;
            }

            var jarPath = Path.Combine(AndroidSdkManager.AndroidSdkRoot, InstantAppsJarPath);

            if (!File.Exists(jarPath))
            {
                Debug.LogErrorFormat("Build and Run failed to locate ia.jar file at: {0}", jarPath);
                var message =
                    string.Format(
                        "Failed to locate version 1.2 or later of the {0}.\n\nClick \"OK\" to install the {0}.",
                        InstantAppsSdkDisplayName);
                if (PlayInstantBuilder.DisplayBuildErrorDialog(message))
                {
                    InstallPlayInstantSdk();
                }

                return;
            }

#if UNITY_2018_3_OR_NEWER
            EditorUserBuildSettings.buildAppBundle = false;
#endif

            var apkPath = Path.Combine(Path.GetTempPath(), "temp.apk");
            Debug.LogFormat("Build and Run package location: {0}", apkPath);

            var buildPlayerOptions = PlayInstantBuilder.CreateBuildPlayerOptions(apkPath,
                                                                                 EditorUserBuildSettings.development ? BuildOptions.Development : BuildOptions.None);
            if (!PlayInstantBuilder.BuildAndSign(buildPlayerOptions))
            {
                // Do not log here. The method we called was responsible for logging.
                return;
            }

            var window = PostBuildCommandLineDialog.CreateDialog("Install and run app");
            window.modal              = false;
            window.summaryText        = "Installing app on device";
            window.bodyText           = "The APK built successfully.\n\n";
            window.autoScrollToBottom = true;
            window.CommandLineParams  = new CommandLineParameters
            {
                FileName  = JavaUtilities.JavaBinaryPath,
                Arguments = string.Format(
                    "-jar {0} run {1}",
                    CommandLine.QuotePath(jarPath),
                    CommandLine.QuotePath(apkPath))
            };
            window.CommandLineParams.AddEnvironmentVariable(
                AndroidSdkManager.AndroidHome, AndroidSdkManager.AndroidSdkRoot);
            window.Show();
        }
예제 #3
0
        /// <summary>
        /// Builds an APK to a temporary location using the scenes selected in Unity's main Build Settings.
        /// </summary>
        public static void BuildAndRun()
        {
            if (!Directory.Exists(AndroidSdkManager.AndroidSdkRoot))
            {
                PlayInstantBuilder.LogError("Failed to locate the Android SDK. Check Preferences -> External Tools to set the path.");
                return;
            }

            var jarPath = Path.Combine(AndroidSdkManager.AndroidSdkRoot, InstantAppsJarPath);

            if (!File.Exists(jarPath))
            {
                Debug.LogErrorFormat("Build and Run failed to locate ia.jar file at: {0}", jarPath);
                var message =
                    string.Format(
                        "Failed to locate version 1.2 or later of the {0}.\n\nClick \"OK\" to install the {0}.",
                        PlayInstantSdkInstaller.InstantAppsSdkName);
                if (PlayInstantBuilder.DisplayBuildErrorDialog(message))
                {
                    PlayInstantSdkInstaller.SetUp();
                }

                return;
            }

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

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

            var buildPlayerOptions = PlayInstantBuilder.CreateBuildPlayerOptions(apkPath,
                                                                                 EditorUserBuildSettings.development ? BuildOptions.Development : BuildOptions.None);

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

            var window = PostBuildCommandLineDialog.CreateDialog("Install and run app");

            window.modal              = false;
            window.summaryText        = "Installing app on device";
            window.bodyText           = "The APK built successfully. Waiting for scripts to reload...\n";
            window.autoScrollToBottom = true;
            window.CommandLineParams  = new CommandLineParameters
            {
                FileName  = JavaUtilities.JavaBinaryPath,
                Arguments = string.Format(
                    "-jar {0} run {1}",
                    CommandLine.QuotePathIfNecessary(jarPath),
                    CommandLine.QuotePathIfNecessary(apkPath))
            };
            window.CommandLineParams.AddEnvironmentVariable(
                AndroidSdkManager.AndroidHome, AndroidSdkManager.AndroidSdkRoot);
            window.Show();
        }