Skip to content

Commit 0decf45

Browse files
[One .NET] support for multiple $(RuntimeIdentifiers)
To mirror what we have for `$(AndroidSupportedAbis)` in the existing Xamarin.Android world, we need a way for .NET 6 apps to support multiple architectures. A `HelloAndroid.csproj` targeting all architectures might look like: <Project Sdk="Microsoft.NET.Sdk"> <PropertyGroup> <TargetFramework>net5.0-android</TargetFramework> <RuntimeIdentifiers>android.21-x86;android.21-x64;android.21-arm;android.21-arm64</RuntimeIdentifiers> <OutputType>Exe</OutputType> </PropertyGroup> </Project> To achieve this, we can do a nested `<MSBuild/>` call: <ItemGroup> <_RIDs Include="$(RuntimeIdentifiers)" /> </ItemGroup> <MSBuild Projects="$(MSBuildProjectFile)" Targets="_ComputeFilesToPublishForRuntimeIdentifiers" Properties="RuntimeIdentifier=%(_RIDs.Identity)"> <Output TaskParameter="TargetOutputs" ItemName="ResolvedFileToPublish" /> </MSBuild> For a new target: <Target Name="_ComputeFilesToPublishForRuntimeIdentifiers" DependsOnTargets="ResolveReferences;ComputeFilesToPublish" Returns="@(ResolvedFileToPublish)"> </Target> This is equivalent to what would happen in the legacy `_ResolveAssemblies` target. The linker then outputs files to: obj\Release\net5.0\$(RuntimeIdentifier)\linked\ One problem with this, is you receive multiple BCL assemblies for each architecture: obj\Release\net5.0\android.21-arm\linked\System.Linq.dll obj\Release\net5.0\android.21-arm64\linked\System.Linq.dll obj\Release\net5.0\android.21-x86\linked\System.Linq.dll obj\Release\net5.0\android.21-x64\linked\System.Linq.dll I created a `<ProcessAssemblies/>` MSBuild task that checks the mvid of each assembly to detect duplicates. Non-duplicates will be placed in a sub-directory within the `.apk` file, such as: * `assemblies\HelloAndroid.dll` * `assemblies\System.Linq.dll` * `assemblies\arm64-v8a\System.Private.CoreLib.dll` * `assemblies\armeabi-v7a\System.Private.CoreLib.dll` * `assemblies\x86\System.Private.CoreLib.dll` * `assemblies\x86_64\System.Private.CoreLib.dll` I had to make a few build & runtime changes for these ABI sub-directories to work. Other notes: * We must pass `@(IntermediateAssembly)` from the outer build to the nested `<MSBuild/>` calls. Otherwise, the inner calls look for `obj\Release\net5.0\android.21-arm\HelloAndroid.dll` instead of `obj\Release\net5.0\HelloAndroid.dll` that actually exists. * `_ComputeFilesToPublishForRuntimeIdentifiers` was running some extra targets causing `<ResolveSdks/>` to run 5 times for 4 ABIs. I had to make changes in `BuildOrder.targets` to fix this. * `<ResolveAssemblies/>` now sets `%(IntermediateLinkerOutput)` on each assembly item. This allows .NET 6 builds to support multiple linker directories.
1 parent 5a5580c commit 0decf45

21 files changed

+457
-206
lines changed

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

Lines changed: 70 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -10,42 +10,54 @@ _ResolveAssemblies MSBuild target.
1010

1111
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
1212

13-
<Target Name="_ResolveAssemblies" DependsOnTargets="ComputeFilesToPublish">
13+
<UsingTask TaskName="Xamarin.Android.Tasks.ProcessAssemblies" AssemblyFile="$(_XamarinAndroidBuildTasksAssembly)" />
1414

15-
<!--
16-
TODO: not yet complete.
17-
18-
Two things here are placeholders for later:
19-
20-
* %(HasMonoAndroidReference) is always True to disable
21-
performance improvements around $(TargetFrameworkVersion)
22-
detection.
15+
<Target Name="_ComputeFilesToPublishForRuntimeIdentifiers"
16+
DependsOnTargets="_FixupIntermediateAssembly;ResolveReferences;ComputeFilesToPublish"
17+
Returns="@(ResolvedFileToPublish)">
18+
</Target>
2319

