Skip to content

Commit 5b575fc

Browse files
[One .NET] simplify native library inclusion
I've noticed the `_IncludeNativeSystemLibraries` MSBuild target can take 40ms because it is running this workaround: <!-- HACK remove any unexpected runtime components --> <FrameworkNativeLibrary Remove="@(ResolvedFileToPublish)" Condition=" $([System.Text.RegularExpressions.Regex]::IsMatch('%(FullPath)', '.*linux-.*')) " /> The `_IncludeNativeSystemLibraries` also can be split up between "legacy" Xamarin.Android and .NET 6. The .NET 6 version can simply check the `@(ResolvedFileToPublish)` item group, as the other parts support the intepreter, profiler, etc., which are not available in .NET 6 yet. I created a new `<ProcessNativeLibraries/>` MSBuild task to simplify the work in C#: * We can iterate over all `.so` files from `@(ResolvedFileToPublish)`. * We can fix up `libmonodroid.so` as needed. * We can emit a warning if the ABI is unknown without using a `Regex`. It is possible for Linux `.so` files to be brought in from NuGet packages as discussed in: dotnet/runtime#45927 The warning is a new alternate message for XA4301, such as: warning XA4301: Cannot determine ABI of native library 'C:\src\xamarin-android\packages\sqlitepclraw.lib.e_sqlite3.linux\1.1.11\runtimes\linux-arm64\native\libe_sqlite3.so'. Remove the 'SQLitePCLRaw.lib.e_sqlite3.linux' NuGet package, or notify the library author. As part of this change, .NET 6 will no longer need to do: <PropertyGroup> <_Assemblies>@(_ResolvedFrameworkAssemblies)</_Assemblies> So we can avoid creating a ~14K character string. ~~ Results ~~ Timing the project fromm the `DotNetBuild(android.21-arm,false)` test, in a build with no changes: Before: 40 ms _IncludeNativeSystemLibraries 1 calls After: 4 ms _IncludeNativeSystemLibraries 1 calls This should save ~36ms from all .NET 6 builds.
1 parent 7be31df commit 5b575fc

19 files changed

+217
-64
lines changed

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

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ _ResolveAssemblies MSBuild target.
1010

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

13-
<UsingTask TaskName="Xamarin.Android.Tasks.ProcessAssemblies" AssemblyFile="$(_XamarinAndroidBuildTasksAssembly)" />
13+
<UsingTask TaskName="Xamarin.Android.Tasks.ProcessAssemblies" AssemblyFile="$(_XamarinAndroidBuildTasksAssembly)" />
14+
<UsingTask TaskName="Xamarin.Android.Tasks.ProcessNativeLibraries" AssemblyFile="$(_XamarinAndroidBuildTasksAssembly)" />
1415

1516
<PropertyGroup Condition=" '$(_ComputeFilesToPublishForRuntimeIdentifiers)' == 'true' ">
1617
<OutputPath Condition=" '$(_OuterOutputPath)' != '' ">$(_OuterOutputPath)</OutputPath>
@@ -157,4 +158,15 @@ _ResolveAssemblies MSBuild target.
157158
</ItemGroup>
158159
</Target>
159160

161+
<Target Name="_IncludeNativeSystemLibraries">
162+
<ItemGroup>
163+
<_ResolvedNativeLibraries Include="@(ResolvedFileToPublish)" Condition=" '%(ResolvedFileToPublish.Extension)' == '.so' " />
164+
</ItemGroup>
165+
<ProcessNativeLibraries
166+
InputLibraries="@(_ResolvedNativeLibraries)"
167+
IncludeDebugSymbols="$(AndroidIncludeDebugSymbols)">
168+
<Output TaskParameter="OutputLibraries" ItemName="FrameworkNativeLibrary" />
169+
</ProcessNativeLibraries>
170+
</Target>
171+
160172
</Project>

src/Xamarin.Android.Build.Tasks/Properties/Resources.resx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -661,6 +661,12 @@ The following are literal names and should not be translated: ABI, 'libs/armeabi
661661
<value>Cannot determine ABI of native library '{0}'. Move this file to a directory with a valid Android ABI name such as 'libs/armeabi-v7a/'.</value>
662662
<comment>The following are literal names and should not be translated: ABI, 'libs/armeabi-v7a/'
663663
{0} - The file path</comment>
664+
</data>
665+
<data name="XA4301_ABI_NuGet" xml:space="preserve">
666+
<value>Cannot determine ABI of native library '{0}'. Remove the '{1}' NuGet package, or notify the library author.</value>
667+
<comment>The following are literal names and should not be translated: ABI, NuGet
668+
{0} - The native library file path
669+
{1} - Either the name of the NuGet package or a path to the native library</comment>
664670
</data>
665671
<data name="XA4301_ABI_Ignoring" xml:space="preserve">
666672
<value>Could not determine ABI of some native libraries. Ignoring those: {0}</value>

