string GenerateCommandLineCommands(string ManifestFile, string currentAbi, string currentResourceOutputFile) { var cmd = new CommandLineBuilder(); cmd.AppendSwitch("link"); if (MonoAndroidHelper.LogInternalExceptions) { cmd.AppendSwitch("-v"); } string manifestDir = Path.Combine(Path.GetDirectoryName(ManifestFile), currentAbi != null ? currentAbi : "manifest"); Directory.CreateDirectory(manifestDir); string manifestFile = Path.Combine(manifestDir, Path.GetFileName(ManifestFile)); ManifestDocument manifest = new ManifestDocument(ManifestFile, this.Log); manifest.SdkVersion = AndroidSdkPlatform; if (!string.IsNullOrEmpty(VersionCodePattern)) { try { manifest.CalculateVersionCode(currentAbi, VersionCodePattern, VersionCodeProperties); } catch (ArgumentOutOfRangeException ex) { Log.LogCodedError("XA0003", ManifestFile, 0, ex.Message); return(string.Empty); } } if (currentAbi != null && string.IsNullOrEmpty(VersionCodePattern)) { manifest.SetAbi(currentAbi); } if (!manifest.ValidateVersionCode(out string error, out string errorCode)) { Log.LogCodedError(errorCode, ManifestFile, 0, error); return(string.Empty); } manifest.ApplicationName = ApplicationName; manifest.Save(manifestFile); cmd.AppendSwitchIfNotNull("--manifest ", manifestFile); if (!string.IsNullOrEmpty(JavaDesignerOutputDirectory)) { var designerDirectory = Path.IsPathRooted(JavaDesignerOutputDirectory) ? JavaDesignerOutputDirectory : Path.Combine(WorkingDirectory, JavaDesignerOutputDirectory); Directory.CreateDirectory(designerDirectory); cmd.AppendSwitchIfNotNull("--java ", JavaDesignerOutputDirectory); } if (PackageName != null) { cmd.AppendSwitchIfNotNull("--custom-package ", PackageName.ToLowerInvariant()); } if (AdditionalResourceArchives != null) { foreach (var item in AdditionalResourceArchives) { var flata = Path.Combine(WorkingDirectory, item.ItemSpec); if (File.Exists(flata)) { cmd.AppendSwitchIfNotNull("-R ", flata); } else { Log.LogDebugMessage("Archive does not exist: " + flata); } } } if (CompiledResourceFlatArchive != null) { var flata = Path.Combine(WorkingDirectory, CompiledResourceFlatArchive.ItemSpec); if (File.Exists(flata)) { cmd.AppendSwitchIfNotNull("-R ", flata); } else { Log.LogDebugMessage("Archive does not exist: " + flata); } } cmd.AppendSwitch("--auto-add-overlay"); if (!string.IsNullOrWhiteSpace(UncompressedFileExtensions)) { foreach (var ext in UncompressedFileExtensions.Split(new char [] { ';', ',' }, StringSplitOptions.RemoveEmptyEntries)) { cmd.AppendSwitchIfNotNull("-0 ", ext); } } if (!string.IsNullOrEmpty(ExtraPackages)) { cmd.AppendSwitchIfNotNull("--extra-packages ", ExtraPackages); } cmd.AppendSwitchIfNotNull("-I ", JavaPlatformJarPath); if (!string.IsNullOrEmpty(ResourceSymbolsTextFile)) { cmd.AppendSwitchIfNotNull("--output-text-symbols ", ResourceSymbolsTextFile); } if (ProtobufFormat) { cmd.AppendSwitch("--proto-format"); } var extraArgsExpanded = ExpandString(ExtraArgs); if (extraArgsExpanded != ExtraArgs) { Log.LogDebugMessage(" ExtraArgs expanded: {0}", extraArgsExpanded); } if (!string.IsNullOrWhiteSpace(extraArgsExpanded)) { cmd.AppendSwitch(extraArgsExpanded); } if (!string.IsNullOrWhiteSpace(AssetsDirectory)) { var assetDir = AssetsDirectory.TrimEnd('\\'); if (!Path.IsPathRooted(assetDir)) { assetDir = Path.Combine(WorkingDirectory, assetDir); } if (!string.IsNullOrWhiteSpace(assetDir) && Directory.Exists(assetDir)) { cmd.AppendSwitchIfNotNull("-A ", assetDir); } } cmd.AppendSwitchIfNotNull("-o ", currentResourceOutputFile); return(cmd.ToString()); }
string [] GenerateCommandLineCommands(string ManifestFile, string currentAbi, string currentResourceOutputFile) { List <string> cmd = new List <string> (); string manifestDir = Path.Combine(Path.GetDirectoryName(ManifestFile), currentAbi != null ? currentAbi : "manifest"); Directory.CreateDirectory(manifestDir); string manifestFile = Path.Combine(manifestDir, Path.GetFileName(ManifestFile)); ManifestDocument manifest = new ManifestDocument(ManifestFile); manifest.SdkVersion = AndroidSdkPlatform; if (!string.IsNullOrEmpty(VersionCodePattern)) { try { manifest.CalculateVersionCode(currentAbi, VersionCodePattern, VersionCodeProperties); } catch (ArgumentOutOfRangeException ex) { LogCodedError("XA0003", ManifestFile, 0, ex.Message); return(cmd.ToArray()); } } if (currentAbi != null && string.IsNullOrEmpty(VersionCodePattern)) { manifest.SetAbi(currentAbi); } if (!manifest.ValidateVersionCode(out string error, out string errorCode)) { LogCodedError(errorCode, ManifestFile, 0, error); return(cmd.ToArray()); } manifest.ApplicationName = ApplicationName; manifest.Save(LogCodedWarning, manifestFile); cmd.Add("link"); if (MonoAndroidHelper.LogInternalExceptions) { cmd.Add("-v"); } cmd.Add($"--manifest"); cmd.Add(GetFullPath(manifestFile)); if (!string.IsNullOrEmpty(JavaDesignerOutputDirectory)) { var designerDirectory = Path.IsPathRooted(JavaDesignerOutputDirectory) ? JavaDesignerOutputDirectory : Path.Combine(WorkingDirectory, JavaDesignerOutputDirectory); Directory.CreateDirectory(designerDirectory); cmd.Add("--java"); cmd.Add(GetFullPath(JavaDesignerOutputDirectory)); } if (PackageName != null) { cmd.Add("--custom-package"); cmd.Add(PackageName.ToLowerInvariant()); } if (AdditionalResourceArchives != null) { for (int i = AdditionalResourceArchives.Length - 1; i >= 0; i--) { var flata = GetFullPath(AdditionalResourceArchives [i].ItemSpec); if (Directory.Exists(flata)) { foreach (var line in Directory.EnumerateFiles(flata, "*.flat", SearchOption.TopDirectoryOnly)) { cmd.Add("-R"); cmd.Add(GetFullPath(line)); } } else if (File.Exists(flata)) { cmd.Add("-R"); cmd.Add(flata); } else { LogDebugMessage($"Archive does not exist: {flata}"); } } } if (CompiledResourceFlatArchive != null) { var flata = GetFullPath(CompiledResourceFlatArchive.ItemSpec); if (Directory.Exists(flata)) { foreach (var line in Directory.EnumerateFiles(flata, "*.flat", SearchOption.TopDirectoryOnly)) { cmd.Add("-R"); cmd.Add(GetFullPath(line)); } } else if (File.Exists(flata)) { cmd.Add("-R"); cmd.Add(flata); } else { LogDebugMessage($"Archive does not exist: {flata}"); } } if (CompiledResourceFlatFiles != null) { var appFiles = new List <string> (); for (int i = CompiledResourceFlatFiles.Length - 1; i >= 0; i--) { var file = CompiledResourceFlatFiles [i]; var fullPath = GetFullPath(file.ItemSpec); if (!File.Exists(fullPath)) { LogDebugMessage($"File does not exist: {fullPath}"); } else if (!string.IsNullOrEmpty(file.GetMetadata("ResourceDirectory"))) { cmd.Add("-R"); cmd.Add(fullPath); } else { appFiles.Add(fullPath); } } foreach (var fullPath in appFiles) { cmd.Add("-R"); cmd.Add(fullPath); } } cmd.Add("--auto-add-overlay"); if (!string.IsNullOrWhiteSpace(UncompressedFileExtensions)) { foreach (var ext in UncompressedFileExtensions.Split(new char [] { ';', ',' }, StringSplitOptions.RemoveEmptyEntries)) { cmd.Add("-0"); cmd.Add(ext.StartsWith(".", StringComparison.OrdinalIgnoreCase) ? ext : $".{ext}"); } } if (!string.IsNullOrEmpty(ExtraPackages)) { cmd.Add("--extra-packages"); cmd.Add(ExtraPackages); } cmd.Add("-I"); cmd.Add(GetFullPath(JavaPlatformJarPath)); if (!string.IsNullOrEmpty(ResourceSymbolsTextFile)) { cmd.Add("--output-text-symbols"); cmd.Add(GetFullPath(ResourceSymbolsTextFile)); } if (ProtobufFormat) { cmd.Add("--proto-format"); } if (!string.IsNullOrWhiteSpace(ExtraArgs)) { foreach (Match match in exraArgSplitRegEx.Matches(ExtraArgs)) { string value = match.Value.Trim(' ', '"', '\''); if (!string.IsNullOrEmpty(value)) { cmd.Add(value); } } } // When adding Assets the first item found takes precedence. // So we need to add the applicaiton Assets first. if (!string.IsNullOrEmpty(AssetsDirectory)) { var assetDir = GetFullPath(AssetsDirectory.TrimEnd('\\')); if (Directory.Exists(assetDir)) { cmd.Add("-A"); cmd.Add(assetDir); } else { LogDebugMessage($"asset directory did not exist: {assetDir}"); } } if (AdditionalAndroidAssetPaths != null) { for (int i = 0; i < AdditionalAndroidAssetPaths.Length; i++) { var assetDir = GetFullPath(AdditionalAndroidAssetPaths [i].ItemSpec.TrimEnd('\\')); if (!string.IsNullOrWhiteSpace(assetDir)) { if (Directory.Exists(assetDir)) { cmd.Add("-A"); cmd.Add(GetFullPath(assetDir)); } else { LogDebugMessage($"asset directory did not exist: {assetDir}"); } } } } if (!string.IsNullOrEmpty(ProguardRuleOutput)) { cmd.Add("--proguard"); cmd.Add(GetFullPath(proguardRuleOutputTemp)); } cmd.Add("-o"); cmd.Add(GetFullPath(currentResourceOutputFile)); return(cmd.ToArray()); }