Skip to content

Commit 4e1cf9d

Browse files
committed
Almost there, TBC
1 parent dfa62fa commit 4e1cf9d

File tree

5 files changed

+72
-7
lines changed

5 files changed

+72
-7
lines changed

src/Xamarin.Android.Build.Tasks/Microsoft.Android.Sdk/targets/Microsoft.Android.Sdk.AssemblyStores.targets

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,13 @@
1717
<CreateEmbeddedAssemblyStore
1818
AndroidBinUtilsDirectory="$(AndroidBinUtilsDirectory)"
1919
AppSharedLibrariesDir="$(_AndroidApplicationSharedLibraryPath)"
20+
CompressedAssembliesDir="$(_AndroidCompressedAssembliesDir)\test\"
21+
Debug="$(AndroidIncludeDebugSymbols)"
22+
EnableCompression="$(AndroidEnableAssemblyCompression)"
23+
ProjectFullPath="$(MSBuildProjectFullPath)"
2024
ResolvedUserAssemblies="@(_ShrunkUserAssemblies);@(_AndroidResolvedSatellitePaths)"
21-
ResolvedFrameworkAssemblies="@(_ShrunkFrameworkAssemblies)">
25+
ResolvedFrameworkAssemblies="@(_ShrunkFrameworkAssemblies)"
26+
SupportedAbis="@(_BuildTargetAbis)">
2227
<Output TaskParameter="EmbeddedObjectFiles" ItemName="_NativeAssemblyTarget" />
2328
<Output TaskParameter="NativeAssemblySources" ItemName="_EmbeddedAssemblyStoreSourceFiles" />
2429
</CreateEmbeddedAssemblyStore>

src/Xamarin.Android.Build.Tasks/Microsoft.Android.Sdk/targets/Microsoft.Android.Sdk.BuildOrder.targets

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,6 @@ properties that determine build ordering.
6262
<_PrepareBuildApkDependsOnTargets>
6363
_SetLatestTargetFrameworkVersion;
6464
_GetLibraryImports;
65-
_RemoveRegisterAttribute;
6665
_ResolveAssemblies;
6766
_ResolveSatellitePaths;
6867
_CreatePackageWorkspace;

src/Xamarin.Android.Build.Tasks/Tasks/BuildApk.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,9 @@ public class BuildApk : AndroidTask
118118
[Required]
119119
public string ProjectFullPath { get; set; }
120120

121+
[Required]
122+
public string CompressedAssembliesDir { get; set; }
123+
121124
[Output]
122125
public ITaskItem[] OutputFiles { get; set; }
123126

@@ -354,7 +357,7 @@ public override bool RunTask ()
354357

