protected override string GenerateCommandLineCommands() { var cmd = new CommandLineBuilder(); if (!UseProguard) { // Add the JavaOptions if they are not null // These could be any of the additional options if (!string.IsNullOrEmpty(JavaOptions)) { cmd.AppendSwitch(JavaOptions); } // Add the specific -XmxN to override the default heap size for the JVM // N can be in the form of Nm or NGB (e.g 100m or 1GB ) cmd.AppendSwitchIfNotNull("-Xmx", JavaMaximumHeapSize); cmd.AppendSwitchIfNotNull("-jar ", Path.Combine(ProguardJarPath)); } if (!ClassesOutputDirectory.EndsWith(Path.DirectorySeparatorChar.ToString(), StringComparison.OrdinalIgnoreCase)) { ClassesOutputDirectory += Path.DirectorySeparatorChar; } var classesZip = Path.Combine(ClassesOutputDirectory, "classes.zip"); var acwLines = File.ReadAllLines(AcwMapFile); using (var appcfg = File.CreateText(ProguardGeneratedApplicationConfiguration)) for (int i = 0; i + 3 < acwLines.Length; i += 4) { try { var java = acwLines [i + 3].Substring(acwLines [i + 3].IndexOf(';') + 1); appcfg.WriteLine("-keep class " + java + " { *; }"); } catch { // skip invalid lines } } var injars = new List <string> (); var libjars = new List <string> (); injars.Add(classesZip); if (JavaLibrariesToEmbed != null) { foreach (var jarfile in JavaLibrariesToEmbed) { injars.Add(jarfile.ItemSpec); } } using (var xamcfg = File.Create(ProguardCommonXamarinConfiguration)) GetType().Assembly.GetManifestResourceStream("proguard_xamarin.cfg").CopyTo(xamcfg); var configs = ProguardConfigurationFiles .Replace("{sdk.dir}", AndroidSdkDirectory + Path.DirectorySeparatorChar) .Replace("{intermediate.common.xamarin}", ProguardCommonXamarinConfiguration) .Replace("{intermediate.references}", ProguardGeneratedReferenceConfiguration) .Replace("{intermediate.application}", ProguardGeneratedApplicationConfiguration) .Replace("{project}", string.Empty) // current directory anyways. .Split(';') .Select(s => s.Trim()) .Where(s => !string.IsNullOrWhiteSpace(s)); var enclosingChar = OS.IsWindows ? "\"" : string.Empty; foreach (var file in configs) { if (File.Exists(file)) { cmd.AppendSwitchUnquotedIfNotNull("-include ", $"{enclosingChar}'{file}'{enclosingChar}"); } else { Log.LogWarning("Proguard configuration file '{0}' was not found.", file); } } libjars.Add(JavaPlatformJarPath); if (ExternalJavaLibraries != null) { foreach (var jarfile in ExternalJavaLibraries.Select(p => p.ItemSpec)) { libjars.Add(jarfile); } } cmd.AppendSwitchUnquotedIfNotNull("-injars ", $"{enclosingChar}'" + string.Join($"'{Path.PathSeparator}'", injars.Distinct()) + $"'{enclosingChar}"); cmd.AppendSwitchUnquotedIfNotNull("-libraryjars ", $"{enclosingChar}'" + string.Join($"'{Path.PathSeparator}'", libjars.Distinct()) + $"'{enclosingChar}"); cmd.AppendSwitchIfNotNull("-outjars ", ProguardJarOutput); if (EnableLogging) { cmd.AppendSwitchIfNotNull("-dump ", DumpOutput); cmd.AppendSwitchIfNotNull("-printseeds ", PrintSeedsOutput); cmd.AppendSwitchIfNotNull("-printusage ", PrintUsageOutput); cmd.AppendSwitchIfNotNull("-printmapping ", PrintMappingOutput); } // http://stackoverflow.com/questions/5701126/compile-with-proguard-gives-exception-local-variable-type-mismatch#7587680 cmd.AppendSwitch("-optimizations !code/allocation/variable"); return(cmd.ToString()); }
protected override string GenerateCommandLineCommands() { var cmd = new CommandLineBuilder(); if (!UseProguard) { // Add the JavaOptions if they are not null // These could be any of the additional options if (!string.IsNullOrEmpty(JavaOptions)) { cmd.AppendSwitch(JavaOptions); } // Add the specific -XmxN to override the default heap size for the JVM // N can be in the form of Nm or NGB (e.g 100m or 1GB ) cmd.AppendSwitchIfNotNull("-Xmx", JavaMaximumHeapSize); cmd.AppendSwitchIfNotNull("-jar ", Path.Combine(ProguardJarPath)); } if (!ClassesOutputDirectory.EndsWith(Path.DirectorySeparatorChar.ToString(), StringComparison.OrdinalIgnoreCase)) { ClassesOutputDirectory += Path.DirectorySeparatorChar; } var classesZip = Path.Combine(ClassesOutputDirectory, "..", "classes.zip"); var acwLines = File.ReadAllLines(AcwMapFile); using (var appcfg = File.CreateText(ProguardGeneratedApplicationConfiguration)) for (int i = 0; i + 2 < acwLines.Length; i += 3) { try { var line = acwLines [i + 2]; var java = line.Substring(line.IndexOf(';') + 1); appcfg.WriteLine("-keep class " + java + " { *; }"); } catch { // skip invalid lines } } if (!string.IsNullOrWhiteSpace(ProguardCommonXamarinConfiguration)) { using (var xamcfg = File.CreateText(ProguardCommonXamarinConfiguration)) { GetType().Assembly.GetManifestResourceStream("proguard_xamarin.cfg").CopyTo(xamcfg.BaseStream); if (!string.IsNullOrEmpty(ProguardMappingFileOutput)) { xamcfg.WriteLine("-keepattributes SourceFile"); xamcfg.WriteLine("-keepattributes LineNumberTable"); xamcfg.WriteLine($"-printmapping {Path.GetFullPath (ProguardMappingFileOutput)}"); } } } var enclosingChar = OS.IsWindows ? "\"" : string.Empty; foreach (var file in ProguardConfigurationFiles) { if (File.Exists(file)) { cmd.AppendSwitchUnquotedIfNotNull("-include ", $"{enclosingChar}'{file}'{enclosingChar}"); } else { Log.LogCodedWarning("XA4304", file, 0, Properties.Resources.XA4304, file); } } var injars = new List <string> (); var libjars = new List <string> (); injars.Add(classesZip); if (JavaLibrariesToEmbed != null) { foreach (var jarfile in JavaLibrariesToEmbed) { injars.Add(jarfile.ItemSpec); } } libjars.Add(JavaPlatformJarPath); if (JavaLibrariesToReference != null) { foreach (var jarfile in JavaLibrariesToReference.Select(p => p.ItemSpec)) { libjars.Add(jarfile); } } cmd.AppendSwitchUnquotedIfNotNull("-injars ", "\"'" + string.Join($"'{ProguardInputJarFilter}{Path.PathSeparator}'", injars.Distinct()) + $"'{ProguardInputJarFilter}\""); cmd.AppendSwitchUnquotedIfNotNull("-libraryjars ", $"{enclosingChar}'" + string.Join($"'{Path.PathSeparator}'", libjars.Distinct()) + $"'{enclosingChar}"); cmd.AppendSwitchIfNotNull("-outjars ", ProguardJarOutput); if (EnableLogging) { cmd.AppendSwitchIfNotNull("-dump ", DumpOutput); cmd.AppendSwitchIfNotNull("-printseeds ", PrintSeedsOutput); cmd.AppendSwitchIfNotNull("-printusage ", PrintUsageOutput); cmd.AppendSwitchIfNotNull("-printmapping ", PrintMappingOutput); } // http://stackoverflow.com/questions/5701126/compile-with-proguard-gives-exception-local-variable-type-mismatch#7587680 cmd.AppendSwitch("-optimizations !code/allocation/variable"); return(cmd.ToString()); }
public void TestAppendSwitchUnquotedIfNotNull9() { clb = new CommandLineBuilder(); clb.AppendSwitchUnquotedIfNotNull("/switch", items, null); }
public void TestAppendSwitchUnquotedIfNotNull8() { clb = new CommandLineBuilder(); clb.AppendSwitchUnquotedIfNotNull(null, items, "delimiter"); }
public void TestAppendSwitchUnquotedIfNotNull3() { clb = new CommandLineBuilder(); clb.AppendSwitchUnquotedIfNotNull(null, items [0]); }
public void TestAppendSwitchUnquotedIfNotNull1() { clb = new CommandLineBuilder(); clb.AppendSwitchUnquotedIfNotNull(null, "parameter"); }