public override bool Execute()
        {
            Log.LogDebugMessage("EmbeddedNativeLibraries Task");
            Log.LogDebugMessage("  OutputDirectory: {0}", OutputDirectory);
            Log.LogDebugTaskItems("  EmbeddedNativeLibraries:", EmbeddedNativeLibraries);

            var outDirInfo = new DirectoryInfo(OutputDirectory);

            // Copy files into _NativeLibraryImportsDirectoryName (native_library_imports) dir.
            if (!outDirInfo.Exists)
            {
                outDirInfo.Create();
            }
            foreach (var lib in EmbeddedNativeLibraries)
            {
                // seealso bug #3477 to find out why we use this method.
                var abi = MonoAndroidHelper.GetNativeLibraryAbi(lib);
                if (abi == null)
                {
                    Log.LogWarning(
                        subcategory:      string.Empty,
                        warningCode:      "XA4300",
                        helpKeyword:      string.Empty,
                        file:             lib.ItemSpec,
                        lineNumber:       0,
                        columnNumber:     0,
                        endLineNumber:    0,
                        endColumnNumber:  0,
                        message:          "Native library '{0}' will not be bundled because it has an unsupported ABI.",
                        messageArgs:      new [] {
                        lib.ItemSpec,
                    }
                        );
                    continue;
                }
                if (!outDirInfo.GetDirectories(abi).Any())
                {
                    outDirInfo.CreateSubdirectory(abi);
                }
                MonoAndroidHelper.CopyIfChanged(lib.ItemSpec, Path.Combine(OutputDirectory, abi, Path.GetFileName(lib.ItemSpec)));
            }

            var outpath = Path.Combine(outDirInfo.Parent.FullName, "__AndroidNativeLibraries__.zip");

            if (Files.ArchiveZip(outpath, f => {
                using (var zip = new ZipArchiveEx(f)) {
                    zip.AddDirectory(OutputDirectory, outDirInfo.Name);
                }
            }))
            {
                Log.LogDebugMessage("Saving contents to " + outpath);
            }

            return(true);
        }
Example #2
0
        public override bool RunTask()
        {
            var outDirInfo = new DirectoryInfo(OutputDirectory);

            // Copy files into _NativeLibraryImportsDirectoryName (native_library_imports) dir.
            if (!outDirInfo.Exists)
            {
                outDirInfo.Create();
            }
            foreach (var lib in EmbeddedNativeLibraries)
            {
                // seealso bug #3477 to find out why we use this method.
                var abi = MonoAndroidHelper.GetNativeLibraryAbi(lib);
                if (abi == null)
                {
                    Log.LogWarning(
                        subcategory:      string.Empty,
                        warningCode:      "XA4300",
                        helpKeyword:      string.Empty,
                        file:             lib.ItemSpec,
                        lineNumber:       0,
                        columnNumber:     0,
                        endLineNumber:    0,
                        endColumnNumber:  0,
                        message:          Properties.Resources.XA4300,
                        messageArgs:      new [] {
                        lib.ItemSpec,
                    }
                        );
                    continue;
                }
                if (!outDirInfo.GetDirectories(abi).Any())
                {
                    outDirInfo.CreateSubdirectory(abi);
                }
                MonoAndroidHelper.CopyIfChanged(lib.ItemSpec, Path.Combine(OutputDirectory, abi, Path.GetFileName(lib.ItemSpec)));
            }

            var outpath = Path.Combine(outDirInfo.Parent.FullName, "__AndroidNativeLibraries__.zip");

            if (Files.ArchiveZip(outpath, f => {
                using (var zip = new ZipArchiveEx(f)) {
                    zip.AddDirectory(OutputDirectory, "native_library_imports");
                }
            }))
            {
                Log.LogDebugMessage("Saving contents to " + outpath);
            }

            return(!Log.HasLoggedErrors);
        }
Example #3
0
        public override bool Execute()
        {
            if (!Directory.Exists(ClassesOutputDirectory))
            {
                Directory.CreateDirectory(ClassesOutputDirectory);
            }
            var result = base.Execute();

            if (!result)
            {
                return(result);
            }
            // compress all the class files
            using (var zip = new ZipArchiveEx(Path.Combine(ClassesOutputDirectory, "..", "classes.zip"), FileMode.OpenOrCreate))
                zip.AddDirectory(ClassesOutputDirectory, "", CompressionMethod.Store);
            return(result);
        }