24-
* Is there better metadata to use other than %(NuGetPackageId)
25-
to determine which runtime components are coming from our
26-
known @(FrameworkReference)s?
27-
-->
20+
<Target Name="_FixupIntermediateAssembly" Condition=" '$(_OuterIntermediateAssembly)' != '' ">
21+
<ItemGroup>
22+
<IntermediateAssembly Remove="@(IntermediateAssembly)" />
23+
<IntermediateAssembly Include="$(_OuterIntermediateAssembly)" />
24+
</ItemGroup>
25+
</Target>
2826

27+
<Target Name="_ResolveAssemblies">
28+
<ItemGroup>
29+
<_RIDs Include="$(RuntimeIdentifier)" Condition=" '$(RuntimeIdentifiers)' == '' " />
30+
<_RIDs Include="$(RuntimeIdentifiers)" Condition=" '$(RuntimeIdentifiers)' != '' " />
31+
</ItemGroup>
32+
<PropertyGroup>
33+
<_AdditionalProperties>_ComputeFilesToPublishForRuntimeIdentifiers=true;_OuterIntermediateAssembly=@(IntermediateAssembly)</_AdditionalProperties>
34+
</PropertyGroup>
35+
<MSBuild
36+
Projects="$(MSBuildProjectFile)"
37+
Targets="_ComputeFilesToPublishForRuntimeIdentifiers"
38+
Properties="RuntimeIdentifier=%(_RIDs.Identity);$(_AdditionalProperties)">
39+
<Output TaskParameter="TargetOutputs" ItemName="ResolvedFileToPublish" />
40+
</MSBuild>
41+
<ItemGroup>
42+
<_ResolvedAssemblyFiles Include="@(ResolvedFileToPublish)" Condition=" '%(ResolvedFileToPublish.Extension)' == '.dll' " />
43+
</ItemGroup>
44+
<ProcessAssemblies
45+
InputAssemblies="@(_ResolvedAssemblyFiles)"
46+
IntermediateAssemblyDirectory="$(MonoAndroidIntermediateAssemblyDir)"
47+
LinkMode="$(AndroidLinkMode)">
48+
<Output TaskParameter="OutputAssemblies" ItemName="ResolvedAssemblies" />
49+
<Output TaskParameter="ShrunkAssemblies" ItemName="_ShrunkAssemblies" />
50+
</ProcessAssemblies>
2951
<ItemGroup>
3052
<ResolvedFrameworkAssemblies
31-
Include="@(ResolvedFileToPublish)"
32-
Condition=" '%(ResolvedFileToPublish.Extension)' == '.dll' and '%(ResolvedFileToPublish.NuGetPackageId)' == 'Microsoft.Android.Runtime.$(RuntimeIdentifier)' "
33-
HasMonoAndroidReference="True"
34-
/>
35-
<ResolvedFrameworkAssemblies
36-
Include="@(ResolvedFileToPublish)"
37-
Condition=" '%(ResolvedFileToPublish.Extension)' == '.dll' and '%(ResolvedFileToPublish.NuGetPackageId)' == 'Microsoft.NETCore.App.Runtime.$(RuntimeIdentifier)' "
38-
HasMonoAndroidReference="True"
53+
Include="@(ResolvedAssemblies)"
54+
Condition=" '%(ResolvedAssemblies.FrameworkAssembly)' == 'true' "
3955
/>
4056
<ResolvedUserAssemblies
41-
Include="@(ResolvedFileToPublish)"
42-
Exclude="@(ResolvedFrameworkAssemblies)"
43-
Condition=" '%(ResolvedFileToPublish.Extension)' == '.dll' "
44-
HasMonoAndroidReference="True"
57+
Include="@(ResolvedAssemblies)"
58+
Condition=" '%(ResolvedAssemblies.FrameworkAssembly)' != 'true' "
4559
/>
46-
<ResolvedAssemblies Include="@(ResolvedFrameworkAssemblies);@(ResolvedUserAssemblies)" />
4760
</ItemGroup>
48-
4961
<Hash ItemsToHash="@(ResolvedAssemblies)">
5062
<Output TaskParameter="HashResult" PropertyName="_ResolvedUserAssembliesHash" />
5163
</Hash>
@@ -60,4 +72,35 @@ _ResolveAssemblies MSBuild target.
6072
</ItemGroup>
6173
</Target>
6274

