Exemplo n.º 1
0
        public virtual bool Initialize(BuildToolLogger buildToolLogger)
        {
            if (!_androidBuildTools.Initialize(buildToolLogger) || !_androidSdkPlatform.Initialize(buildToolLogger))
            {
                return(false);
            }

            var newestBuildToolsVersion = _androidBuildTools.GetNewestBuildToolsVersion();

            if (newestBuildToolsVersion == null)
            {
                buildToolLogger.DisplayErrorDialog(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 (buildToolLogger.DisplayActionableErrorDialog(message))
            {
                AndroidSdkPackageInstaller.InstallPackage(BuildToolsPackageName, BuildToolsDisplayName);
            }

            return(false);
        }
Exemplo n.º 2
0
        public virtual bool Initialize(BuildToolLogger buildToolLogger)
        {
            if (!_androidSdk.Initialize(buildToolLogger))
            {
                return(false);
            }

            string ignoredPath;
            var    newestVersion = GetNewestVersionAndPath(out ignoredPath);

            if (newestVersion == null)
            {
                // Being unable to find any existing SDK may indicate a config issue, so don't try to install a new SDK.
                buildToolLogger.DisplayErrorDialog(
                    "Failed to locate any Android SDK Platform version. Check that the Android SDK specified "
                    + "through Preferences -> External Tools has at least one Android SDK Platform installed.");
                return(false);
            }

            if (newestVersion < MinimumVersion)
            {
                var installedVersionMessage = string.Format(
                    "The highest installed Android API Level is {0}, however version {1} is the minimum "
                    + "required to build for Google Play.\n\nClick \"OK\" to install Android API Level {2}.",
                    newestVersion, MinimumVersion, LatestVersion);
                if (buildToolLogger.DisplayActionableErrorDialog(installedVersionMessage))
                {
                    // Note: this install can be slow, but it's not clear that it's any slower through Unity.
                    AndroidSdkPackageInstaller.InstallPackage(
                        string.Format("platforms;android-{0}", LatestVersion),
                        string.Format("Android SDK Platform {0}", LatestVersion),
                        _androidSdk.RootPath);
                }

                return(false);
            }

            var targetSdkVersion = PlayerSettings.Android.targetSdkVersion;

            if (targetSdkVersion == AndroidSdkVersions.AndroidApiLevelAuto || (int)targetSdkVersion >= MinimumVersion)
            {
                return(true);
            }

            var selectedVersionMessage = string.Format(
                "The currently selected Android Target API Level is {0}, however version {1} is the minimum "
                + "required to build for Google Play.\n\nClick \"OK\" to change the Target API Level to "
                + "\"Automatic (highest installed)\", which is currently {2}.",
                (int)targetSdkVersion, MinimumVersion, newestVersion);

            if (buildToolLogger.DisplayActionableErrorDialog(selectedVersionMessage))
            {
                PlayerSettings.Android.targetSdkVersion = AndroidSdkVersions.AndroidApiLevelAuto;
            }

            return(false);
        }
        private static string GetInstantAppJarPath(AndroidSdk androidSdk, BuildToolLogger buildToolLogger)
        {
            var jarPath = Path.Combine(androidSdk.RootPath, InstantAppsJarPath);

            if (File.Exists(jarPath))
            {
                return(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 (buildToolLogger.DisplayActionableErrorDialog(message))
            {
                AndroidSdkPackageInstaller.InstallPackage(InstantAppsSdkPackageName, InstantAppsSdkDisplayName);
            }

            return(null);
        }