Example #4
0
        public override bool RunTask()
        {
            if (!Directory.Exists(ClassesOutputDirectory))
            {
                Directory.CreateDirectory(ClassesOutputDirectory);
            }
            var result = base.RunTask();

            if (!result)
            {
                return(result);
            }
            // compress all the class files
            if (!string.IsNullOrEmpty(ClassesZip))
            {
                using (var zip = new ZipArchiveEx(ClassesZip, FileMode.OpenOrCreate)) {
                    zip.AddDirectory(ClassesOutputDirectory, "", CompressionMethod.Store);
                }
            }
            return(result);
        }
Example #5
0
        public override bool RunTask()
        {
            var outDirInfo = new DirectoryInfo(OutputDirectory);

            // Copy files into _LibraryProjectImportsDirectoryName (library_project_imports) dir.
            if (!outDirInfo.Exists)
            {
                outDirInfo.Create();
            }
            foreach (var sub in new string [] { "assets", "res", "java", "bin" })
            {
                var subdirInfo = new DirectoryInfo(Path.Combine(outDirInfo.FullName, sub));
                if (!subdirInfo.Exists)
                {
                    subdirInfo.Create();
                }
            }

            var compiledArchive = Path.Combine(FlatArchivesDirectory, "compiled.flata");

            if (File.Exists(compiledArchive))
            {
                Log.LogDebugMessage($"Coping: {compiledArchive} to {outDirInfo.FullName}");
                MonoAndroidHelper.CopyIfChanged(compiledArchive, Path.Combine(outDirInfo.FullName, "compiled.flata"));
            }

            var dir_sep = new char [] { Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar };

            if (AndroidAssets != null)
            {
                var dstsub = Path.Combine(outDirInfo.FullName, "assets");
                if (!Directory.Exists(dstsub))
                {
                    Directory.CreateDirectory(dstsub);
                }
                foreach (var item in AndroidAssets)
                {
                    var path = item.GetMetadata("Link");
                    path = !string.IsNullOrWhiteSpace(path) ? path : item.ItemSpec;
                    var head = string.Join("\\", path.Split(dir_sep).TakeWhile(s => !s.Equals(MonoAndroidAssetsPrefix, StringComparison.OrdinalIgnoreCase)));
                    path = head.Length == path.Length ? path : path.Substring((head.Length == 0 ? 0 : head.Length + Path.DirectorySeparatorChar) + MonoAndroidAssetsPrefix.Length).TrimStart(dir_sep);
                    MonoAndroidHelper.CopyIfChanged(item.ItemSpec, Path.Combine(dstsub, path));
                }
            }
            // resources folders are converted to the structure that aapt accepts.
            foreach (var srcsub in Directory.GetDirectories(ResourceDirectory))
            {
                var dstsub = Path.Combine(outDirInfo.FullName, "res", Path.GetFileName(srcsub));
                if (!Directory.Exists(dstsub))
                {
                    Directory.CreateDirectory(dstsub);
                }
                foreach (var file in Directory.GetFiles(srcsub))
                {
                    var filename = Path.GetFileName(file);
                    MonoAndroidHelper.CopyIfChanged(file, Path.Combine(dstsub, Path.GetFileName(file)));
                }
            }
            if (RemovedAndroidResourceFiles != null)
            {
                foreach (var removedFile in RemovedAndroidResourceFiles)
                {
                    var removed = Path.Combine(outDirInfo.FullName, removedFile.ItemSpec);
                    if (File.Exists(removed))
                    {
                        File.Delete(removed);
                        Log.LogDebugMessage($"Removed: {removed}");
                    }
                }
            }
            if (AndroidJavaSources != null)
            {
                foreach (var item in AndroidJavaSources)
                {
                    MonoAndroidHelper.CopyIfChanged(item.ItemSpec, Path.Combine(outDirInfo.FullName, item.ItemSpec));
                }
            }
            if (AndroidJavaLibraries != null)
            {
                foreach (var item in AndroidJavaLibraries)
                {
                    MonoAndroidHelper.CopyIfChanged(item.ItemSpec, Path.Combine(outDirInfo.FullName, item.ItemSpec));
                }
            }

            var nameCaseMap = new StringWriter();

            // add resource case mapping descriptor to the archive.
            if (AndroidResourcesInThisExactProject != null && AndroidResourcesInThisExactProject.Any())
            {
                Log.LogMessage("writing __res_name_case_map.txt...");
                foreach (var res in AndroidResourcesInThisExactProject)
                {
                    nameCaseMap.WriteLine("{0};{1}", res.GetMetadata("LogicalName").Replace('\\', '/'), Path.Combine(Path.GetFileName(Path.GetDirectoryName(res.ItemSpec)), Path.GetFileName(res.ItemSpec)).Replace('\\', '/'));
                }
                File.WriteAllText(Path.Combine(outDirInfo.FullName, "__res_name_case_map.txt"), nameCaseMap.ToString());
            }

            var outpath  = Path.Combine(outDirInfo.Parent.FullName, "__AndroidLibraryProjects__.zip");
            var fileMode = File.Exists(outpath) ? FileMode.Open : FileMode.CreateNew;

            if (Files.ArchiveZipUpdate(outpath, f => {
                using (var zip = new ZipArchiveEx(f, fileMode)) {
                    zip.AddDirectory(outDirInfo.FullName, "library_project_imports");
                    if (RemovedAndroidResourceFiles != null)
                    {
                        foreach (var r in RemovedAndroidResourceFiles)
                        {
                            Log.LogDebugMessage($"Removed {r.ItemSpec} from {outpath}");
                            zip.RemoveFile("library_project_imports", r.ItemSpec);
                        }
                    }
                }
            }))
            {
                Log.LogDebugMessage("Saving contents to " + outpath);
            }

            return(!Log.HasLoggedErrors);
        }
