Пример #1
0
        protected string GenerateCommandLineCommands(string ManifestFile, string currentAbi, string currentResourceOutputFile)
        {
            // For creating Resource.Designer.cs:
            //   Running command: C:\Program Files (x86)\Android\android-sdk-windows\platform-tools\aapt
            //     "package"
            //     "-M" "C:\Users\Jonathan\AppData\Local\Temp\ryob4gaw.way\AndroidManifest.xml"
            //     "-J" "C:\Users\Jonathan\AppData\Local\Temp\ryob4gaw.way"
            //     "-F" "C:\Users\Jonathan\AppData\Local\Temp\ryob4gaw.way\resources.apk"
            //     "-S" "c:\users\jonathan\documents\visual studio 2010\Projects\MonoAndroidApplication4\MonoAndroidApplication4\obj\Debug\res"
            //     "-I" "C:\Program Files (x86)\Android\android-sdk-windows\platforms\android-8\android.jar"
            //     "--max-res-version" "10"

            // For packaging:
            //   Running command: C:\Program Files (x86)\Android\android-sdk-windows\platform-tools\aapt
            //     "package"
            //     "-f"
            //     "-m"
            //     "-M" "AndroidManifest.xml"
            //     "-J" "src"
            //     "--custom-package" "androidmsbuildtest.androidmsbuildtest"
            //     "-F" "bin\packaged_resources"
            //     "-S" "C:\Users\Jonathan\Documents\Visual Studio 2010\Projects\AndroidMSBuildTest\AndroidMSBuildTest\obj\Debug\res"
            //     "-I" "C:\Program Files (x86)\Android\android-sdk-windows\platforms\android-8\android.jar"
            //     "--extra-packages" "com.facebook.android:my.another.library"

            var cmd = new CommandLineBuilder();

            cmd.AppendSwitch("package");

            if (MonoAndroidHelper.LogInternalExceptions)
            {
                cmd.AppendSwitch("-v");
            }
            if (NonConstantId)
            {
                cmd.AppendSwitch("--non-constant-id");
            }
            cmd.AppendSwitch("-f");
            cmd.AppendSwitch("-m");
            string manifestFile;
            string manifestDir = Path.Combine(Path.GetDirectoryName(ManifestFile), currentAbi != null ? currentAbi : "manifest");

            Directory.CreateDirectory(manifestDir);
            manifestFile = Path.Combine(manifestDir, Path.GetFileName(ManifestFile));
            ManifestDocument manifest = new ManifestDocument(ManifestFile, this.Log);

            if (currentAbi != null)
            {
                manifest.SetAbi(currentAbi);
            }
            manifest.ApplicationName = ApplicationName;
            manifest.Save(manifestFile);

            cmd.AppendSwitchIfNotNull("-M ", manifestFile);
            Directory.CreateDirectory(JavaDesignerOutputDirectory);
            cmd.AppendSwitchIfNotNull("-J ", JavaDesignerOutputDirectory);

            if (PackageName != null)
            {
                cmd.AppendSwitchIfNotNull("--custom-package ", PackageName.ToLowerInvariant());
            }

            if (!string.IsNullOrEmpty(currentResourceOutputFile))
            {
                cmd.AppendSwitchIfNotNull("-F ", currentResourceOutputFile + ".bk");
            }
            // The order of -S arguments is *important*, always make sure this one comes FIRST
            cmd.AppendSwitchIfNotNull("-S ", ResourceDirectory.TrimEnd('\\'));
            if (AdditionalResourceDirectories != null)
            {
                foreach (var resdir in AdditionalResourceDirectories)
                {
                    cmd.AppendSwitchIfNotNull("-S ", resdir.ItemSpec.TrimEnd('\\'));
                }
            }
            if (AdditionalAndroidResourcePaths != null)
            {
                foreach (var dir in AdditionalAndroidResourcePaths)
                {
                    cmd.AppendSwitchIfNotNull("-S ", Path.Combine(dir.ItemSpec.TrimEnd(System.IO.Path.DirectorySeparatorChar), "res"));
                }
            }

            if (LibraryProjectJars != null)
            {
                foreach (var jar in LibraryProjectJars)
                {
                    cmd.AppendSwitchIfNotNull("-j ", jar);
                }
            }

            cmd.AppendSwitchIfNotNull("-I ", JavaPlatformJarPath);

            // Add asset directory if it exists
            if (!string.IsNullOrWhiteSpace(AssetDirectory) && Directory.Exists(AssetDirectory))
            {
                cmd.AppendSwitchIfNotNull("-A ", AssetDirectory.TrimEnd('\\'));
            }

            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);
            }

            // TODO: handle resource names
            if (ExplicitCrunch)
            {
                cmd.AppendSwitch("--no-crunch");
            }

            cmd.AppendSwitch("--auto-add-overlay");

            var extraArgsExpanded = ExpandString(ExtraArgs);

            if (extraArgsExpanded != ExtraArgs)
            {
                Log.LogDebugMessage("  ExtraArgs expanded: {0}", extraArgsExpanded);
            }

            if (!string.IsNullOrWhiteSpace(extraArgsExpanded))
            {
                cmd.AppendSwitch(extraArgsExpanded);
            }

            if (!AndroidUseLatestPlatformSdk)
            {
                cmd.AppendSwitchIfNotNull("--max-res-version ", ApiLevel);
            }

            return(cmd.ToString());
        }