75+
<Target Name="_PrepareAssemblies"
76+
DependsOnTargets="$(_PrepareAssembliesDependsOnTargets)">
77+
<ItemGroup Condition=" '$(AndroidLinkMode)' == 'None' ">
78+
<_ResolvedAssemblies Include="@(ResolvedAssemblies->'%(IntermediateLinkerOutput)')" />
79+
<_ResolvedUserAssemblies Include="@(ResolvedUserAssemblies->'%(IntermediateLinkerOutput)')" />
80+
<_ResolvedFrameworkAssemblies Include="@(ResolvedFrameworkAssemblies->'%(IntermediateLinkerOutput)')" />
81+
<_ShrunkAssemblies Include="@(_ResolvedAssemblies)" />
82+
<_ShrunkUserAssemblies Include="@(_ResolvedUserAssemblies)" />
83+
<_ShrunkFrameworkAssemblies Include="@(_ResolvedFrameworkAssemblies)" />
84+
</ItemGroup>
85+
<ItemGroup Condition=" '$(AndroidLinkMode)' != 'None' ">
86+
<_ResolvedAssemblies Include="@(ResolvedAssemblies)" />
87+
<_ResolvedUserAssemblies Include="@(ResolvedUserAssemblies)" />
88+
<_ResolvedFrameworkAssemblies Include="@(ResolvedFrameworkAssemblies)" />
89+
<_ShrunkFrameworkAssemblies
90+
Include="@(_ShrunkAssemblies)"
91+
Condition=" '%(_ShrunkAssemblies.FrameworkAssembly)' == 'true' "
92+
/>
93+
<_ShrunkUserAssemblies
94+
Include="@(_ShrunkAssemblies)"
95+
Condition=" '%(_ShrunkAssemblies.FrameworkAssembly)' != 'true' "
96+
/>
97+
</ItemGroup>
98+
<ItemGroup>
99+
<_ResolvedUserMonoAndroidAssemblies
100+
Include="@(_ResolvedUserAssemblies)"
101+
Condition=" '%(_ResolvedUserAssemblies.TargetFrameworkIdentifier)' == 'MonoAndroid' Or '%(_ResolvedUserAssemblies.HasMonoAndroidReference)' == 'True' "
102+
/>
103+
</ItemGroup>
104+
</Target>
105+
63106
</Project>

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

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -45,18 +45,8 @@ projects, these properties are set in Xamarin.Android.Legacy.targets.
4545
</BuildDependsOn>
4646
</PropertyGroup>
4747

48-
<PropertyGroup>
49-
<CompileDependsOn>
50-
_SetupDesignTimeBuildForCompile;
51-
_AddAndroidDefines;
52-
_IncludeLayoutBindingSources;
53-
AddLibraryJarsToBind;
54-
$(CompileDependsOn);
55-
</CompileDependsOn>
56-
<CoreCompileDependsOn>
57-
UpdateGeneratedFiles;
58-
$(CoreCompileDependsOn)
59-
</CoreCompileDependsOn>
48+
<!-- Targets that run unless we are running _ComputeFilesToPublishForRuntimeIdentifiers -->
49+
<PropertyGroup Condition=" '$(_ComputeFilesToPublishForRuntimeIdentifiers)' != 'true' ">
6050
<CoreResolveReferencesDependsOn>
6151
_SeparateAppExtensionReferences;
6252
_PrepareWearApplication;
@@ -71,6 +61,20 @@ projects, these properties are set in Xamarin.Android.Legacy.targets.
7161
AddEmbeddedJarsAsResources;
7262
AddEmbeddedReferenceJarsAsResources;
7363
</ResolveReferencesDependsOn>
64+
</PropertyGroup>
65+
66+
<PropertyGroup>
67+
<CompileDependsOn>
68+
_SetupDesignTimeBuildForCompile;
69+
_AddAndroidDefines;
70+
_IncludeLayoutBindingSources;
71+
AddLibraryJarsToBind;
72+
$(CompileDependsOn);
73+
</CompileDependsOn>
74+
<CoreCompileDependsOn>
75+
UpdateGeneratedFiles;
76+
$(CoreCompileDependsOn)
77+
</CoreCompileDependsOn>
7478
<DeferredBuildDependsOn>
7579
$(DeferredBuildDependsOn);
7680
UpdateAndroidResources;

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

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ This file contains the .NET 5-specific targets to customize ILLink
1010
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
1111

