Skip to content

Commit cb678cf

Browse files
committed
Don't package BCL libraries when linking dynamically
1 parent d216289 commit cb678cf

File tree

1 file changed

+29
-1
lines changed

1 file changed

+29
-1
lines changed

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

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,19 @@ public class ProcessNativeLibraries : AndroidTask
2222
"libxamarin-debug-app-helper",
2323
};
2424

25+
// Please keep the list sorted. Any new runtime libraries that are added upstream need to be mentioned here.
26+
static readonly HashSet<string> KnownRuntimeNativeLibraries = new (StringComparer.OrdinalIgnoreCase) {
27+
"libSystem.Globalization.Native.so",
28+
"libSystem.IO.Compression.Native.so",
29+
"libSystem.Native.so",
30+
"libSystem.Security.Cryptography.Native.Android.so",
31+
"libmono-component-debugger.so",
32+
"libmono-component-diagnostics_tracing.so",
33+
"libmono-component-hot_reload.so",
34+
"libmono-component-marshal-ilgen.so",
35+
"libmonosgen-2.0.so",
36+
};
37+
2538
/// <summary>
2639
/// Assumed to be .so files only
2740
/// </summary>
@@ -93,12 +106,27 @@ public override bool RunTask ()
93106
continue;
94107
}
95108

96-
output.Add (library);
109+
if (!IgnoreLibraryWhenLinkingRuntime (library)) {
110+
output.Add (library);
111+
}
97112
}
98113

99114
OutputLibraries = output.ToArray ();
100115

101116
return !Log.HasLoggedErrors;
102117
}
118+
119+
bool IgnoreLibraryWhenLinkingRuntime (ITaskItem libItem)
120+
{
121+
// We ignore all the shared libraries coming from the runtime packages, as they are all linked into our runtime and
122+
// need not be packaged.
123+
string packageId = libItem.GetMetadata ("NuGetPackageId");
124+
if (packageId.StartsWith ("Microsoft.NETCore.App.Runtime.Mono.android-", StringComparison.OrdinalIgnoreCase)) {
125+
return true;
126+
}
127+
128+
// Should `NuGetPackageId` be empty, we check the libs by name, as the last resort.
129+
return KnownRuntimeNativeLibraries.Contains (Path.GetFileName (libItem.ItemSpec));
130+
}
103131
}
104132
}

0 commit comments

Comments
 (0)