Пример #1
0
 /// <summary>
 /// Runs the "flutter pub run build_runner build" command in the current working directory.
 /// The directory must contain a pubspec.yaml file.
 /// </summary>
 public static void BuildBuildRunner(string projectFolder, bool deleteConflictingOutputs = false, bool verbose = false)
 {
     FlutnetShell.RunCommand(
         deleteConflictingOutputs
             ? $"flutter pub run build_runner build --delete-conflicting-outputs"
             : $"flutter pub run build_runner build", projectFolder, verbose);
 }
Пример #2
0
        /// <summary>
        /// Runs the "flutter --version" command to retrieve the current version of Flutter.
        /// </summary>
        public static FlutterVersion GetVersion(bool verbose = false)
        {
            CommandResult result = FlutnetShell.RunCommand("flutter --version --no-version-check", Environment.CurrentDirectory, verbose);

            FlutterVersion version = new FlutterVersion();

            using (StringReader reader = new StringReader(result.StandardOutput))
            {
                string   versionLine = reader.ReadLine();
                string[] parts       = versionLine
                                       .Replace("Flutter", string.Empty, StringComparison.InvariantCultureIgnoreCase)
                                       .Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
                if (parts.Length > 0)
                {
                    version.Version = parts[0].Trim();
                }

                string frameworkRevLine = reader.ReadLine();
                int    index            = frameworkRevLine.IndexOf("revision ", StringComparison.InvariantCultureIgnoreCase);
                if (index != -1)
                {
                    version.FrameworkRev = frameworkRevLine.Substring(index + 9, 10).Trim();
                }

                string engineRevLine = reader.ReadLine();
                index = engineRevLine.IndexOf("revision ", StringComparison.InvariantCultureIgnoreCase);
                if (index != -1)
                {
                    version.EngineRev = engineRevLine.Substring(index + 9).Trim();
                }
            }

            return(version);
        }
Пример #3
0
        public static bool TryLocateJavaSdk(out string sdkPath)
        {
            string path;

            // Check #1 - JAVA_HOME environment variables

            path = GetEnvironmentVariable("JAVA_HOME");
            if (!string.IsNullOrEmpty(path))
            {
                sdkPath = path;
                return(true);
            }

            // Check #2 - Default Microsoft's Mobile OpenJDK location
            // https://docs.microsoft.com/en-us/xamarin/android/get-started/installation/openjdk#troubleshooting

            string jdkRoot;

            if (OperatingSystem.IsWindows())
            {
                jdkRoot = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles), "Android", "jdk");
            }
            else
            {
                jdkRoot = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Personal), "Library", "Developer", "Xamarin", "jdk");
            }
            path = Directory.EnumerateDirectories(jdkRoot, "microsoft_dist_openjdk_1.8.0.*").FirstOrDefault();

            if (!string.IsNullOrEmpty(path) && Directory.Exists(path))
            {
                sdkPath = path;
                return(true);
            }

            // Check #3 - Try look for Java SDK location inside Android Studio settings
            if (TryParseAndroidStudioConfig("JavaSDK", out path))
            {
                sdkPath = path;
                return(true);
            }

            // Check #4 - Try locate java executable/script
            if (FlutnetShell.TryLocateFile("java", out string javaFullPath))
            {
                try
                {
                    sdkPath = Path.GetDirectoryName(Path.GetDirectoryName(javaFullPath));
                    return(true);
                }
                catch
                {
                    // ignored
                }
            }

            sdkPath = default;
            return(false);
        }
Пример #4
0
        /// <summary>
        /// Runs the "flutter create -t package" command to create a Flutter package.
        /// </summary>
        /// <returns>A <see cref="Flutnet.Cli.Core.Dart.DartProject"/> that represents the newly created Flutter package.</returns>
        public static DartProject CreatePackage(string workingDir, string name, string description = null, bool verbose = false)
        {
            StringBuilder sb = new StringBuilder();

            sb.Append("flutter create -t package ");
            if (!string.IsNullOrEmpty(description))
            {
                sb.Append($"--description {description.Quoted()} ");
            }
            sb.Append(name);

            FlutnetShell.RunCommand(sb.ToString(), workingDir, verbose);

            DartProject prj = new DartProject(new DirectoryInfo(Path.Combine(workingDir, name)));

            prj.Load();
            return(prj);
        }