1212
<Target Name="_PrepareLinking"
13+
Condition=" '$(PublishTrimmed)' == 'true' "
1314
AfterTargets="ComputeResolvedFilesToPublishList"
1415
DependsOnTargets="GetReferenceAssemblyPaths">
1516
<ItemGroup>
@@ -22,9 +23,7 @@ This file contains the .NET 5-specific targets to customize ILLink
2223
</ItemGroup>
2324
<PropertyGroup>
2425
<!-- make the output verbose to see what the linker is doing. FIXME: make dependent upon verbosity level -->
25-
<_ExtraTrimmerArgs>$(_ExtraTrimmerArgs) --verbose --custom-data XATargetFrameworkDirectories="$(_XATargetFrameworkDirectories)"</_ExtraTrimmerArgs>
26-
27-
<IntermediateLinkDir>$(MonoAndroidIntermediateAssemblyDir)</IntermediateLinkDir>
26+
<_ExtraTrimmerArgs>$(_ExtraTrimmerArgs) --verbose --deterministic --custom-data XATargetFrameworkDirectories="$(_XATargetFrameworkDirectories)"</_ExtraTrimmerArgs>
2827

2928
<!-- we don't want to ignore stuff we can't find -->
3029
<_ExtraTrimmerArgs>$(_ExtraTrimmerArgs) --skip-unresolved false</_ExtraTrimmerArgs>
@@ -43,4 +42,9 @@ This file contains the .NET 5-specific targets to customize ILLink
4342
</_TrimmerCustomSteps>
4443
</ItemGroup>
4544
</Target>
45+
46+
<Target Name="_LinkAssemblies"
47+
DependsOnTargets="_ResolveAssemblies;_CreatePackageWorkspace;$(_BeforeLinkAssemblies);_GenerateJniMarshalMethods;_LinkAssembliesNoShrink"
48+
/>
49+
4650
</Project>

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ called for "legacy" projects in Xamarin.Android.Legacy.targets.
5858
<RuntimeIdentifierToAbi
5959
Condition=" '$(AndroidApplication)' == 'true' "
6060
RuntimeIdentifier="$(RuntimeIdentifier)"
61+
RuntimeIdentifiers="$(RuntimeIdentifiers)"
6162
SupportedAbis="$(AndroidSupportedAbis)">
6263
<Output TaskParameter="SupportedAbis" PropertyName="AndroidSupportedAbis" />
6364
</RuntimeIdentifierToAbi>

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@
99
<AndroidApplication Condition=" '$(AndroidApplication)' == '' And '$(OutputType)' == 'Exe' ">true</AndroidApplication>
1010
<AndroidApplication Condition=" '$(AndroidApplication)' == '' ">false</AndroidApplication>
1111
<SelfContained Condition=" '$(SelfContained)' == '' And '$(AndroidApplication)' == 'true' ">true</SelfContained>
12-
<RuntimeIdentifier Condition=" '$(RuntimeIdentifier)' == '' And '$(AndroidApplication)' == 'true' ">android.21-x86</RuntimeIdentifier>
12+
<!-- Prefer $(RuntimeIdentifiers) plural -->
13+
<RuntimeIdentifiers Condition=" '$(RuntimeIdentifier)' == '' And '$(RuntimeIdentifiers)' == '' And '$(AndroidApplication)' == 'true' ">android.21-arm64;android.21-x86</RuntimeIdentifiers>
14+
<RuntimeIdentifier Condition=" '$(RuntimeIdentifiers)' != '' And '$(RuntimeIdentifier)' != '' " />
1315
<AndroidManifest Condition=" '$(AndroidManifest)' == '' And '$(AndroidApplication)' == 'true' ">Properties\AndroidManifest.xml</AndroidManifest>
1416
<!-- We don't ever need a `static void Main` method, so switch to Library here-->
1517
<OutputType Condition=" '$(OutputType)' == 'Exe' ">Library</OutputType>

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

Lines changed: 28 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -317,23 +317,24 @@ private void AddAssemblies (ZipArchiveEx apk)
317317
sourcePath = CompressAssembly (assembly);
318318

319319
// Add assembly
320-
AddFileToArchiveIfNewer (apk, sourcePath, GetTargetDirectory (assembly.ItemSpec) + "/" + Path.GetFileName (assembly.ItemSpec), compressionMethod: UncompressedMethod);
320+
var assemblyPath = GetAssemblyPath (assembly, frameworkAssembly: false);
321+
AddFileToArchiveIfNewer (apk, sourcePath, assemblyPath + Path.GetFileName (assembly.ItemSpec), compressionMethod: UncompressedMethod);
321322

