Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
a12b468
NativeAOT runtime skeleton
grendello Sep 1, 2025
a8219ea
Slowly figuring out NativeAOT build complexities
grendello Sep 1, 2025
f26572c
Link libc++ statically, include Android naot runtime in linking
grendello Sep 2, 2025
ab8022f
Don't link static libc++, it causes duplicate symbol errors with libs…
grendello Sep 2, 2025
b715c08
Add logging to the naot android runtime
grendello Sep 2, 2025
7283f26
Typo
grendello Sep 2, 2025
22fd8f8
Shared code (gc bridge, os bridge), p/invokes
grendello Sep 3, 2025
52a14d3
Host code sharing tweaks
grendello Sep 3, 2025
e2b8af3
Hook up NAOT-specific GC bridge code
grendello Sep 4, 2025
6001975
Enable ManagedTypeManager
grendello Sep 4, 2025
0fd2d86
Bring in the rest of relevant changes from #10402
grendello Sep 4, 2025
0db919c
Oops, forgot to add this one
grendello Sep 4, 2025
3c13a60
Temporarily add this, to be removed before merging
grendello Sep 4, 2025
94a8b96
Support logger configuration via the standard XA properties
grendello Sep 5, 2025
a04ba61
Don't generate compressed assemblies native sources, they aren't used
grendello Sep 5, 2025
1c39ab7
Beginnings of support for calling custom JNI_OnLoad functions
grendello Sep 5, 2025
a03f64c
Assembly source generation
grendello Sep 8, 2025
3dc1087
JNI on-load initialization of libraries
grendello Sep 9, 2025
8bb773e
Support for environment variables, TBC
grendello Sep 9, 2025
75ab6cb
[WIP] environment variables + system properties support
grendello Sep 10, 2025
1bafefa
Environment variables support complete
grendello Sep 10, 2025
dd37395
Address feedback
grendello Sep 11, 2025
71bfea0
Assembly compression is not used on NativeAOT
grendello Sep 11, 2025
3cbfa4f
Don't spam the logs
grendello Sep 11, 2025
cf4140f
Remove log spam
grendello Sep 11, 2025
68b9a88
Initialize max gref count
grendello Sep 11, 2025
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
1 change: 1 addition & 0 deletions Configuration.props
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,7 @@
<PropertyGroup>
<_MonoRuntimeFlavorDirName>mono</_MonoRuntimeFlavorDirName>
<_CLRRuntimeFlavorDirName>clr</_CLRRuntimeFlavorDirName>
<_NativeAotRuntimeFlavorDirName>nativeaot</_NativeAotRuntimeFlavorDirName>
<_RuntimeRedistDirName>redist</_RuntimeRedistDirName>
</PropertyGroup>