Пример #5
0
        /// <summary>
        /// Runs the "flutter build ios-framework" command to create an iOS framework
        /// to be integrated into a native iOS application (available only on macOS).
        /// </summary>
        public static void BuildIosFramework(string projectFolder, FlutterModuleBuildConfig buildConfig, bool verbose = false)
        {
            StringBuilder sb = new StringBuilder();

            sb.Append("flutter build ios-framework ");

            if (buildConfig != FlutterModuleBuildConfig.Default)
            {
                if (!buildConfig.HasFlag(FlutterModuleBuildConfig.Debug))
                {
                    sb.Append("--no-debug ");
                }
                if (!buildConfig.HasFlag(FlutterModuleBuildConfig.Profile))
                {
                    sb.Append("--no-profile ");
                }
                if (!buildConfig.HasFlag(FlutterModuleBuildConfig.Release))
                {
                    sb.Append("--no-release ");
                }
            }

            FlutnetShell.RunCommand(sb.ToString(), projectFolder, verbose);
        }
Пример #6
0
        private static string GetEnvironmentVariable(string variable)
        {
            string value = null;

            if (Utilities.OperatingSystem.IsWindows())
            {
                value = Environment.GetEnvironmentVariable(variable) ??
                        Environment.GetEnvironmentVariable(variable, EnvironmentVariableTarget.Machine);
            }
            else if (Utilities.OperatingSystem.IsMacOS())
            {
                try
                {
                    CommandResult result = FlutnetShell.RunInMacOsShell($"echo ${variable}", Environment.CurrentDirectory);
                    value = result.StandardOutput.Split(new[] { Environment.NewLine }, 2, StringSplitOptions.RemoveEmptyEntries).FirstOrDefault();
                }
                catch (Exception)
                {
                    // ignored
                }
            }

            return(value);
        }
Пример #7
0
        public static int Run()
        {
            if (Utilities.OperatingSystem.IsMacOS())
            {
                string shell1 = GetCurrentLoginShell();
                string shell2 = GetDefaultLoginShell();
                string rc     = GetShellConfigurationFile(shell1);
            }

            string flutterSdkPath = null;

            if (!FlutnetShell.TryLocateFile("flutter", out string path))
            {
                FlutterAssistant.Configure(Utilities.OperatingSystem.IsMacOS()
                    ? DefaultFlutterSdkPath_macOS : DefaultFlutterSdkPath_Windows, string.Empty, string.Empty);

                if (FlutnetShell.TryLocateFile("flutter", out string path2))
                {
                    flutterSdkPath = Path.GetDirectoryName(Path.GetDirectoryName(path2));
                }
            }
            else
            {
                flutterSdkPath = Path.GetDirectoryName(Path.GetDirectoryName(path));
            }

            Console.WriteLine("Flutter bin path: {0}", flutterSdkPath);

            //FlutterTools.GetDoctorReport();

            //string env = GetEnvironmentVariable("ANDROID_SDK_ROOT");

            //FlutterAssistant.DiagnosticResult diag = FlutterAssistant.RunDiagnostic();

            return(0);
        }