322323
// Try to add config if exists
323324
var config = Path.ChangeExtension (assembly.ItemSpec, "dll.config");
324-
AddAssemblyConfigEntry (apk, config);
325+
AddAssemblyConfigEntry (apk, assemblyPath, config);
325326

326327
// Try to add symbols if Debug
327328
if (debug) {
328329
var symbols = Path.ChangeExtension (assembly.ItemSpec, "dll.mdb");
329330

330331
if (File.Exists (symbols))
331-
AddFileToArchiveIfNewer (apk, symbols, AssembliesPath + Path.GetFileName (symbols), compressionMethod: UncompressedMethod);
332+
AddFileToArchiveIfNewer (apk, symbols, assemblyPath + Path.GetFileName (symbols), compressionMethod: UncompressedMethod);
332333

333334
symbols = Path.ChangeExtension (assembly.ItemSpec, "pdb");
334335

335336
if (File.Exists (symbols))
336-
AddFileToArchiveIfNewer (apk, symbols, AssembliesPath + Path.GetFileName (symbols), compressionMethod: UncompressedMethod);
337+
AddFileToArchiveIfNewer (apk, symbols, assemblyPath + Path.GetFileName (symbols), compressionMethod: UncompressedMethod);
337338
}
338339
count++;
339340
if (count == ZipArchiveEx.ZipFlushLimit) {
@@ -358,20 +359,21 @@ private void AddAssemblies (ZipArchiveEx apk)
358359
}
359360

360361
sourcePath = CompressAssembly (assembly);
361-
AddFileToArchiveIfNewer (apk, sourcePath, AssembliesPath + Path.GetFileName (assembly.ItemSpec), compressionMethod: UncompressedMethod);
362+
var assemblyPath = GetAssemblyPath (assembly, frameworkAssembly: true);
363+
AddFileToArchiveIfNewer (apk, sourcePath, assemblyPath + Path.GetFileName (assembly.ItemSpec), compressionMethod: UncompressedMethod);
362364
var config = Path.ChangeExtension (assembly.ItemSpec, "dll.config");
363-
AddAssemblyConfigEntry (apk, config);
365+
AddAssemblyConfigEntry (apk, assemblyPath, config);
364366
// Try to add symbols if Debug
365367
if (debug) {
366368
var symbols = Path.ChangeExtension (assembly.ItemSpec, "dll.mdb");
367369

368370
if (File.Exists (symbols))
369-
AddFileToArchiveIfNewer (apk, symbols, AssembliesPath + Path.GetFileName (symbols), compressionMethod: UncompressedMethod);
371+
AddFileToArchiveIfNewer (apk, symbols, assemblyPath + Path.GetFileName (symbols), compressionMethod: UncompressedMethod);
370372

371373
symbols = Path.ChangeExtension (assembly.ItemSpec, "pdb");
372374

373375
if (File.Exists (symbols))
374-
AddFileToArchiveIfNewer (apk, symbols, AssembliesPath + Path.GetFileName (symbols), compressionMethod: UncompressedMethod);
376+
AddFileToArchiveIfNewer (apk, symbols, assemblyPath + Path.GetFileName (symbols), compressionMethod: UncompressedMethod);
375377
}
376378
count++;
377379
if (count == ZipArchiveEx.ZipFlushLimit) {
@@ -399,7 +401,8 @@ string CompressAssembly (ITaskItem assembly)
399401
return assembly.ItemSpec;
400402
}
401403