355358
if (compress) {
356359
string key = CompressedAssemblyInfo.GetKey (ProjectFullPath);
357-
Log.LogDebugMessage ($"Retrieving assembly compression info with key '{key}'");
360+
Log.LogDebugMessage ($"[{TaskPrefix}] Retrieving assembly compression info with key '{key}'");
358361
compressedAssembliesInfo = BuildEngine4.UnregisterTaskObjectAssemblyLocal<IDictionary<AndroidTargetArch, Dictionary<string, CompressedAssemblyInfo>>> (key, RegisteredTaskObjectLifetime.Build);
359362
if (compressedAssembliesInfo == null)
360363
throw new InvalidOperationException ($"Assembly compression info not found for key '{key}'. Compression will not be performed.");
@@ -424,7 +427,6 @@ void AddAssemblies (DSOWrapperGenerator.Config dsoWrapperConfig, ZipArchiveEx ap
424427
{
425428
string sourcePath;
426429
AssemblyCompression.AssemblyData compressedAssembly = null;
427-
string compressedOutputDir = Path.GetFullPath (Path.Combine (Path.GetDirectoryName (ApkOutputPath), "..", "lz4"));
428430
AssemblyStoreBuilder? storeBuilder = null;
429431

430432
if (UseAssemblyStore) {
@@ -507,7 +509,7 @@ string CompressAssembly (ITaskItem assembly)
507509
return assembly.ItemSpec;
508510
}
509511

510-
return AssemblyCompression.Compress (Log, assembly, compressedAssembliesInfo, compressedOutputDir);
512+
return AssemblyCompression.Compress (Log, assembly, compressedAssembliesInfo, CompressedAssembliesDir);
511513
}
512514
}
513515

src/Xamarin.Android.Build.Tasks/Tasks/CreateEmbeddedAssemblyStore.cs

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
1+
using System;
2+
using System.Collections.Generic;
13

24
using Microsoft.Android.Build.Tasks;
35
using Microsoft.Build.Framework;
6+
using Microsoft.Build.Utilities;
47
using Xamarin.Android.Tools;
58

69
namespace Xamarin.Android.Tasks;
@@ -15,12 +18,27 @@ public class CreateEmbeddedAssemblyStore : AndroidTask
1518
[Required]
1619
public string AppSharedLibrariesDir { get; set; }
1720

21+
[Required]
22+
public string CompressedAssembliesDir { get; set; }
23+
24+
[Required]
25+
public bool Debug { get; set; }
26+
27+
[Required]
28+
public bool EnableCompression { get; set; }
29+
30+
[Required]
31+
public string ProjectFullPath { get; set; }
32+
1833
[Required]
1934
public ITaskItem[] ResolvedUserAssemblies { get; set; }
2035

2136
[Required]
2237
public ITaskItem[] ResolvedFrameworkAssemblies { get; set; }
2338

39+
[Required]
40+
public string [] SupportedAbis { get; set; }
41+
2442
[Output]
2543
public ITaskItem[] NativeAssemblySources { get; set; }
2644

@@ -29,6 +47,42 @@ public class CreateEmbeddedAssemblyStore : AndroidTask
2947

3048
public override bool RunTask ()
3149
{
50+
bool compress = !Debug && EnableCompression;
51+
IDictionary<AndroidTargetArch, Dictionary<string, CompressedAssemblyInfo>>? compressedAssembliesInfo = null;
52+
53+
if (compress) {
54+
string key = CompressedAssemblyInfo.GetKey (ProjectFullPath);
55+
Log.LogDebugMessage ($"[{TaskPrefix}] Retrieving assembly compression info with key '{key}'");
56+
compressedAssembliesInfo = BuildEngine4.GetRegisteredTaskObjectAssemblyLocal<IDictionary<AndroidTargetArch, Dictionary<string, CompressedAssemblyInfo>>> (key, RegisteredTaskObjectLifetime.Build);
57+
if (compressedAssembliesInfo == null) {
58+
throw new InvalidOperationException ($"Assembly compression info not found for key '{key}'. Compression will not be performed.");
59+
}
60+
}
61+
62+
var storeBuilder = new AssemblyStoreBuilder (Log);
63+
64+
// Add user assemblies
65+
AssemblyPackagingHelper.AddAssembliesFromCollection (Log, SupportedAbis, ResolvedUserAssemblies, DoAddAssembliesFromArchCollection);
66+
67+
// Add framework assemblies
68+
AssemblyPackagingHelper.AddAssembliesFromCollection (Log, SupportedAbis, ResolvedFrameworkAssemblies, DoAddAssembliesFromArchCollection);
69+
3270
return !Log.HasLoggedErrors;
71+
72+
void DoAddAssembliesFromArchCollection (TaskLoggingHelper log, AndroidTargetArch arch, ITaskItem assembly)
73+
{
74+
string sourcePath = CompressAssembly (assembly);
75+
storeBuilder.AddAssembly (sourcePath, assembly, includeDebugSymbols: Debug);
76+
return;
77+
}
78+
79+
string CompressAssembly (ITaskItem assembly)
80+
{
81+
if (!compress) {
82+
return assembly.ItemSpec;
83+
}
84+
85+
return AssemblyCompression.Compress (Log, assembly, compressedAssembliesInfo, CompressedAssembliesDir);
86+
}
3387
}
3488
}

src/Xamarin.Android.Build.Tasks/Xamarin.Android.Common.targets

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@ Copyright (C) 2011-2012 Xamarin. All rights reserved.
292292