Пример #8
0
        /// <summary>
        /// Runs the "flutter doctor" command to retrieve the status of the current installation of Flutter.
        /// </summary>
        public static FlutterDoctorReport GetDoctorReport(bool verbose = false)
        {
            CommandResult result = FlutnetShell.RunCommand("flutter doctor --no-version-check", Environment.CurrentDirectory, verbose);

            FlutterDoctorReport report = new FlutterDoctorReport();

            using (StringReader reader = new StringReader(result.StandardOutput))
            {
                // Read "Doctor summary" first line
                reader.ReadLine();

                FlutterDoctorReportItemBuilder builder = null;
                string line;
                while ((line = reader.ReadLine()) != null)
                {
                    if (string.IsNullOrEmpty(line))
                    {
                        if (builder != null)
                        {
                            report.Items.Add(builder.Build());
                            builder = null;
                        }
                    }

                    if (!line.StartsWith("["))
                    {
                        builder?.AddContent(line.TrimStart());
                        continue;
                    }

                    int index = line.IndexOf("]", StringComparison.InvariantCultureIgnoreCase);
                    if (index != -1)
                    {
                        string symbol = line.Substring(1, index - 1);
                        string msg    = line.Substring(index + 2);

                        if (builder != null)
                        {
                            report.Items.Add(builder.Build());
                        }
                        builder = new FlutterDoctorReportItemBuilder(msg);

                        switch (symbol)
                        {
                        case "√":
                        case "✓":
                            builder.SetType(FlutterDoctorReportItemType.Check);
                            break;

                        case "!":
                            builder.SetType(FlutterDoctorReportItemType.Warning);
                            break;

                        default:
                            builder.SetType(FlutterDoctorReportItemType.Error);
                            break;
                        }
                    }
                }
            }

            return(report);
        }
Пример #9
0
 /// <summary>
 /// Runs the "flutter pub get" command to get all the dependencies listed in the pubspec.yaml file
 /// in the current working directory, as well as their transitive dependencies.
 /// </summary>
 public static void GetDependencies(string projectFolder, bool verbose = false)
 {
     FlutnetShell.RunCommand("flutter pub get", projectFolder, verbose);
 }
Пример #10
0
 /// <summary>
 /// Runs the "flutter pub upgrade" command.
 /// </summary>
 public static void PubUpgrade(string projectFolder, bool verbose = false)
 {
     FlutnetShell.RunCommand("flutter pub upgrade", projectFolder, verbose);
 }
Пример #11
0
 /// <summary>
 /// Runs the "flutter clean" command to remove all the files produced by the previous build(s), such as the build folder.
 /// </summary>
 public static void Clean(string projectFolder, bool verbose = false)
 {
     FlutnetShell.RunCommand("flutter clean", projectFolder, verbose);
 }
Пример #12
0
        public static bool TryLocateAndroidSdk(out string sdkPath)
        {
            string path;

            // Check #1 - ANDROID_SDK_ROOT or ANDROID_HOME environment variables

            path = GetEnvironmentVariable("ANDROID_SDK_ROOT");
            if (!string.IsNullOrEmpty(path))
            {
                sdkPath = path;
                return(true);
            }

            path = GetEnvironmentVariable("ANDROID_HOME");
            if (!string.IsNullOrEmpty(path))
            {
                sdkPath = path;
                return(true);
            }

            // Check #2 - Default Xamarin Android SDK location

            if (OperatingSystem.IsWindows())
            {
                // https://docs.microsoft.com/en-us/xamarin/android/troubleshooting/questions/android-sdk-location?tabs=windows
                path = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ProgramFilesX86), "Android", "android-sdk");
            }
            else
            {
                // https://docs.microsoft.com/en-us/xamarin/android/troubleshooting/questions/android-sdk-location?tabs=macos
                path = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Personal), "Library", "Developer", "Xamarin", "android-sdk-macosx");
            }

            if (Directory.Exists(path))
            {
                sdkPath = path;
                return(true);
            }

            // Check #3 - Try look for Android SDK location inside Android Studio settings
            if (TryParseAndroidStudioConfig("Android SDK", out path))
            {
                sdkPath = path;
                return(true);
            }

            // Check #4 - Try locate adb executable/script
            //NOTE: This command can fail also on machines where Android SDK and Xamarin.Android are correctly installed
            //      (You're not required to add Android SDK platform-tools folder - where adb resides - to PATH environment variable)
            if (FlutnetShell.TryLocateFile("adb", out string adbFullPath))
            {
                try
                {
                    sdkPath = Path.GetDirectoryName(Path.GetDirectoryName(adbFullPath));
                    return(true);
                }
                catch
                {
                    // ignored
                }
            }

            sdkPath = default;
            return(false);
        }