Expand Down
7 changes: 7 additions & 0 deletions Xamarin.Android.sln
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "native-mono", "src\native\n
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "native-clr", "src\native\native-clr.csproj", "{9B42A5BB-74CB-46E2-BCE0-AF763A792551}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "native-nativeaot", "src\native\native-nativeaot.csproj", "{645E1718-C8C4-4C23-8A49-5A37E4ECF7ED}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Tests", "Tests", "{CAB438D8-B0F5-4AF0-BEBD-9E2ADBD7B483}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Xamarin.ProjectTools", "src\Xamarin.Android.Build.Tasks\Tests\Xamarin.ProjectTools\Xamarin.ProjectTools.csproj", "{2DD1EE75-6D8D-4653-A800-0A24367F7F38}"
Expand Down Expand Up @@ -211,6 +213,10 @@ Global
{9B42A5BB-74CB-46E2-BCE0-AF763A792551}.Debug|AnyCPU.Build.0 = Debug|Any CPU
{9B42A5BB-74CB-46E2-BCE0-AF763A792551}.Release|AnyCPU.ActiveCfg = Release|Any CPU
{9B42A5BB-74CB-46E2-BCE0-AF763A792551}.Release|AnyCPU.Build.0 = Release|Any CPU
{645E1718-C8C4-4C23-8A49-5A37E4ECF7ED}.Debug|AnyCPU.ActiveCfg = Debug|Any CPU
{645E1718-C8C4-4C23-8A49-5A37E4ECF7ED}.Debug|AnyCPU.Build.0 = Debug|Any CPU
{645E1718-C8C4-4C23-8A49-5A37E4ECF7ED}.Release|AnyCPU.ActiveCfg = Release|Any CPU
{645E1718-C8C4-4C23-8A49-5A37E4ECF7ED}.Release|AnyCPU.Build.0 = Release|Any CPU
{2DD1EE75-6D8D-4653-A800-0A24367F7F38}.Debug|AnyCPU.ActiveCfg = Debug|Any CPU
{2DD1EE75-6D8D-4653-A800-0A24367F7F38}.Debug|AnyCPU.Build.0 = Debug|Any CPU
{2DD1EE75-6D8D-4653-A800-0A24367F7F38}.Release|AnyCPU.ActiveCfg = Release|Any CPU
Expand Down Expand Up @@ -383,6 +389,7 @@ Global
{D48EE8D0-0A0A-4493-AEF5-DAF5F8CF86AD} = {864062D3-A415-4A6F-9324-5820237BA058}
{53EE4C57-1C03-405A-8243-8DA539546C88} = {04E3E11E-B47D-4599-8AFC-50515A95E715}
{9B42A5BB-74CB-46E2-BCE0-AF763A792551} = {04E3E11E-B47D-4599-8AFC-50515A95E715}
{645E1718-C8C4-4C23-8A49-5A37E4ECF7ED} = {04E3E11E-B47D-4599-8AFC-50515A95E715}
{2DD1EE75-6D8D-4653-A800-0A24367F7F38} = {CAB438D8-B0F5-4AF0-BEBD-9E2ADBD7B483}
{53E4ABF0-1085-45F9-B964-DCAE4B819998} = {CAB438D8-B0F5-4AF0-BEBD-9E2ADBD7B483}
{38C762AB-8FD1-44DE-9855-26AAE7129DC3} = {864062D3-A415-4A6F-9324-5820237BA058}
Expand Down
3 changes: 3 additions & 0 deletions build-tools/create-packs/Microsoft.Android.Runtime.proj
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ projects that use the Microsoft.Android.Runtimes framework in .NET 6+.
BeforeTargets="GetFilesToPackage" >
<PropertyGroup>
<_RuntimeFlavorDirName Condition=" '$(AndroidRuntime)' == 'CoreCLR' ">$(_CLRRuntimeFlavorDirName)</_RuntimeFlavorDirName>
<_RuntimeFlavorDirName Condition=" '$(AndroidRuntime)' == 'NativeAOT' ">$(_NativeAotRuntimeFlavorDirName)</_RuntimeFlavorDirName>
<_RuntimeFlavorDirName Condition=" '$(AndroidRuntime)' == 'Mono' Or '$(AndroidRuntime)' == '' ">$(_MonoRuntimeFlavorDirName)</_RuntimeFlavorDirName>
<_ClangArch Condition=" '$(AndroidRID)' == 'android-arm64' ">aarch64</_ClangArch>
<_ClangArch Condition=" '$(AndroidRID)' == 'android-arm' ">arm</_ClangArch>
Expand Down Expand Up @@ -102,6 +103,8 @@ projects that use the Microsoft.Android.Runtimes framework in .NET 6+.
</ItemGroup>

<ItemGroup Condition=" '$(AndroidRuntime)' == 'NativeAOT' ">
<NativeRuntimeAsset Condition=" Exists('$(NativeRuntimeOutputRootDir)$(_RuntimeFlavorDirName)\$(AndroidRID)\libnaot-android.debug-static-debug.a') " Include="$(NativeRuntimeOutputRootDir)$(_RuntimeFlavorDirName)\$(AndroidRID)\libnaot-android.debug-static-debug.a" />
<NativeRuntimeAsset Condition=" Exists('$(NativeRuntimeOutputRootDir)$(_RuntimeFlavorDirName)\$(AndroidRID)\libnaot-android.release-static-release.a') " Include="$(NativeRuntimeOutputRootDir)$(_RuntimeFlavorDirName)\$(AndroidRID)\libnaot-android.release-static-release.a" />
<_AndroidRuntimePackAssemblies Include="$(_MonoAndroidNETOutputRoot)$(AndroidLatestStableApiLevel)\Microsoft.Android.Runtime.NativeAOT.dll" />
</ItemGroup>

Expand Down
6 changes: 6 additions & 0 deletions samples/NativeAOT/MainActivity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
using Android.Util;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Security.Cryptography;
using System.Text;