Пример #2
0
        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());
        }
Пример #3
0
        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());
        }
Пример #4
0
        protected string GenerateCommandLineCommands(string ManifestFile, string currentAbi, string currentResourceOutputFile)
        {
            // For creating Resource.designer.cs:
            //   Running command: C:\Program Files (x86)\Android\android-sdk-windows\platform-tools\aapt
            //     "package"
            //     "-M" "C:\Users\Jonathan\AppData\Local\Temp\ryob4gaw.way\AndroidManifest.xml"
            //     "-J" "C:\Users\Jonathan\AppData\Local\Temp\ryob4gaw.way"
            //     "-F" "C:\Users\Jonathan\AppData\Local\Temp\ryob4gaw.way\resources.apk"
            //     "-S" "c:\users\jonathan\documents\visual studio 2010\Projects\MonoAndroidApplication4\MonoAndroidApplication4\obj\Debug\res"
            //     "-I" "C:\Program Files (x86)\Android\android-sdk-windows\platforms\android-8\android.jar"
            //     "--max-res-version" "10"

            // For packaging:
            //   Running command: C:\Program Files (x86)\Android\android-sdk-windows\platform-tools\aapt
            //     "package"
            //     "-f"
            //     "-m"
            //     "-M" "AndroidManifest.xml"
            //     "-J" "src"
            //     "--custom-package" "androidmsbuildtest.androidmsbuildtest"
            //     "-F" "bin\packaged_resources"
            //     "-S" "C:\Users\Jonathan\Documents\Visual Studio 2010\Projects\AndroidMSBuildTest\AndroidMSBuildTest\obj\Debug\res"
            //     "-I" "C:\Program Files (x86)\Android\android-sdk-windows\platforms\android-8\android.jar"
            //     "--extra-packages" "com.facebook.android:my.another.library"

            var cmd = new CommandLineBuilder();

            cmd.AppendSwitch("package");

            if (MonoAndroidHelper.LogInternalExceptions)
            {
                cmd.AppendSwitch("-v");
            }
            if (NonConstantId)
            {
                cmd.AppendSwitch("--non-constant-id");
            }
            cmd.AppendSwitch("-f");
            cmd.AppendSwitch("-m");
            string manifestFile;
            string manifestDir = Path.Combine(Path.GetDirectoryName(ManifestFile), currentAbi != null ? currentAbi : "manifest");

            Directory.CreateDirectory(manifestDir);
            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(string.Empty);
                }
            }
            if (currentAbi != null && string.IsNullOrEmpty(VersionCodePattern))
            {
                manifest.SetAbi(currentAbi);
            }
            if (!manifest.ValidateVersionCode(out string error, out string errorCode))
            {
                LogCodedError(errorCode, ManifestFile, 0, error);
                return(string.Empty);
            }
            manifest.ApplicationName = ApplicationName;
            manifest.Save(LogCodedWarning, manifestFile);

            cmd.AppendSwitchIfNotNull("-M ", manifestFile);
            var designerDirectory = Path.IsPathRooted(JavaDesignerOutputDirectory) ? JavaDesignerOutputDirectory : Path.Combine(WorkingDirectory, JavaDesignerOutputDirectory);

            Directory.CreateDirectory(designerDirectory);
            cmd.AppendSwitchIfNotNull("-J ", JavaDesignerOutputDirectory);

            if (PackageName != null)
            {
                cmd.AppendSwitchIfNotNull("--custom-package ", PackageName.ToLowerInvariant());
            }

            if (!string.IsNullOrEmpty(currentResourceOutputFile))
            {
                cmd.AppendSwitchIfNotNull("-F ", currentResourceOutputFile + ".bk");
            }
            // The order of -S arguments is *important*, always make sure this one comes FIRST
            cmd.AppendSwitchIfNotNull("-S ", resourceDirectory.TrimEnd('\\'));
            if (AdditionalResourceDirectories != null)
            {
                foreach (var dir in AdditionalResourceDirectories)
                {
                    var resdir = dir.ItemSpec.TrimEnd('\\');
                    if (Directory.Exists(resdir))
                    {
                        cmd.AppendSwitchIfNotNull("-S ", resdir);
                    }
                }
            }
            if (AdditionalAndroidResourcePaths != null)
            {
                foreach (var dir in AdditionalAndroidResourcePaths)
                {
                    var resdir = Path.Combine(dir.ItemSpec, "res");
                    if (Directory.Exists(resdir))
                    {
                        cmd.AppendSwitchIfNotNull("-S ", resdir);
                    }
                }
            }

            if (LibraryProjectJars != null)
            {
                foreach (var jar in LibraryProjectJars)
                {
                    cmd.AppendSwitchIfNotNull("-j ", jar);
                }
            }

            cmd.AppendSwitchIfNotNull("-I ", JavaPlatformJarPath);

            // Add asset directory if it exists
            if (!string.IsNullOrWhiteSpace(AssetDirectory))
            {
                var assetDir = AssetDirectory.TrimEnd('\\');
                if (!Path.IsPathRooted(assetDir))
                {
                    assetDir = Path.Combine(WorkingDirectory, assetDir);
                }
                if (!string.IsNullOrWhiteSpace(assetDir) && Directory.Exists(assetDir))
                {
                    cmd.AppendSwitchIfNotNull("-A ", assetDir);
                }
            }
            if (!string.IsNullOrWhiteSpace(UncompressedFileExtensions))
            {
                foreach (var ext in UncompressedFileExtensions.Split(new char[] { ';', ',' }, StringSplitOptions.RemoveEmptyEntries))
                {
                    cmd.AppendSwitchIfNotNull("-0 ", ext.StartsWith(".", StringComparison.OrdinalIgnoreCase) ? ext : $".{ext}");
                }
            }

            if (!string.IsNullOrEmpty(ExtraPackages))
            {
                cmd.AppendSwitchIfNotNull("--extra-packages ", ExtraPackages);
            }

            cmd.AppendSwitch("--auto-add-overlay");

            if (!string.IsNullOrEmpty(ResourceSymbolsTextFileDirectory))
            {
                cmd.AppendSwitchIfNotNull("--output-text-symbols ", ResourceSymbolsTextFileDirectory);
            }

            var extraArgsExpanded = ExpandString(ExtraArgs);

            if (extraArgsExpanded != ExtraArgs)
            {
                LogDebugMessage("  ExtraArgs expanded: {0}", extraArgsExpanded);
            }

            if (!string.IsNullOrWhiteSpace(extraArgsExpanded))
            {
                cmd.AppendSwitch(extraArgsExpanded);
            }

            if (!AndroidUseLatestPlatformSdk)
            {
                cmd.AppendSwitchIfNotNull("--max-res-version ", ApiLevel);
            }

            return(cmd.ToString());
        }