public override bool RunTask() { Aot.TryGetSequencePointsMode(AndroidSequencePointsMode, out sequencePointsMode); var outputFiles = new List <string> (); uncompressedFileExtensions = UncompressedFileExtensions?.Split(new char [] { ';', ',' }, StringSplitOptions.RemoveEmptyEntries) ?? new string [0]; existingEntries.Clear(); bool debug = _Debug; bool compress = !debug && EnableCompression; IDictionary <string, CompressedAssemblyInfo> compressedAssembliesInfo = null; if (compress) { string key = CompressedAssemblyInfo.GetKey(ProjectFullPath); Log.LogDebugMessage($"Retrieving assembly compression info with key '{key}'"); compressedAssembliesInfo = BuildEngine4.UnregisterTaskObjectAssemblyLocal <IDictionary <string, CompressedAssemblyInfo> > (key, RegisteredTaskObjectLifetime.Build); if (compressedAssembliesInfo == null) { throw new InvalidOperationException($"Assembly compression info not found for key '{key}'. Compression will not be performed."); } } ExecuteWithAbi(SupportedAbis, ApkInputPath, ApkOutputPath, debug, compress, compressedAssembliesInfo); outputFiles.Add(ApkOutputPath); if (CreatePackagePerAbi && SupportedAbis.Length > 1) { foreach (var abi in SupportedAbis) { existingEntries.Clear(); var path = Path.GetDirectoryName(ApkOutputPath); var apk = Path.GetFileNameWithoutExtension(ApkOutputPath); ExecuteWithAbi(new [] { abi }, String.Format("{0}-{1}", ApkInputPath, abi), Path.Combine(path, String.Format("{0}-{1}.apk", apk, abi)), debug, compress, compressedAssembliesInfo); outputFiles.Add(Path.Combine(path, String.Format("{0}-{1}.apk", apk, abi))); } } OutputFiles = outputFiles.Select(a => new TaskItem(a)).ToArray(); Log.LogDebugTaskItems(" [Output] OutputFiles :", OutputFiles); return(!Log.HasLoggedErrors); }
void GenerateCompressedAssemblySources() { if (Debug || !EnableCompression) { Generate(null); return; } var assemblies = new SortedDictionary <string, CompressedAssemblyInfo> (StringComparer.Ordinal); foreach (ITaskItem assembly in ResolvedAssemblies) { if (bool.TryParse(assembly.GetMetadata("AndroidSkipAddToPackage"), out bool value) && value) { continue; } if (assemblies.ContainsKey(assembly.ItemSpec)) { continue; } var fi = new FileInfo(assembly.ItemSpec); if (!fi.Exists) { Log.LogError($"Assembly {assembly.ItemSpec} does not exist"); continue; } assemblies.Add(CompressedAssemblyInfo.GetDictionaryKey(assembly), new CompressedAssemblyInfo(checked ((uint)fi.Length))); } uint index = 0; foreach (var kvp in assemblies) { kvp.Value.DescriptorIndex = index++; } string key = CompressedAssemblyInfo.GetKey(ProjectFullPath); Log.LogDebugMessage($"Storing compression assemblies info with key '{key}'"); BuildEngine4.RegisterTaskObjectAssemblyLocal(key, assemblies, RegisteredTaskObjectLifetime.Build); Generate(assemblies); void Generate(IDictionary <string, CompressedAssemblyInfo> dict) { foreach (string abi in SupportedAbis) { NativeAssemblerTargetProvider asmTargetProvider = GeneratePackageManagerJava.GetAssemblyTargetProvider(abi); string baseAsmFilePath = Path.Combine(EnvironmentOutputDirectory, $"compressed_assemblies.{abi.ToLowerInvariant ()}"); string asmFilePath = $"{baseAsmFilePath}.s"; var asmgen = new CompressedAssembliesNativeAssemblyGenerator(dict, asmTargetProvider, baseAsmFilePath); using (var sw = MemoryStreamPool.Shared.CreateStreamWriter()) { asmgen.Write(sw); sw.Flush(); if (MonoAndroidHelper.CopyIfStreamChanged(sw.BaseStream, asmFilePath)) { Log.LogDebugMessage($"File {asmFilePath} was regenerated"); } } } } }