namespace NativeAOT;

Expand All @@ -27,5 +29,9 @@ protected override void OnCreate(Bundle? savedInstanceState)
if (t) {
throw new InvalidOperationException ("What happened?");
}

// This tests loading and initializing JNI shared libraries
var hashData = new byte[32];
SHA256.HashData(Encoding.ASCII.GetBytes("Hello World"), hashData.AsSpan());
}
}
28 changes: 28 additions & 0 deletions samples/NativeAOT/run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/bin/bash -e
CONFIG=Release
APK="bin/${CONFIG}/net10.0-android/net.dot.hellonativeaot-Signed.apk"
PACKAGE="net.dot.hellonativeaot"
ACTIVITY="my.MainActivity"

FAILED=no
rm -rf bin obj
../../dotnet-local.sh build -c ${CONFIG} -bl || FAILED=yes
../../dotnet-local.sh msbuild -v:diag msbuild.binlog > msbuild.txt
if [ "${FAILED}" == "yes" ]; then
echo Build failed
exit 1
fi

if [ -n "${1}" ]; then
exit 0
fi

adb uninstall "${PACKAGE}" || true
adb install -r -d --no-streaming --no-fastdeploy "${APK}"
#adb shell setprop debug.mono.log default,assembly,timing=bare
adb logcat -G 128M
adb logcat -c
adb shell am start -S --user "0" -a "android.intent.action.MAIN" -c "android.intent.category.LAUNCHER" -n "${PACKAGE}/${ACTIVITY}" -W
echo "Waiting for the app to start..."
sleep 5
adb logcat -d > log.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,15 @@ static partial class JavaInteropRuntime
{
static JniRuntime? runtime;

[DllImport("xa-internal-api")]
static extern int XA_Host_NativeAOT_JNI_OnLoad (IntPtr vm, IntPtr reserved);

[UnmanagedCallersOnly (EntryPoint="JNI_OnLoad")]
static int JNI_OnLoad (IntPtr vm, IntPtr reserved)
{
try {
AndroidLog.Print (AndroidLogLevel.Info, "JavaInteropRuntime", "JNI_OnLoad()");
XA_Host_NativeAOT_JNI_OnLoad (vm, reserved);
LogcatTextWriter.Init ();
return (int) JniVersion.v1_6;
}
Expand All @@ -29,6 +33,9 @@ static void JNI_OnUnload (IntPtr vm, IntPtr reserved)
runtime?.Dispose ();
}

[DllImport("xa-internal-api")]
static extern void XA_Host_NativeAOT_OnInit ();

// symbol name from `$(IntermediateOutputPath)obj/Release/osx-arm64/h-classes/net_dot_jni_hello_JavaInteropRuntime.h`
[UnmanagedCallersOnly (EntryPoint="Java_net_dot_jni_nativeaot_JavaInteropRuntime_init")]
static void init (IntPtr jnienv, IntPtr klass, IntPtr classLoader)
Expand All @@ -38,12 +45,11 @@ static void init (IntPtr jnienv, IntPtr klass, IntPtr classLoader)
var settings = new DiagnosticSettings ();
settings.AddDebugDotnetLog ();

var typeManager = new ManagedTypeManager ();
var options = new NativeAotRuntimeOptions {
EnvironmentPointer = jnienv,
ClassLoader = new JniObjectReference (classLoader),
TypeManager = typeManager,
ValueManager = new SimpleValueManager (),
ClassLoader = new JniObjectReference (classLoader, JniObjectReferenceType.Global),
TypeManager = new ManagedTypeManager (),
ValueManager = ManagedValueManager.GetOrCreateInstance (),
UseMarshalMemberBuilder = false,
JniGlobalReferenceLogWriter = settings.GrefLog,
JniLocalReferenceLogWriter = settings.LrefLog,
Expand All @@ -52,6 +58,7 @@ static void init (IntPtr jnienv, IntPtr klass, IntPtr classLoader)

// Entry point into Mono.Android.dll
JNIEnvInit.InitializeJniRuntime (runtime);
XA_Host_NativeAOT_OnInit ();

transition = new JniTransition (jnienv);

Expand All @@ -64,4 +71,4 @@ static void init (IntPtr jnienv, IntPtr klass, IntPtr classLoader)
}
transition.Dispose ();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ static NativeAotRuntimeOptions CreateJreVM (NativeAotRuntimeOptions builder)
builder.TypeManager ??= new ManagedTypeManager ();
#endif // NET

builder.ValueManager ??= new SimpleValueManager ();
builder.ObjectReferenceManager ??= new ManagedObjectReferenceManager (builder.JniGlobalReferenceLogWriter, builder.JniLocalReferenceLogWriter);
builder.ValueManager ??= ManagedValueManager.GetOrCreateInstance();
builder.ObjectReferenceManager ??= new Android.Runtime.AndroidObjectReferenceManager ();

if (builder.InvocationPointer != IntPtr.Zero || builder.EnvironmentPointer != IntPtr.Zero)
return builder;
Expand Down
5 changes: 3 additions & 2 deletions src/Mono.Android/Android.Runtime/AndroidRuntime.cs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,8 @@ public AndroidRuntimeOptions (IntPtr jnienv,
}
}