402-
if (compressedAssembliesInfo.TryGetValue (Path.GetFileName (assembly.ItemSpec), out CompressedAssemblyInfo info) && info != null) {
404+
var key = CompressedAssemblyInfo.GetDictionaryKey (assembly);
405+
if (compressedAssembliesInfo.TryGetValue (key, out CompressedAssemblyInfo info) && info != null) {
403406
EnsureCompressedAssemblyData (assembly.ItemSpec, info.DescriptorIndex);
404407
AssemblyCompression.CompressionResult result = AssemblyCompression.Compress (compressedAssembly);
405408
if (result != AssemblyCompression.CompressionResult.Success) {
@@ -419,6 +422,8 @@ string CompressAssembly (ITaskItem assembly)
419422
return assembly.ItemSpec;
420423
}
421424
return compressedAssembly.DestinationPath;
425+
} else {
426+
Log.LogDebugMessage ($"Assembly missing from {CompressedAssemblyInfo.CompressedAssembliesInfoKey}: {key}");
422427
}
423428

424429
return assembly.ItemSpec;
@@ -437,9 +442,9 @@ bool AddFileToArchiveIfNewer (ZipArchiveEx apk, string file, string inArchivePat
437442
return true;
438443
}
439444

440-
void AddAssemblyConfigEntry (ZipArchiveEx apk, string configFile)
445+
void AddAssemblyConfigEntry (ZipArchiveEx apk, string assemblyPath, string configFile)
441446
{
442-
string inArchivePath = AssembliesPath + Path.GetFileName (configFile);
447+
string inArchivePath = assemblyPath + Path.GetFileName (configFile);
443448
existingEntries.Remove (inArchivePath);
444449

445450
if (!File.Exists (configFile))
@@ -460,13 +465,20 @@ void AddAssemblyConfigEntry (ZipArchiveEx apk, string configFile)
460465
}
461466
}
462467

463-
string GetTargetDirectory (string path)
468+
/// <summary>
469+
/// Returns the in-archive path for an assembly
470+
/// </summary>
471+
string GetAssemblyPath (ITaskItem assembly, bool frameworkAssembly)
464472
{
465-
string culture, file;
466-
if (SatelliteAssembly.TryGetSatelliteCultureAndFileName (path, out culture, out file)) {
467-
return AssembliesPath + culture;
473+
var assembliesPath = AssembliesPath;
474+
var abiDirectory = assembly.GetMetadata ("AbiDirectory");
475+
if (!string.IsNullOrEmpty (abiDirectory)) {
476+
assembliesPath += abiDirectory + "/";
468477
}
469-
return AssembliesPath.TrimEnd ('/');
478+
if (!frameworkAssembly && SatelliteAssembly.TryGetSatelliteCultureAndFileName (assembly.ItemSpec, out var culture, out _)) {
479+
assembliesPath += culture + "/";
480+
}
481+
return assembliesPath;
470482
}
471483

472484
class LibInfo

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

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ public class FilterAssemblies : AndroidTask
2020
public override string TaskPrefix => "FLT";
2121

2222
const string TargetFrameworkIdentifier = "MonoAndroid";
23-
const string MonoAndroidReference = "Mono.Android";
2423

2524
public bool DesignTimeBuild { get; set; }
2625

@@ -53,8 +52,8 @@ public override bool RunTask ()
5352
Log.LogDebugMessage ($"{nameof (TargetFrameworkIdentifier)} did not match: {assemblyItem.ItemSpec}");
5453

5554
// Fallback to looking for a Mono.Android reference
56-
if (HasReference (reader)) {
57-
Log.LogDebugMessage ($"{MonoAndroidReference} reference found: {assemblyItem.ItemSpec}");
55+
if (MonoAndroidHelper.HasMonoAndroidReference (reader)) {
56+
Log.LogDebugMessage ($"Mono.Android reference found: {assemblyItem.ItemSpec}");
5857
output.Add (assemblyItem);
5958
continue;
6059
}
@@ -104,18 +103,6 @@ string GetTargetFrameworkIdentifier (AssemblyDefinition assembly, MetadataReader
104103
return targetFrameworkIdentifier;
105104
}
106105

107-
bool HasReference (MetadataReader reader)
108-
{
109-
foreach (var handle in reader.AssemblyReferences) {
110-
var reference = reader.GetAssemblyReference (handle);
111-
var name = reader.GetString (reference.Name);
112-
if (MonoAndroidReference == name) {
113-
return true;
114-
}
115-
}
116-
return false;
117-
}
118-
119106
bool HasEmbeddedResource (MetadataReader reader)
120107
{
121108
foreach (var handle in reader.ManifestResources) {

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,8 @@ void GenerateCompressedAssemblySources ()
5353
continue;
5454
}
5555

56-
assemblies.Add (Path.GetFileName (assembly.ItemSpec), new CompressedAssemblyInfo (checked((uint)fi.Length)));
56+
var key = CompressedAssemblyInfo.GetDictionaryKey (assembly);
57+
assemblies.Add (key, new CompressedAssemblyInfo (checked((uint)fi.Length)));
5758
}
5859

5960
uint index = 0;

0 commit comments

Comments
 (0)