Пример #1
0
 public static SdkConfigOptions DeOptionalize(this OptionalSdkConfigOptions sdkConfigOptions)
 {
     return(new SdkConfigOptions()
     {
         AndroidSdkDirectory = sdkConfigOptions.AndroidSdkDirectory.Select(dir => dir.NativePath).Or((string)null),
         AndroidNdkDirectory = sdkConfigOptions.AndroidNdkDirectory.Select(dir => dir.NativePath).Or((string)null),
         JavaJdkDirectory = sdkConfigOptions.JavaJdkDirectory.Select(dir => dir.NativePath).Or((string)null),
         HaveAllSdkPackages = sdkConfigOptions.HaveAllSdkPackages
     });
 }
Пример #2
0
        public void Save(OptionalSdkConfigOptions options)
        {
            if (_fs.Exists(_configPath.ContainingDirectory) == false)
            {
                _fs.Create(_configPath.ContainingDirectory);
            }

            _fs.ReplaceText(_configPath, JsonConvert.SerializeObject(options.DeOptionalize(),
                                                                     new JsonSerializerSettings
            {
                NullValueHandling = NullValueHandling.Ignore
            }));
        }
Пример #3
0
        public static OptionalSdkConfigOptions VerifyInstallation(IFileSystem fs, OptionalSdkConfigOptions config, IProgress <InstallerEvent> progress)
        {
            // Verify everything
            var javaValidator = new JavaValidator(fs);

            if (!IsInstalled(config.JavaJdkDirectory, javaValidator.IsInstalledAt, progress))
            {
                config.JavaJdkDirectory = Optional.None();
            }

            var androidSdkValidator = new AndroidSDKValidator(fs);

            if (!IsInstalled(config.AndroidSdkDirectory, androidSdkValidator.IsInstalledAt, progress))
            {
                config.AndroidSdkDirectory = Optional.None();
            }

            config.HaveAllSdkPackages = IsInstalled(config.AndroidSdkDirectory, androidSdkValidator.AreRequiredPackagesInstalled, progress);

            return(config);
        }
Пример #4
0
        void Install(OptionalSdkConfigOptions config, InstallOptions opts)
        {
            // Remove old NDK installation
            config.AndroidNdkDirectory.Do(ndkPath => BackwardCompatibility.RemoveOldNdk(_fs, ndkPath));

            if (config.JavaJdkDirectory.HasValue == false)
            {
                var javaValidator = new JavaValidator(_fs);
                config.JavaJdkDirectory = TryToFindJdk(_fs, javaValidator, _progress)
                                          .Or(() => opts.Noninteractive ? Optional.None() : AskUserToProvidePath("Java Development Kit", javaValidator, _progress));
            }

            if (config.AndroidSdkDirectory.HasValue == false)
            {
                var androidSdkValidator = new AndroidSDKValidator(_fs);
                config.AndroidSdkDirectory = TryToFindAndroidSdk(androidSdkValidator, _progress)
                                             .Or(() => opts.Noninteractive ? Optional.None() : AskUserToProvidePath("Android SDK", androidSdkValidator, _progress));
            }

            // Then install based on configuration
            config.JavaJdkDirectory = config.JavaJdkDirectory.MatchWith(
                _ => _,
                () =>
            {
                var defaultPath = Platform.OperatingSystem == OS.Windows
                                                ? PathExtensions.GetEnvironmentPath(Environment.SpecialFolder.ProgramFiles)
                                  / new DirectoryName("Java")
                                  / new DirectoryName("jdk1.8.0_40")
                                                : AbsoluteDirectoryPath.Parse("/Library/Java/JavaVirtualMachines")
                                  / new DirectoryName("jdk1.8.0_40.jdk")
                                  / new DirectoryName("Contents")
                                  / new DirectoryName("Home");

                var installer = new JavaInstaller(_fs);
                installer.Install(CancellationToken.None, _dialog, _progress, opts);
                return(defaultPath);
            });

            config.JavaJdkDirectory.Do(jdk => Environment.SetEnvironmentVariable("JAVA_HOME", jdk.NativePath, EnvironmentVariableTarget.Process));

            config.AndroidSdkDirectory = config.AndroidSdkDirectory.MatchWith(
                _ => _,
                () =>
            {
                var defaultPath = Platform.OperatingSystem == OS.Mac
                                                ? PathExtensions.GetEnvironmentPath(Environment.SpecialFolder.Personal)
                                  / new DirectoryName("Library")
                                  / new DirectoryName("Android")
                                  / new DirectoryName("sdk")
                                                : PathExtensions.GetEnvironmentPath(Environment.SpecialFolder.LocalApplicationData)
                                  / new DirectoryName("Fusetools")
                                  / new DirectoryName("Fuse")
                                  / new DirectoryName("Android")
                                  / new DirectoryName("AndroidSDK");

                var installer = new AndroidSDKInstaller(defaultPath, _fs);
                installer.Install(CancellationToken.None, _dialog, _progress, opts);
                return(defaultPath);
            });

            config.AndroidSdkDirectory.Do(
                androidRoot =>
            {
                if (config.HaveAllSdkPackages &&
                    config.AndroidNdkDirectory.HasValue)
                {
                    return;
                }

                var installer = new AndroidSDKPackageInstaller(
                    _fs,
                    androidRoot,
                    Platform.OperatingSystem == OS.Windows
                                                        ? androidRoot / new DirectoryName("tools") / new FileName("android.bat")
                                                        : androidRoot / new DirectoryName("tools") / new FileName("android"),
                    Platform.OperatingSystem == OS.Windows
                                                        ? androidRoot / new DirectoryName("tools") / new DirectoryName("bin") / new FileName("sdkmanager.bat")
                                                        : androidRoot / new DirectoryName("tools") / new DirectoryName("bin") / new FileName("sdkmanager"));

                var result = installer.Install(CancellationToken.None, _dialog, _progress);

                config.AndroidNdkDirectory = result.NdkBundle;
            });
        }