class AndroidObjectReferenceManager : JniRuntime.JniObjectReferenceManager {
// TODO: this shouldn't be public
public class AndroidObjectReferenceManager : JniRuntime.JniObjectReferenceManager {
Comment on lines +105 to +106
Copy link
Member

Choose a reason for hiding this comment

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

This is the only thing we'll need to fix ASAP next week.

public override int GlobalReferenceCount {
get {return RuntimeNativeMethods._monodroid_gref_get ();}
}
Expand Down Expand Up @@ -186,7 +187,7 @@ public override JniObjectReference CreateGlobalReference (JniObjectReference val
var from = log ? new StringBuilder (new StackTrace (true).ToString ()) : null;
int gc = RuntimeNativeMethods._monodroid_gref_log_new (value.Handle, ctype, r.Handle, ntype, tname, tid, from, 1);
if (gc >= JNIEnvInit.gref_gc_threshold) {
Logger.Log (LogLevel.Info, "monodroid-gc", gc + " outstanding GREFs. Performing a full GC!");
Logger.Log (LogLevel.Debug, "monodroid-gc", gc + " outstanding GREFs. Performing a full GC!");
System.GC.Collect ();
}

Expand Down
4 changes: 4 additions & 0 deletions src/Mono.Android/Android.Runtime/JNIEnvInit.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,10 @@ static Type TypeGetType (string typeName) =>
internal static void InitializeJniRuntime (JniRuntime runtime)
{
androidRuntime = runtime;
gref_gc_threshold = RuntimeNativeMethods._monodroid_max_gref_get ();
if (gref_gc_threshold != int.MaxValue) {
gref_gc_threshold = checked((gref_gc_threshold * 9) / 10);
}
Comment on lines +86 to +88
Copy link
Member

Choose a reason for hiding this comment

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

Is this taking 90% of this number for all runtimes? Do we need this change?

Copy link
Member

Choose a reason for hiding this comment

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

Other runtimes set gref_gc_threshold through different code path but it's still the same value (90% of the max GREF count).

SetSynchronizationContext ();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ This file contains the NativeAOT-specific MSBuild logic for .NET for Android.
<Project>

<UsingTask TaskName="Xamarin.Android.Tasks.SetNdkPathForIlc" AssemblyFile="$(_XamarinAndroidBuildTasksAssembly)" />
<UsingTask TaskName="Xamarin.Android.Tasks.GenerateNativeAotLibraryLoadAssemblerSources" AssemblyFile="$(_XamarinAndroidBuildTasksAssembly)" />
<UsingTask TaskName="Xamarin.Android.Tasks.GenerateNativeAotEnvironmentAssemblerSources" AssemblyFile="$(_XamarinAndroidBuildTasksAssembly)" />

<!-- Default property values for NativeAOT -->
<PropertyGroup>
Expand Down Expand Up @@ -93,6 +95,9 @@ This file contains the NativeAOT-specific MSBuild logic for .NET for Android.
<ItemGroup>
<!-- Android needs a proper soname property or it will refuse to load the library -->
<LinkerArg Include="&quot;-Wl,-soname,lib$(TargetName)$(NativeBinaryExt)&quot;" />
<LinkerArg Include="-Wl,--error-unresolved-symbols" />
<LinkerArg Include="-Wl,--no-undefined" />

<!-- Required for [UnmanagedCallersOnly] to work inside this assembly -->
<UnmanagedEntryPointsAssembly Include="Microsoft.Android.Runtime.NativeAOT" />
<!-- Give ILLink's output to ILC -->
Expand All @@ -110,7 +115,85 @@ This file contains the NativeAOT-specific MSBuild logic for .NET for Android.
<ResolvedFileToPublish Include="$(_NdkSysrootDir)libc++_shared.so" RuntimeIdentifier="$(RuntimeIdentifier)" />
Copy link
Member

Choose a reason for hiding this comment

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

Can this be removed? Are we statically linking libc++?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We're not right now because NativeAOT has a compatibility library that conflicts with static libc++. I want to explore a fix for this in a separate PR, since this one is too big already.

Copy link
Member

Choose a reason for hiding this comment

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

I agree it makes sense to split that off into separate PR. I suppose you can remove the shim libc++ from the list and then add the real one instead.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We need to keep both references to libc++_shared.so in this PR as we both need to link against it (the <LinkerArg> item) and package it (the ResolvedFileToPublish item)

<!-- Satellite assemblies -->
<IlcSatelliteAssembly Include="$(_OuterIntermediateSatelliteAssembliesWithTargetPath)" />

<LinkerArg Include="@(RuntimePackAsset->WithMetadataValue('Filename', 'libnaot-android.$(Configuration.ToLower())-static-$(Configuration.ToLower())'))" />
<LinkerArg Include="$(_NdkSysrootDir)libc++_shared.so" />

<!-- Every p/invoke using the `xa-internal-api` "library" will be called directly -->
<DirectPInvoke Include="xa-internal-api" />
</ItemGroup>
</Target>

<Target Name="_PrepareNativeAotAndroidAppInputs">
<ItemGroup>
<_PrivateBuildTargetAbi Condition=" '$(RuntimeIdentifier)' == 'android-arm64' " Include="arm64-v8a" />
<_PrivateBuildTargetAbi Condition=" '$(RuntimeIdentifier)' == 'android-x64' " Include="x86_64" />
</ItemGroup>

<PrepareAbiItems
BuildTargetAbis="@(_PrivateBuildTargetAbi)"
NativeSourcesDir="$(_NativeAssemblySourceDir)"
Debug="$(AndroidIncludeDebugSymbols)"
Mode="jni_init">
<Output TaskParameter="AssemblySources" ItemName="_PrivateJniInitFuncsAssemblySource" />
</PrepareAbiItems>

<PrepareAbiItems
BuildTargetAbis="@(_PrivateBuildTargetAbi)"
NativeSourcesDir="$(_NativeAssemblySourceDir)"
Debug="$(AndroidIncludeDebugSymbols)"
Mode="environment">
<Output TaskParameter="AssemblySources" ItemName="_PrivateEnvironmentAssemblySource" />
</PrepareAbiItems>

<ItemGroup>
<_PrivateJniInitFuncsNativeObjectFile Include="@(_PrivateJniInitFuncsAssemblySource->'$([System.IO.Path]::ChangeExtension('%(Identity)', '.o'))')">
<abi>%(_PrivateJniInitFuncsAssemblySource.abi)</abi>
</_PrivateJniInitFuncsNativeObjectFile>

<_PrivateEnvironmentNativeObjectFile Include="@(_PrivateEnvironmentAssemblySource->'$([System.IO.Path]::ChangeExtension('%(Identity)', '.o'))')">
<abi>%(_PrivateEnvironmentAssemblySource.abi)</abi>
</_PrivateEnvironmentNativeObjectFile>

<_PrivateAndroidNaotResolvedAssemblyFiles Include="@(ResolvedFileToPublish->Distinct())" Condition=" '%(ResolvedFileToPublish.Extension)' == '.dll' " />
</ItemGroup>
</Target>

<Target
Name="_GenerateNativeAotAndroidAppAssemblerSources"
DependsOnTargets="_GenerateEnvironmentFiles;_PrepareNativeAotAndroidAppInputs"
Inputs="@(_PrivateAndroidNaotResolvedAssemblyFiles);@(AndroidEnvironment);@(LibraryEnvironments)"
Outputs="@(_PrivateJniInitFuncsAssemblySource);@(_PrivateJniInitFuncsNativeObjectFile);@(_PrivateEnvironmentAssemblySource);@(_PrivateEnvironmentNativeObjectFile)">
<GenerateNativeAotLibraryLoadAssemblerSources
ResolvedAssemblies="@(_PrivateAndroidNaotResolvedAssemblyFiles)"
CustomJniInitFunctions="@(AndroidStaticJniInitFunction)"
OutputSources="@(_PrivateJniInitFuncsAssemblySource)" />

<GenerateNativeAotEnvironmentAssemblerSources
Debug="$(AndroidIncludeDebugSymbols)"
Environments="@(AndroidEnvironment);@(LibraryEnvironments)"
HttpClientHandlerType="$(AndroidHttpClientHandlerType)"
OutputSources="@(_PrivateEnvironmentAssemblySource)"
RID="$(RuntimeIdentifier)" />

<CompileNativeAssembly
Sources="@(_PrivateJniInitFuncsAssemblySource);@(_PrivateEnvironmentAssemblySource)"
DebugBuild="$(AndroidIncludeDebugSymbols)"
WorkingDirectory="$(_NativeAssemblySourceDir)"
AndroidBinUtilsDirectory="$(AndroidBinUtilsDirectory)" />

<ItemGroup>
<LinkerArg Include="@(_PrivateJniInitFuncsNativeObjectFile)" />
<LinkerArg Include="@(_PrivateEnvironmentNativeObjectFile)" />
</ItemGroup>
</Target>

<!-- Make sure we have a chance to generate our application-specific static library before linking
takes place. We must run after `IlcCompile`, which is a dependency of `LinkNative` -->
<Target
Name="_GenerateNativeAotAndroidAppLibrary"
AfterTargets="IlcCompile"
DependsOnTargets="_GenerateNativeAotAndroidAppAssemblerSources">
</Target>

<Target Name="_AndroidFixNativeLibraryFileName" AfterTargets="ComputeFilesToPublish">
Expand Down
28 changes: 1 addition & 27 deletions src/Xamarin.Android.Build.Tasks/Tasks/GenerateJavaStubs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -91,32 +91,6 @@ public override bool RunTask ()
return !Log.HasLoggedErrors;
}

XAAssemblyResolver MakeResolver (bool useMarshalMethods, AndroidTargetArch targetArch, Dictionary<string, ITaskItem> assemblies)
{
var readerParams = new ReaderParameters ();
if (useMarshalMethods) {
readerParams.ReadWrite = true;
readerParams.InMemory = true;
}

var res = new XAAssemblyResolver (targetArch, Log, loadDebugSymbols: true, loadReaderParameters: readerParams);
var uniqueDirs = new HashSet<string> (StringComparer.OrdinalIgnoreCase);

Log.LogDebugMessage ($"Adding search directories to new architecture {targetArch} resolver:");
foreach (var kvp in assemblies) {
string assemblyDir = Path.GetDirectoryName (kvp.Value.ItemSpec);
if (uniqueDirs.Contains (assemblyDir)) {
continue;
}

uniqueDirs.Add (assemblyDir);
res.SearchDirectories.Add (assemblyDir);
Log.LogDebugMessage ($" {assemblyDir}");
}

return res;
}

void Run (bool useMarshalMethods)
{
PackageNamingPolicy pnp;
Expand Down Expand Up @@ -253,7 +227,7 @@ internal static Dictionary<string, ITaskItem> MaybeGetArchAssemblies (Dictionary

(bool success, NativeCodeGenState? stubsState) GenerateJavaSourcesAndMaybeClassifyMarshalMethods (AndroidTargetArch arch, Dictionary<string, ITaskItem> assemblies, Dictionary<string, ITaskItem> userAssemblies, bool useMarshalMethods, bool generateJavaCode)
{
XAAssemblyResolver resolver = MakeResolver (useMarshalMethods, arch, assemblies);
XAAssemblyResolver resolver = MonoAndroidHelper.MakeResolver (Log, useMarshalMethods, arch, assemblies);
var tdCache = new TypeDefinitionCache ();
(List<TypeDefinition> allJavaTypes, List<TypeDefinition> javaTypesForJCW) = ScanForJavaTypes (resolver, tdCache, assemblies, userAssemblies, useMarshalMethods);
var jcwContext = new JCWGeneratorContext (arch, resolver, assemblies.Values, javaTypesForJCW, tdCache);
Expand Down
Loading
Loading