Example #6
0
        public override bool Execute()
        {
            if (IsApplication)
            {
                return(true);
            }

            Log.LogDebugMessage("CreateManagedLibraryResourceArchive Task");
            Log.LogDebugMessage("  OutputDirectory: {0}", OutputDirectory);
            Log.LogDebugMessage("  ResourceDirectory: {0}", ResourceDirectory);
            Log.LogDebugTaskItems("  AndroidAssets:", AndroidAssets);
            Log.LogDebugTaskItems("  AndroidJavaSources:", AndroidJavaSources);
            Log.LogDebugTaskItems("  AndroidJavaLibraries:", AndroidJavaLibraries);

            var outDirInfo = new DirectoryInfo(OutputDirectory);

            // Copy files into _LibraryProjectImportsDirectoryName (library_project_imports) dir.
            if (!outDirInfo.Exists)
            {
                outDirInfo.Create();
            }
            foreach (var sub in new string [] { "assets", "res", "java", "bin" })
            {
                var subdirInfo = new DirectoryInfo(Path.Combine(outDirInfo.FullName, sub));
                if (!subdirInfo.Exists)
                {
                    subdirInfo.Create();
                }
            }

            var dir_sep = new char [] { Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar };

            if (AndroidAssets != null)
            {
                var dstsub = Path.Combine(outDirInfo.FullName, "assets");
                if (!Directory.Exists(dstsub))
                {
                    Directory.CreateDirectory(dstsub);
                }
                foreach (var item in AndroidAssets)
                {
                    var path = item.GetMetadata("Link");
                    path = !string.IsNullOrWhiteSpace(path) ? path : item.ItemSpec;
                    var head = string.Join("\\", path.Split(dir_sep).TakeWhile(s => !s.Equals(MonoAndroidAssetsPrefix, StringComparison.OrdinalIgnoreCase)));
                    path = head.Length == path.Length ? path : path.Substring((head.Length == 0 ? 0 : head.Length + Path.DirectorySeparatorChar) + MonoAndroidAssetsPrefix.Length).TrimStart(dir_sep);
                    MonoAndroidHelper.CopyIfChanged(item.ItemSpec, Path.Combine(dstsub, path));
                }
            }
            // resources folders are converted to the structure that aapt accepts.
            bool hasInvalidName = false;

            foreach (var srcsub in Directory.GetDirectories(ResourceDirectory))
            {
                var dstsub = Path.Combine(outDirInfo.FullName, "res", Path.GetFileName(srcsub));
                if (!Directory.Exists(dstsub))
                {
                    Directory.CreateDirectory(dstsub);
                }
                foreach (var file in Directory.GetFiles(srcsub))
                {
                    var filename = Path.GetFileName(file);
                    MonoAndroidHelper.CopyIfChanged(file, Path.Combine(dstsub, Path.GetFileName(file)));
                }
            }
            if (hasInvalidName)
            {
                return(false);
            }
            if (AndroidJavaSources != null)
            {
                foreach (var item in AndroidJavaSources)
                {
                    MonoAndroidHelper.CopyIfChanged(item.ItemSpec, Path.Combine(outDirInfo.FullName, item.ItemSpec));
                }
            }
            if (AndroidJavaLibraries != null)
            {
                foreach (var item in AndroidJavaLibraries)
                {
                    MonoAndroidHelper.CopyIfChanged(item.ItemSpec, Path.Combine(outDirInfo.FullName, item.ItemSpec));
                }
            }

            var nameCaseMap = new StringWriter();

            // add resource case mapping descriptor to the archive.
            if (AndroidResourcesInThisExactProject != null && AndroidResourcesInThisExactProject.Any())
            {
                Log.LogMessage("writing __res_name_case_map.txt...");
                foreach (var res in AndroidResourcesInThisExactProject)
                {
                    nameCaseMap.WriteLine("{0};{1}", res.GetMetadata("LogicalName").Replace('\\', '/'), Path.Combine(Path.GetFileName(Path.GetDirectoryName(res.ItemSpec)), Path.GetFileName(res.ItemSpec)).Replace('\\', '/'));
                }
                File.WriteAllText(Path.Combine(OutputDirectory, "__res_name_case_map.txt"), nameCaseMap.ToString());
            }

            var outpath = Path.Combine(outDirInfo.Parent.FullName, "__AndroidLibraryProjects__.zip");

            if (Files.ArchiveZip(outpath, f => {
                using (var zip = new ZipArchiveEx(f)) {
                    zip.AddDirectory(OutputDirectory, outDirInfo.Name);
                }
            }))
            {
                Log.LogDebugMessage("Saving contents to " + outpath);
            }

            return(true);
        }
