Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ _ResolveAssemblies MSBuild target.

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

<UsingTask TaskName="Xamarin.Android.Tasks.ProcessAssemblies" AssemblyFile="$(_XamarinAndroidBuildTasksAssembly)" />
<UsingTask TaskName="Xamarin.Android.Tasks.ProcessAssemblies" AssemblyFile="$(_XamarinAndroidBuildTasksAssembly)" />
<UsingTask TaskName="Xamarin.Android.Tasks.ProcessNativeLibraries" AssemblyFile="$(_XamarinAndroidBuildTasksAssembly)" />

<PropertyGroup Condition=" '$(_ComputeFilesToPublishForRuntimeIdentifiers)' == 'true' ">
<OutputPath Condition=" '$(_OuterOutputPath)' != '' ">$(_OuterOutputPath)</OutputPath>
Expand Down Expand Up @@ -157,4 +158,15 @@ _ResolveAssemblies MSBuild target.
</ItemGroup>
</Target>

<Target Name="_IncludeNativeSystemLibraries">
<ItemGroup>
<_ResolvedNativeLibraries Include="@(ResolvedFileToPublish)" Condition=" '%(ResolvedFileToPublish.Extension)' == '.so' " />
</ItemGroup>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How are we going to handle _AndroidNativeLibraryForFastDev in the .net 6 world? This is used when we fast deploy most native libraries to the override directory rather than include them in the apk.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hopefully some test will fail here, as this was removed for .NET 6:

<_AndroidNativeLibraryForFastDev Condition=" '$(_InstantRunEnabled)' == 'True' And '$(AndroidUseDebugRuntime)' == 'True' And '$(_AndroidCheckedBuild)' == '' " Include="%(_TargetLibDir.Identity)\libxamarin-debug-app-helper.so" />

I'll need to add an equivalent for these.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

libxamarin-debug-app-helper.so is in our runtime packs and will end up as a @(FrameworkNativeLibrary), and those items aren't fast deployed. Before fb727f0, these files were hard coded in the <BuildApk/> task.

It looks like only @(AndroidNativeLibrary) items are added to @(_AndroidNativeLibraryForFastDev): https://github.com/xamarin/monodroid/blob/27736a7ffc48d606ab45598f761e873f8572f46a/tools/msbuild/Xamarin.Android.Common.Debugging.targets#L224.

Maybe we should look at fast deploying @(FrameworkNativeLibrary) in a future PR? If we try to fast deploy both customer libs and framework libs we'll need to rework: https://github.com/xamarin/xamarin-android/blob/aaa37c3df94490ee9befb8381f4dd7aa18226355/src/Xamarin.Android.Build.Tasks/Tasks/BuildApk.cs#L589