src/Xamarin.Android.Build.Tasks/Properties/xlf/Resources.cs.xlf

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,13 @@ The capitalized word "Portable" that appears earlier in the message is plain tex
6464
<note>In this message, the term "bundled" is a short way of saying "included into the final application package."
6565
The following are literal names and should not be translated: ABI, 'libs/armeabi-v7a/'
6666
{0} - The file path</note>
67+
</trans-unit>
68+
<trans-unit id="XA4301_ABI_NuGet">
69+
<source>Cannot determine ABI of native library '{0}'. Remove the '{1}' NuGet package, or notify the library author.</source>
70+
<target state="new">Cannot determine ABI of native library '{0}'. Remove the '{1}' NuGet package, or notify the library author.</target>
71+
<note>The following are literal names and should not be translated: ABI, NuGet
72+
{0} - The native library file path
73+
{1} - Either the name of the NuGet package or a path to the native library</note>
6774
</trans-unit>
6875
<trans-unit id="XA_Manifest_AutoGenerated_Header">
6976
<source>

src/Xamarin.Android.Build.Tasks/Properties/xlf/Resources.de.xlf

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,13 @@ The capitalized word "Portable" that appears earlier in the message is plain tex
6464
<note>In this message, the term "bundled" is a short way of saying "included into the final application package."
6565
The following are literal names and should not be translated: ABI, 'libs/armeabi-v7a/'
6666
{0} - The file path</note>
67+
</trans-unit>
68+
<trans-unit id="XA4301_ABI_NuGet">
69+
<source>Cannot determine ABI of native library '{0}'. Remove the '{1}' NuGet package, or notify the library author.</source>
70+
<target state="new">Cannot determine ABI of native library '{0}'. Remove the '{1}' NuGet package, or notify the library author.</target>
71+
<note>The following are literal names and should not be translated: ABI, NuGet
72+
{0} - The native library file path
73+
{1} - Either the name of the NuGet package or a path to the native library</note>
6774
</trans-unit>
6875
<trans-unit id="XA_Manifest_AutoGenerated_Header">
6976
<source>

src/Xamarin.Android.Build.Tasks/Properties/xlf/Resources.es.xlf

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,13 @@ The capitalized word "Portable" that appears earlier in the message is plain tex
6464
<note>In this message, the term "bundled" is a short way of saying "included into the final application package."
6565
The following are literal names and should not be translated: ABI, 'libs/armeabi-v7a/'
6666
{0} - The file path</note>
67+
</trans-unit>
68+
<trans-unit id="XA4301_ABI_NuGet">
69+
<source>Cannot determine ABI of native library '{0}'. Remove the '{1}' NuGet package, or notify the library author.</source>
70+
<target state="new">Cannot determine ABI of native library '{0}'. Remove the '{1}' NuGet package, or notify the library author.</target>
71+
<note>The following are literal names and should not be translated: ABI, NuGet
72+
{0} - The native library file path
73+
{1} - Either the name of the NuGet package or a path to the native library</note>
6774
</trans-unit>
6875
<trans-unit id="XA_Manifest_AutoGenerated_Header">
6976
<source>

src/Xamarin.Android.Build.Tasks/Properties/xlf/Resources.fr.xlf

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,13 @@ The capitalized word "Portable" that appears earlier in the message is plain tex
6464
<note>In this message, the term "bundled" is a short way of saying "included into the final application package."
6565
The following are literal names and should not be translated: ABI, 'libs/armeabi-v7a/'
6666
{0} - The file path</note>
67+
</trans-unit>
68+
<trans-unit id="XA4301_ABI_NuGet">
69+
<source>Cannot determine ABI of native library '{0}'. Remove the '{1}' NuGet package, or notify the library author.</source>
70+
<target state="new">Cannot determine ABI of native library '{0}'. Remove the '{1}' NuGet package, or notify the library author.</target>
71+
<note>The following are literal names and should not be translated: ABI, NuGet
72+
{0} - The native library file path
73+
{1} - Either the name of the NuGet package or a path to the native library</note>
6774
</trans-unit>
6875
<trans-unit id="XA_Manifest_AutoGenerated_Header">
6976
<source>