Example #7
0
        public override bool RunTask()
        {
            if (LibraryProjectPropertiesFiles.Length == 0 && LibraryProjectZipFiles.Length == 0)
            {
                return(true);
            }

            var outDirInfo = new DirectoryInfo(OutputDirectory);

            // Copy files into _LibraryProjectImportsDirectoryName (library_project_imports) dir.
            if (!outDirInfo.Exists)
            {
                outDirInfo.Create();
            }

            var projectsResolved = ResolveLibraryProjectReferences(LibraryProjectPropertiesFiles.Select(p => Path.GetFullPath(p.ItemSpec)));
            var imports          = projectsResolved.Concat(LibraryProjectZipFiles.Select(p => p.ItemSpec));

            foreach (var p in imports)
            {
                // note that imports could contain file name that neither of build items contains
                // (it may be one of those resolved references in project.properties).
                // Also non-zip files are now specified in full path.
                if (!LibraryProjectZipFiles.Any(l => l.ItemSpec == p))
                {
                    // project.properties

                    var fileInfo = new FileInfo(p);
                    if (!fileInfo.Exists)
                    {
                        throw new InvalidOperationException(String.Format("Library project properties file '{0}' does not exist.", p));
                    }
                    var bindir = fileInfo.Directory.FullName;

                    CopyLibraryContent(bindir, false);
                }
                else
                {
                    // zip
                    string tmpname = Path.Combine(Path.GetTempPath(), "monodroid_import_" + Guid.NewGuid().ToString());
                    try {
                        Directory.CreateDirectory(tmpname);
                        var archive = ZipArchive.Open(p, FileMode.Open);
                        archive.ExtractAll(tmpname);

                        if (!CopyLibraryContent(tmpname, p.EndsWith(".aar", StringComparison.OrdinalIgnoreCase)))
                        {
                            return(false);
                        }
                    } finally {
                        Directory.Delete(tmpname, true);
                    }
                }
            }

            var outpath = Path.Combine(outDirInfo.Parent.FullName, "__AndroidLibraryProjects__.zip");

            if (Files.ArchiveZip(outpath, f => {
                using (var zip = new ZipArchiveEx(f)) {
                    zip.AddDirectory(OutputDirectory, "library_project_imports");
                }
            }))
            {
                Log.LogDebugMessage("Saving contents to " + outpath);
            }
            return(true);
        }