Exemplo n.º 1
0
        private static void UpdatePackageReferences(NewProjectSettings settings)
        {
            try
            {
                string productVersion = Assembly.GetEntryAssembly().GetProductVersion();
                string flutterVersion = settings.FlutterVersion;
                if (string.IsNullOrEmpty(flutterVersion))
                {
                    flutterVersion = FlutterTools.GetVersion().Version;
                }

                SdkVersion        sdk = AppSettings.Default.SdkTable.Versions.First(v => v.Version == productVersion);
                SdkFlutterVersion fv  = sdk.Compatibility.FirstOrDefault(f => VersionUtils.Compare(f.Version, flutterVersion) == 0);
                if (fv == null)
                {
                    // We're using a version of Flutter that is not officially supported by Flutnet (no binding libraries exist).
                    // Let's try and see if we can find a prior version that's fully compatible.
                    // If we can't find anything, simply return and keep the template configuration as is.
                    sdk.Compatibility.Sort(new SdkFlutterVersionComparer());
                    fv = sdk.Compatibility.LastOrDefault(f => VersionUtils.Compare(f.Version, flutterVersion) < 0);
                    if (fv == null)
                    {
                        return;
                    }
                }

                if (settings.TargetAndroid)
                {
                    string interopVersion = !string.IsNullOrEmpty(fv.AndroidInteropVersion)
                        ? fv.AndroidInteropVersion
                        : fv.Version;

                    string csprojPath = Path.Combine(settings.SolutionPath, $"{settings.ProjectName}.Android", $"{settings.ProjectName}.Android.csproj");
                    UpdatePackageReferences_AndroidProject(csprojPath, interopVersion);
                    csprojPath = Path.Combine(settings.SolutionPath, $"{settings.ProjectName}.ModuleInterop.Android", $"{settings.ProjectName}.ModuleInterop.Android.csproj");
                    UpdatePackageReferences_AndroidProject(csprojPath, interopVersion);
                }

                if (settings.TargetIos && OperatingSystem.IsMacOS())
                {
                    string interopVersion = !string.IsNullOrEmpty(fv.IosInteropVersion)
                        ? fv.IosInteropVersion
                        : fv.Version;

                    string csprojPath = Path.Combine(settings.SolutionPath, $"{settings.ProjectName}.iOS", $"{settings.ProjectName}.iOS.csproj");
                    UpdatePackageReferences_iOSProject(csprojPath, interopVersion);
                    csprojPath = Path.Combine(settings.SolutionPath, $"{settings.ProjectName}.PluginInterop.iOS", $"{settings.ProjectName}.PluginInterop.iOS.csproj");
                    UpdatePackageReferences_iOSProject(csprojPath, interopVersion);
                }
            }
            catch (Exception e)
            {
                throw new CommandLineException(CommandLineErrorCode.NewProject_SetNativeReferencesFailed, e);
            }
        }
Exemplo n.º 2
0
 /// <summary>
 /// Build the Flutter module to generate the Android Archive (AAR) and/or the iOS framework
 /// that will be embedded into Xamarin applications.
 /// </summary>
 private static void BuildFlutterModule(NewProjectSettings settings, bool verbose = false)
 {
     try
     {
         if (settings.TargetAndroid)
         {
             FlutterTools.BuildAndroidArchive(settings.FlutterModulePath, FlutterModuleBuildConfig.Debug | FlutterModuleBuildConfig.Release, verbose);
         }
         if (settings.TargetIos && OperatingSystem.IsMacOS())
         {
             FlutterTools.BuildIosFramework(settings.FlutterModulePath, FlutterModuleBuildConfig.Debug | FlutterModuleBuildConfig.Release, verbose);
         }
     }
     catch (Exception e)
     {
         throw new CommandLineException(CommandLineErrorCode.NewProject_BuildFlutterModuleFailed, e);
     }
 }
Exemplo n.º 3
0
        private static void SetNativeReferences(NewProjectSettings settings, DartProject project)
        {
            try
            {
                if (settings.TargetAndroid)
                {
                    string csprojPath = Path.Combine(settings.SolutionPath, $"{settings.ProjectName}.ModuleInterop.Android", $"{settings.ProjectName}.ModuleInterop.Android.csproj");
                    SetNativeReference_AndroidBindings(csprojPath, project);
                }
                if (settings.TargetIos && OperatingSystem.IsMacOS())
                {
                    string csprojPath = Path.Combine(settings.SolutionPath, $"{settings.ProjectName}.PluginInterop.iOS", $"{settings.ProjectName}.PluginInterop.iOS.csproj");
                    SetNativeReference_iOSBindings(csprojPath, project);

                    csprojPath = Path.Combine(settings.SolutionPath, $"{settings.ProjectName}.iOS", $"{settings.ProjectName}.iOS.csproj");
                    SetNativeReference_iOSApp(csprojPath, project);
                }
            }
            catch (Exception e)
            {
                Log.Ex(e);
                throw new CommandLineException(CommandLineErrorCode.NewProject_SetNativeReferencesFailed, e);
            }
        }