293293
<_AndroidFastDeployEnvironmentFiles Condition=" '$(_AndroidFastDeployEnvironmentFiles)' == '' And '$(EmbedAssembliesIntoApk)' == 'False' ">True</_AndroidFastDeployEnvironmentFiles>
294294
<_AndroidFastDeployEnvironmentFiles Condition=" '$(_AndroidFastDeployEnvironmentFiles)' == '' ">False</_AndroidFastDeployEnvironmentFiles>
295-
295+
<_AndroidCompressedAssembliesDir>$(IntermediateOutputPath)android\lz4</_AndroidCompressedAssembliesDir>
296296
</PropertyGroup>
297297

298298
<Choose>
@@ -1869,6 +1869,7 @@ because xbuild doesn't support framework reference assemblies.
18691869
<PropertyGroup>
18701870
<_CompileToDalvikDependsOnTargets>
18711871
_CompileJava;
1872+
_RemoveRegisterAttribute;
18721873
_CreateApplicationSharedLibraries;
18731874
_GetMonoPlatformJarPath;
18741875
_GetLibraryImports;
@@ -1999,7 +2000,7 @@ because xbuild doesn't support framework reference assemblies.
19992000
</Target>
20002001

20012002
<Target Name="_CompileNativeAssemblySources"
2002-
DependsOnTargets="_CreateEmbeddedAssemblyStore;_PrepareNativeAssemblyItems;_GenerateCompressedAssembliesNativeSourceFiles"
2003+
DependsOnTargets="_PrepareNativeAssemblyItems;_GenerateCompressedAssembliesNativeSourceFiles;_CreateEmbeddedAssemblyStore"
20032004
Inputs="@(_TypeMapAssemblySource);@(_TypeMapAssemblyInclude);@(_EnvironmentAssemblySource);@(_CompressedAssembliesAssemblySource);@(_MarshalMethodsAssemblySource);@(_AndroidRemapAssemblySource)"
20042005
Outputs="@(_NativeAssemblyTarget)">
20052006
<CompileNativeAssembly
@@ -2116,6 +2117,7 @@ because xbuild doesn't support framework reference assemblies.
21162117
UseAssemblyStore="$(AndroidUseAssemblyStore)"
21172118
AndroidBinUtilsDirectory="$(AndroidBinUtilsDirectory)"
21182119
IntermediateOutputPath="$(IntermediateOutputPath)">
2120+
CompressedAssembliesDir="$(_AndroidCompressedAssembliesDir)">
21192121
<Output TaskParameter="OutputFiles" ItemName="ApkFiles" />
21202122
</BuildApk>
21212123
<BuildBaseAppBundle
@@ -2156,6 +2158,7 @@ because xbuild doesn't support framework reference assemblies.
21562158
UseAssemblyStore="$(AndroidUseAssemblyStore)"
21572159
AndroidBinUtilsDirectory="$(AndroidBinUtilsDirectory)"
21582160
IntermediateOutputPath="$(IntermediateOutputPath)">
2161+
CompressedAssembliesDir="$(_AndroidCompressedAssembliesDir)">
21592162
<Output TaskParameter="OutputFiles" ItemName="BaseZipFile" />
21602163
</BuildBaseAppBundle>
21612164
<BuildAppBundle
@@ -2229,6 +2232,7 @@ because xbuild doesn't support framework reference assemblies.
22292232
ExcludeFiles="@(AndroidPackagingOptionsExclude)"
22302233
AndroidBinUtilsDirectory="$(AndroidBinUtilsDirectory)"
22312234
IntermediateOutputPath="$(IntermediateOutputPath)">
2235+
CompressedAssembliesDir="$(_AndroidCompressedAssembliesDir)">
22322236
<Output TaskParameter="OutputFiles" ItemName="ApkFiles" />
22332237
</BuildApk>
22342238
<BuildBaseAppBundle
@@ -2268,6 +2272,7 @@ because xbuild doesn't support framework reference assemblies.
22682272
ExcludeFiles="@(AndroidPackagingOptionsExclude)"
22692273
AndroidBinUtilsDirectory="$(AndroidBinUtilsDirectory)"
22702274
IntermediateOutputPath="$(IntermediateOutputPath)">
2275+
CompressedAssembliesDir="$(_AndroidCompressedAssembliesDir)">
22712276
<Output TaskParameter="OutputFiles" ItemName="BaseZipFile" />
22722277
</BuildBaseAppBundle>
22732278
<BuildAppBundle

0 commit comments

Comments
 (0)