src/Xamarin.Android.Build.Tasks/Properties/xlf/Resources.it.xlf

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,13 @@ The capitalized word "Portable" that appears earlier in the message is plain tex
6464
<note>In this message, the term "bundled" is a short way of saying "included into the final application package."
6565
The following are literal names and should not be translated: ABI, 'libs/armeabi-v7a/'
6666
{0} - The file path</note>
67+
</trans-unit>
68+
<trans-unit id="XA4301_ABI_NuGet">
69+
<source>Cannot determine ABI of native library '{0}'. Remove the '{1}' NuGet package, or notify the library author.</source>
70+
<target state="new">Cannot determine ABI of native library '{0}'. Remove the '{1}' NuGet package, or notify the library author.</target>
71+
<note>The following are literal names and should not be translated: ABI, NuGet
72+
{0} - The native library file path
73+
{1} - Either the name of the NuGet package or a path to the native library</note>
6774
</trans-unit>
6875
<trans-unit id="XA_Manifest_AutoGenerated_Header">
6976
<source>

src/Xamarin.Android.Build.Tasks/Properties/xlf/Resources.ja.xlf

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,13 @@ The capitalized word "Portable" that appears earlier in the message is plain tex
6464
<note>In this message, the term "bundled" is a short way of saying "included into the final application package."
6565
The following are literal names and should not be translated: ABI, 'libs/armeabi-v7a/'
6666
{0} - The file path</note>
67+
</trans-unit>
68+
<trans-unit id="XA4301_ABI_NuGet">
69+
<source>Cannot determine ABI of native library '{0}'. Remove the '{1}' NuGet package, or notify the library author.</source>
70+
<target state="new">Cannot determine ABI of native library '{0}'. Remove the '{1}' NuGet package, or notify the library author.</target>
71+
<note>The following are literal names and should not be translated: ABI, NuGet
72+
{0} - The native library file path
73+
{1} - Either the name of the NuGet package or a path to the native library</note>
6774
</trans-unit>
6875
<trans-unit id="XA_Manifest_AutoGenerated_Header">
6976
<source>

src/Xamarin.Android.Build.Tasks/Properties/xlf/Resources.ko.xlf

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,13 @@ The capitalized word "Portable" that appears earlier in the message is plain tex
6464
<note>In this message, the term "bundled" is a short way of saying "included into the final application package."
6565
The following are literal names and should not be translated: ABI, 'libs/armeabi-v7a/'
6666
{0} - The file path</note>
67+
</trans-unit>
68+
<trans-unit id="XA4301_ABI_NuGet">
69+
<source>Cannot determine ABI of native library '{0}'. Remove the '{1}' NuGet package, or notify the library author.</source>
70+
<target state="new">Cannot determine ABI of native library '{0}'. Remove the '{1}' NuGet package, or notify the library author.</target>
71+
<note>The following are literal names and should not be translated: ABI, NuGet
72+
{0} - The native library file path
73+
{1} - Either the name of the NuGet package or a path to the native library</note>
6774
</trans-unit>
6875
<trans-unit id="XA_Manifest_AutoGenerated_Header">
6976
<source>

src/Xamarin.Android.Build.Tasks/Properties/xlf/Resources.pl.xlf

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,13 @@ The capitalized word "Portable" that appears earlier in the message is plain tex
6464
<note>In this message, the term "bundled" is a short way of saying "included into the final application package."
6565
The following are literal names and should not be translated: ABI, 'libs/armeabi-v7a/'
6666
{0} - The file path</note>
67+
</trans-unit>
68+
<trans-unit id="XA4301_ABI_NuGet">
69+
<source>Cannot determine ABI of native library '{0}'. Remove the '{1}' NuGet package, or notify the library author.</source>
70+
<target state="new">Cannot determine ABI of native library '{0}'. Remove the '{1}' NuGet package, or notify the library author.</target>
71+
<note>The following are literal names and should not be translated: ABI, NuGet
72+
{0} - The native library file path
73+
{1} - Either the name of the NuGet package or a path to the native library</note>
6774
</trans-unit>
6875
<trans-unit id="XA_Manifest_AutoGenerated_Header">
6976
<source>

0 commit comments

Comments
 (0)