As for the three $(_AndroidNativeLibraryForFastDev) items explicitly mentioned here, two files are used for native static code analysis (which I don't think we ever need to put into customer apps). The other one is for the interpreter, and I am not sure if that is available in .NET 6? I am not sure if we need to worry about any of these in a .NET 6 context?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

certain native libs still need to be in the apk even when fast deploying. specifically monodroid.so and its immediate dependencies. This is because it is loaded as part of the runtime startup. So we can't just fast dev everything.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The latest changes shouldn't change the current logic for .NET 6, except the block:

<!-- HACK remove any unexpected runtime components -->
<FrameworkNativeLibrary
    Remove="@(ResolvedFileToPublish)"
    Condition="  $([System.Text.RegularExpressions.Regex]::IsMatch('%(FullPath)', '.*linux-.*'))  "
/>

Instead of silently ignoring, you get a XA4301 warning now.

The tests we have for Fast Deployment should be passing, so I don't think there is actually anything broken?

<ProcessNativeLibraries
InputLibraries="@(_ResolvedNativeLibraries)"
IncludeDebugSymbols="$(AndroidIncludeDebugSymbols)">
<Output TaskParameter="OutputLibraries" ItemName="FrameworkNativeLibrary" />
</ProcessNativeLibraries>
</Target>

</Project>
6 changes: 6 additions & 0 deletions src/Xamarin.Android.Build.Tasks/Properties/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -661,6 +661,12 @@ The following are literal names and should not be translated: ABI, 'libs/armeabi
<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>
<comment>The following are literal names and should not be translated: ABI, 'libs/armeabi-v7a/'
{0} - The file path</comment>
</data>
<data name="XA4301_ABI_NuGet" xml:space="preserve">
<value>Cannot determine ABI of native library '{0}'. Remove the '{1}' NuGet package, or notify the library author.</value>
<comment>The following are literal names and should not be translated: ABI, NuGet
{0} - The native library file path
{1} - Either the name of the NuGet package or a path to the native library</comment>
</data>
<data name="XA4301_ABI_Ignoring" xml:space="preserve">
<value>Could not determine ABI of some native libraries. Ignoring those: {0}</value>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,13 @@ The capitalized word "Portable" that appears earlier in the message is plain tex
<note>In this message, the term "bundled" is a short way of saying "included into the final application package."
The following are literal names and should not be translated: ABI, 'libs/armeabi-v7a/'
{0} - The file path</note>
</trans-unit>
<trans-unit id="XA4301_ABI_NuGet">
<source>Cannot determine ABI of native library '{0}'. Remove the '{1}' NuGet package, or notify the library author.</source>
<target state="new">Cannot determine ABI of native library '{0}'. Remove the '{1}' NuGet package, or notify the library author.</target>
<note>The following are literal names and should not be translated: ABI, NuGet
{0} - The native library file path
{1} - Either the name of the NuGet package or a path to the native library</note>
</trans-unit>
<trans-unit id="XA_Manifest_AutoGenerated_Header">
<source>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,13 @@ The capitalized word "Portable" that appears earlier in the message is plain tex
<note>In this message, the term "bundled" is a short way of saying "included into the final application package."
The following are literal names and should not be translated: ABI, 'libs/armeabi-v7a/'
{0} - The file path</note>
</trans-unit>
<trans-unit id="XA4301_ABI_NuGet">
<source>Cannot determine ABI of native library '{0}'. Remove the '{1}' NuGet package, or notify the library author.</source>
<target state="new">Cannot determine ABI of native library '{0}'. Remove the '{1}' NuGet package, or notify the library author.</target>
<note>The following are literal names and should not be translated: ABI, NuGet
{0} - The native library file path
{1} - Either the name of the NuGet package or a path to the native library</note>
</trans-unit>
<trans-unit id="XA_Manifest_AutoGenerated_Header">
<source>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,13 @@ The capitalized word "Portable" that appears earlier in the message is plain tex
<note>In this message, the term "bundled" is a short way of saying "included into the final application package."
The following are literal names and should not be translated: ABI, 'libs/armeabi-v7a/'
{0} - The file path</note>
</trans-unit>
<trans-unit id="XA4301_ABI_NuGet">
<source>Cannot determine ABI of native library '{0}'. Remove the '{1}' NuGet package, or notify the library author.</source>
<target state="new">Cannot determine ABI of native library '{0}'. Remove the '{1}' NuGet package, or notify the library author.</target>
<note>The following are literal names and should not be translated: ABI, NuGet
{0} - The native library file path
{1} - Either the name of the NuGet package or a path to the native library</note>
</trans-unit>
<trans-unit id="XA_Manifest_AutoGenerated_Header">
<source>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,13 @@ The capitalized word "Portable" that appears earlier in the message is plain tex
<note>In this message, the term "bundled" is a short way of saying "included into the final application package."
The following are literal names and should not be translated: ABI, 'libs/armeabi-v7a/'
{0} - The file path</note>
</trans-unit>
<trans-unit id="XA4301_ABI_NuGet">
<source>Cannot determine ABI of native library '{0}'. Remove the '{1}' NuGet package, or notify the library author.</source>
<target state="new">Cannot determine ABI of native library '{0}'. Remove the '{1}' NuGet package, or notify the library author.</target>
<note>The following are literal names and should not be translated: ABI, NuGet
{0} - The native library file path
{1} - Either the name of the NuGet package or a path to the native library</note>
</trans-unit>
<trans-unit id="XA_Manifest_AutoGenerated_Header">
<source>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,13 @@ The capitalized word "Portable" that appears earlier in the message is plain tex
<note>In this message, the term "bundled" is a short way of saying "included into the final application package."
The following are literal names and should not be translated: ABI, 'libs/armeabi-v7a/'
{0} - The file path</note>
</trans-unit>
<trans-unit id="XA4301_ABI_NuGet">
<source>Cannot determine ABI of native library '{0}'. Remove the '{1}' NuGet package, or notify the library author.</source>
<target state="new">Cannot determine ABI of native library '{0}'. Remove the '{1}' NuGet package, or notify the library author.</target>
<note>The following are literal names and should not be translated: ABI, NuGet
{0} - The native library file path
{1} - Either the name of the NuGet package or a path to the native library</note>
</trans-unit>
<trans-unit id="XA_Manifest_AutoGenerated_Header">
<source>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,13 @@ The capitalized word "Portable" that appears earlier in the message is plain tex
<note>In this message, the term "bundled" is a short way of saying "included into the final application package."
The following are literal names and should not be translated: ABI, 'libs/armeabi-v7a/'
{0} - The file path</note>
</trans-unit>
<trans-unit id="XA4301_ABI_NuGet">
<source>Cannot determine ABI of native library '{0}'. Remove the '{1}' NuGet package, or notify the library author.</source>
<target state="new">Cannot determine ABI of native library '{0}'. Remove the '{1}' NuGet package, or notify the library author.</target>
<note>The following are literal names and should not be translated: ABI, NuGet
{0} - The native library file path
{1} - Either the name of the NuGet package or a path to the native library</note>
</trans-unit>
<trans-unit id="XA_Manifest_AutoGenerated_Header">
<source>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,13 @@ The capitalized word "Portable" that appears earlier in the message is plain tex
<note>In this message, the term "bundled" is a short way of saying "included into the final application package."
The following are literal names and should not be translated: ABI, 'libs/armeabi-v7a/'
{0} - The file path</note>
</trans-unit>
<trans-unit id="XA4301_ABI_NuGet">
<source>Cannot determine ABI of native library '{0}'. Remove the '{1}' NuGet package, or notify the library author.</source>
<target state="new">Cannot determine ABI of native library '{0}'. Remove the '{1}' NuGet package, or notify the library author.</target>
<note>The following are literal names and should not be translated: ABI, NuGet
{0} - The native library file path
{1} - Either the name of the NuGet package or a path to the native library</note>
</trans-unit>
<trans-unit id="XA_Manifest_AutoGenerated_Header">
<source>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,13 @@ The capitalized word "Portable" that appears earlier in the message is plain tex
<note>In this message, the term "bundled" is a short way of saying "included into the final application package."
The following are literal names and should not be translated: ABI, 'libs/armeabi-v7a/'
{0} - The file path</note>
</trans-unit>
<trans-unit id="XA4301_ABI_NuGet">
<source>Cannot determine ABI of native library '{0}'. Remove the '{1}' NuGet package, or notify the library author.</source>
<target state="new">Cannot determine ABI of native library '{0}'. Remove the '{1}' NuGet package, or notify the library author.</target>
<note>The following are literal names and should not be translated: ABI, NuGet
{0} - The native library file path
{1} - Either the name of the NuGet package or a path to the native library</note>
</trans-unit>
<trans-unit id="XA_Manifest_AutoGenerated_Header">
<source>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,13 @@ The capitalized word "Portable" that appears earlier in the message is plain tex
<note>In this message, the term "bundled" is a short way of saying "included into the final application package."
The following are literal names and should not be translated: ABI, 'libs/armeabi-v7a/'
{0} - The file path</note>
</trans-unit>
<trans-unit id="XA4301_ABI_NuGet">
<source>Cannot determine ABI of native library '{0}'. Remove the '{1}' NuGet package, or notify the library author.</source>
<target state="new">Cannot determine ABI of native library '{0}'. Remove the '{1}' NuGet package, or notify the library author.</target>
<note>The following are literal names and should not be translated: ABI, NuGet
{0} - The native library file path
{1} - Either the name of the NuGet package or a path to the native library</note>
</trans-unit>
<trans-unit id="XA_Manifest_AutoGenerated_Header">
<source>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,13 @@ The capitalized word "Portable" that appears earlier in the message is plain tex
<note>In this message, the term "bundled" is a short way of saying "included into the final application package."
The following are literal names and should not be translated: ABI, 'libs/armeabi-v7a/'
{0} - The file path</note>
</trans-unit>
<trans-unit id="XA4301_ABI_NuGet">
<source>Cannot determine ABI of native library '{0}'. Remove the '{1}' NuGet package, or notify the library author.</source>
<target state="new">Cannot determine ABI of native library '{0}'. Remove the '{1}' NuGet package, or notify the library author.</target>
<note>The following are literal names and should not be translated: ABI, NuGet
{0} - The native library file path
{1} - Either the name of the NuGet package or a path to the native library</note>
</trans-unit>
<trans-unit id="XA_Manifest_AutoGenerated_Header">
<source>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,13 @@ The capitalized word "Portable" that appears earlier in the message is plain tex
<note>In this message, the term "bundled" is a short way of saying "included into the final application package."
The following are literal names and should not be translated: ABI, 'libs/armeabi-v7a/'
{0} - The file path</note>
</trans-unit>
<trans-unit id="XA4301_ABI_NuGet">
<source>Cannot determine ABI of native library '{0}'. Remove the '{1}' NuGet package, or notify the library author.</source>
<target state="new">Cannot determine ABI of native library '{0}'. Remove the '{1}' NuGet package, or notify the library author.</target>
<note>The following are literal names and should not be translated: ABI, NuGet
{0} - The native library file path
{1} - Either the name of the NuGet package or a path to the native library</note>
</trans-unit>
<trans-unit id="XA_Manifest_AutoGenerated_Header">
<source>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,13 @@ The capitalized word "Portable" that appears earlier in the message is plain tex
<note>In this message, the term "bundled" is a short way of saying "included into the final application package."
The following are literal names and should not be translated: ABI, 'libs/armeabi-v7a/'
{0} - The file path</note>
</trans-unit>
<trans-unit id="XA4301_ABI_NuGet">
<source>Cannot determine ABI of native library '{0}'. Remove the '{1}' NuGet package, or notify the library author.</source>
<target state="new">Cannot determine ABI of native library '{0}'. Remove the '{1}' NuGet package, or notify the library author.</target>
<note>The following are literal names and should not be translated: ABI, NuGet
{0} - The native library file path
{1} - Either the name of the NuGet package or a path to the native library</note>
</trans-unit>
<trans-unit id="XA_Manifest_AutoGenerated_Header">
<source>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,13 @@ The capitalized word "Portable" that appears earlier in the message is plain tex
<note>In this message, the term "bundled" is a short way of saying "included into the final application package."
The following are literal names and should not be translated: ABI, 'libs/armeabi-v7a/'
{0} - The file path</note>
</trans-unit>
<trans-unit id="XA4301_ABI_NuGet">
<source>Cannot determine ABI of native library '{0}'. Remove the '{1}' NuGet package, or notify the library author.</source>
<target state="new">Cannot determine ABI of native library '{0}'. Remove the '{1}' NuGet package, or notify the library author.</target>
<note>The following are literal names and should not be translated: ABI, NuGet
{0} - The native library file path
{1} - Either the name of the NuGet package or a path to the native library</note>
</trans-unit>
<trans-unit id="XA_Manifest_AutoGenerated_Header">
<source>
Expand Down
68 changes: 68 additions & 0 deletions src/Xamarin.Android.Build.Tasks/Tasks/ProcessNativeLibraries.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
using System;
using System.Collections.Generic;
using System.IO;
using Microsoft.Build.Framework;

namespace Xamarin.Android.Tasks
{
/// <summary>
/// Processes .so files coming from @(ResolvedFileToPublish).
/// * Checks if ABI is valid
/// * Fixes up libmonodroid.so based on $(AndroidIncludeDebugSymbols)
/// </summary>
public class ProcessNativeLibraries : AndroidTask
{
public override string TaskPrefix => "PRNL";

/// <summary>
/// Assumed to be .so files only
/// </summary>
public ITaskItem [] InputLibraries { get; set; }

public bool IncludeDebugSymbols { get; set; }

[Output]
public ITaskItem [] OutputLibraries { get; set; }

public override bool RunTask ()
{
if (InputLibraries == null || InputLibraries.Length == 0)
return true;

var output = new List<ITaskItem> (InputLibraries.Length);

foreach (var library in InputLibraries) {
var abi = MonoAndroidHelper.GetNativeLibraryAbi (library);
if (string.IsNullOrEmpty (abi)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

…especially when I look at this: XA4301_ABI_RID won't be emitted if the lib is in a directory named after an ABI we know about, %(RuntimeIdentifier) be damned.

Presumably if %(RuntimeIdentifier) doesn't "match", it's unusable, e.g. trying to use a "desktop" Linux .so on Android is doomed, because libc.so is in the wrong location (among other things). Should we "fail early" and error, and check before calling MonoAndroidHelper.GetNativeLibraryAbi()? Or should we "fail at runtime" and warn -- as is done in this PR -- if the .so can't actually be used?

Which dovetails back with the warning message: if an unsupported %(RuntimeIdentifier) means "this has no chance of working", then the message needs to state that, and the fix is to remove the offending .so file. If it has a chance of working, then XA4301_ABI_RID should mirror XA4301_ABI, and mention that moving the .so into a directory with the ABI name will work.

As-is, the XA4301_ABI_RID warning means nothing.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't believe the %(RuntimeIdentifier) metadata would be present in user projects. It would only be present from NuGet packages.

Do you think the existing checks here needs to be changed?

https://github.com/xamarin/xamarin-android/blob/866085a611579ae270289751e46d7388c97f4251/src/Xamarin.Android.Build.Tasks/Utilities/MonoAndroidHelper.cs#L286-L313

I think it will already check %(RuntimeIdentifier) before directory names.

var packageId = library.GetMetadata ("NuGetPackageId");
if (!string.IsNullOrEmpty (packageId)) {
Log.LogCodedWarning ("XA4301", library.ItemSpec, 0, Properties.Resources.XA4301_ABI_NuGet, library.ItemSpec, packageId);
} else {
Log.LogCodedWarning ("XA4301", library.ItemSpec, 0, Properties.Resources.XA4301_ABI, library.ItemSpec);
}
continue;
}
// Both libmono-android.debug.so and libmono-android.release.so are in InputLibraries.
// Use IncludeDebugSymbols to determine which one to include.
// We may eventually have files such as `libmono-android-checked+asan.release.so` as well.
var fileName = Path.GetFileNameWithoutExtension (library.ItemSpec);
if (fileName.StartsWith ("libmono-android", StringComparison.Ordinal)) {
if (fileName.EndsWith (".debug", StringComparison.Ordinal)) {
if (!IncludeDebugSymbols)
continue;
library.SetMetadata ("ArchiveFileName", "libmonodroid.so");
} else if (fileName.EndsWith (".release", StringComparison.Ordinal)) {
if (IncludeDebugSymbols)
continue;
library.SetMetadata ("ArchiveFileName", "libmonodroid.so");
}
}
output.Add (library);
}

OutputLibraries = output.ToArray ();

return !Log.HasLoggedErrors;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3882,6 +3882,9 @@ public void AbiNameInIntermediateOutputPath ()
using (var b = CreateApkBuilder (Path.Combine ("temp", TestName))) {
Assert.IsTrue (b.Build (proj), "Build should have succeeded.");
Assert.IsFalse (StringAssertEx.ContainsText (b.LastBuildOutput, Path.Combine ("armeabi", "libe_sqlite3.so")), "Build should not use `armeabi`.");
if (Builder.UseDotNet) {
StringAssertEx.Contains ("warning XA4301", b.LastBuildOutput, "Should get a XA4301 warning");
}
}
}

Expand Down
Loading