diff --git a/src/Xamarin.Android.Build.Tasks/Microsoft.Android.Sdk/targets/Microsoft.Android.Sdk.DefaultProperties.targets b/src/Xamarin.Android.Build.Tasks/Microsoft.Android.Sdk/targets/Microsoft.Android.Sdk.DefaultProperties.targets index fd91967d398..06e54c8374e 100644 --- a/src/Xamarin.Android.Build.Tasks/Microsoft.Android.Sdk/targets/Microsoft.Android.Sdk.DefaultProperties.targets +++ b/src/Xamarin.Android.Build.Tasks/Microsoft.Android.Sdk/targets/Microsoft.Android.Sdk.DefaultProperties.targets @@ -24,13 +24,13 @@ See: https://github.com/dotnet/sdk/blob/955c0fc7b06e2fa34bacd076ed39f61e4fb61716/src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.Publish.targets#L16 --> <_GetChildProjectCopyToPublishDirectoryItems>false - - <_AndroidNativeAot Condition=" '$(PublishAot)' == 'true' ">true - <_AndroidNativeAot Condition=" '$(_AndroidNativeAot)' == '' ">false - false + false true + <_AndroidRuntime Condition=" '$(PublishAot)' == 'true' and '$(UseMonoRuntime)' != 'true' ">NativeAOT + <_AndroidRuntime Condition=" '$(PublishAot)' != 'true' and '$(UseMonoRuntime)' != 'true' ">CoreCLR + <_AndroidRuntime Condition=" '$(_AndroidRuntime)' == '' ">MonoVM - <_IsPublishing Condition=" '$(_IsPublishing)' == '' and '$(_AndroidNativeAot)' == 'true' ">true + <_IsPublishing Condition=" '$(_IsPublishing)' == '' and '$(_AndroidRuntime)' == 'NativeAOT' ">true $(AndroidMinimumSupportedApiLevel) @@ -88,7 +88,7 @@ SdkOnly None - full + full partial false true @@ -97,7 +97,7 @@ true - true + true true false <_AndroidXA1029 Condition=" '$(AotAssemblies)' != '' ">true diff --git a/src/Xamarin.Android.Build.Tasks/Microsoft.Android.Sdk/targets/Microsoft.Android.Sdk.targets b/src/Xamarin.Android.Build.Tasks/Microsoft.Android.Sdk/targets/Microsoft.Android.Sdk.targets index 31755d131e8..149c3ae323b 100644 --- a/src/Xamarin.Android.Build.Tasks/Microsoft.Android.Sdk/targets/Microsoft.Android.Sdk.targets +++ b/src/Xamarin.Android.Build.Tasks/Microsoft.Android.Sdk/targets/Microsoft.Android.Sdk.targets @@ -27,6 +27,6 @@ - + diff --git a/src/Xamarin.Android.Build.Tasks/Tasks/GenerateJavaStubs.cs b/src/Xamarin.Android.Build.Tasks/Tasks/GenerateJavaStubs.cs index b1ae8f6f750..766ec7c1465 100644 --- a/src/Xamarin.Android.Build.Tasks/Tasks/GenerateJavaStubs.cs +++ b/src/Xamarin.Android.Build.Tasks/Tasks/GenerateJavaStubs.cs @@ -93,13 +93,17 @@ public class GenerateJavaStubs : AndroidTask [Output] public ITaskItem[] GeneratedBinaryTypeMaps { get; set; } - public bool NativeAot { get; set; } + [Required] + public string AndroidRuntime { get; set; } = ""; + + AndroidRuntime androidRuntime; internal const string AndroidSkipJavaStubGeneration = "AndroidSkipJavaStubGeneration"; public override bool RunTask () { try { + androidRuntime = MonoAndroidHelper.ParseAndroidRuntime (AndroidRuntime); bool useMarshalMethods = !Debug && EnableMarshalMethods; Run (useMarshalMethods); } catch (XamarinAndroidException e) { @@ -296,8 +300,8 @@ Dictionary MaybeGetArchAssemblies (Dictionary additionalProviders) { - if (NativeAot) { - Log.LogDebugMessage ("Skipping MonoRuntimeProvider generation for NativeAot"); + if (androidRuntime != Xamarin.Android.Tasks.AndroidRuntime.MonoVM) { + Log.LogDebugMessage ($"Skipping MonoRuntimeProvider generation for: {androidRuntime}"); return; } @@ -354,7 +358,7 @@ IList MergeManifest (NativeCodeGenState codeGenState, Dictionary MergeManifest (NativeCodeGenState codeGenState, Dictionary allJavaTypes, List javaTypesForJCW) = ScanForJavaTypes (resolver, tdCache, assemblies, userAssemblies, useMarshalMethods); var jcwContext = new JCWGeneratorContext (arch, resolver, assemblies.Values, javaTypesForJCW, tdCache, useMarshalMethods); var jcwGenerator = new JCWGenerator (Log, jcwContext) { - NativeAot = NativeAot, + CodeGenerationTarget = androidRuntime == Xamarin.Android.Tasks.AndroidRuntime.MonoVM ? JavaPeerStyle.XAJavaInterop1 : JavaPeerStyle.JavaInterop1 }; bool success; diff --git a/src/Xamarin.Android.Build.Tasks/Utilities/AndroidRuntime.cs b/src/Xamarin.Android.Build.Tasks/Utilities/AndroidRuntime.cs new file mode 100644 index 00000000000..f487869025e --- /dev/null +++ b/src/Xamarin.Android.Build.Tasks/Utilities/AndroidRuntime.cs @@ -0,0 +1,8 @@ +namespace Xamarin.Android.Tasks; + +public enum AndroidRuntime +{ + MonoVM, + CoreCLR, + NativeAOT, +} diff --git a/src/Xamarin.Android.Build.Tasks/Utilities/JCWGenerator.cs b/src/Xamarin.Android.Build.Tasks/Utilities/JCWGenerator.cs index f088c6be137..dcbbedc8b45 100644 --- a/src/Xamarin.Android.Build.Tasks/Utilities/JCWGenerator.cs +++ b/src/Xamarin.Android.Build.Tasks/Utilities/JCWGenerator.cs @@ -44,7 +44,7 @@ class JCWGenerator readonly TaskLoggingHelper log; readonly JCWGeneratorContext context; - public bool NativeAot { get; set; } + public JavaPeerStyle CodeGenerationTarget { get; set; } = JavaPeerStyle.XAJavaInterop1; public MarshalMethodsClassifier? Classifier { get; private set; } @@ -127,7 +127,7 @@ bool GenerateCode (CallableWrapperType generator, TypeDefinition type, string ou bool ok = true; using var writer = MemoryStreamPool.Shared.CreateStreamWriter (); var writer_options = new CallableWrapperWriterOptions { - CodeGenerationTarget = NativeAot ? JavaPeerStyle.JavaInterop1 : JavaPeerStyle.XAJavaInterop1 + CodeGenerationTarget = CodeGenerationTarget }; try { diff --git a/src/Xamarin.Android.Build.Tasks/Utilities/ManifestDocument.cs b/src/Xamarin.Android.Build.Tasks/Utilities/ManifestDocument.cs index 41d97ae3c32..7cb28b4942e 100644 --- a/src/Xamarin.Android.Build.Tasks/Utilities/ManifestDocument.cs +++ b/src/Xamarin.Android.Build.Tasks/Utilities/ManifestDocument.cs @@ -94,7 +94,7 @@ internal class ManifestDocument public bool ForceDebuggable { get; set; } public string VersionName { get; set; } public IVersionResolver VersionResolver { get; set; } = new MonoAndroidHelperVersionResolver (); - public bool NativeAot { get; set; } + public AndroidRuntime AndroidRuntime { get; set; } string versionCode; @@ -673,8 +673,8 @@ XElement CreateApplicationElement (XElement manifest, string applicationClass, L IList AddMonoRuntimeProviders (XElement app) { - if (NativeAot) { - //TODO: implement NativeAOT provider logic + if (AndroidRuntime != AndroidRuntime.MonoVM) { + //TODO: implement provider logic for non-Mono runtimes return []; } diff --git a/src/Xamarin.Android.Build.Tasks/Utilities/MonoAndroidHelper.cs b/src/Xamarin.Android.Build.Tasks/Utilities/MonoAndroidHelper.cs index 833d2b3a534..7570dd63d26 100644 --- a/src/Xamarin.Android.Build.Tasks/Utilities/MonoAndroidHelper.cs +++ b/src/Xamarin.Android.Build.Tasks/Utilities/MonoAndroidHelper.cs @@ -809,5 +809,16 @@ public static string QuoteFileNameArgument (string fileName) builder.AppendFileNameIfNotNull (fileName); return builder.ToString (); } + + public static AndroidRuntime ParseAndroidRuntime (string androidRuntime) + { + if (string.Equals (androidRuntime, "CoreCLR", StringComparison.OrdinalIgnoreCase)) + return AndroidRuntime.CoreCLR; + if (string.Equals (androidRuntime, "NativeAOT", StringComparison.OrdinalIgnoreCase)) + return AndroidRuntime.NativeAOT; + + // Default runtime is MonoVM + return AndroidRuntime.MonoVM; + } } } diff --git a/src/Xamarin.Android.Build.Tasks/Xamarin.Android.Common.targets b/src/Xamarin.Android.Build.Tasks/Xamarin.Android.Common.targets index ba56eff5b92..b5c7c6c7c78 100644 --- a/src/Xamarin.Android.Build.Tasks/Xamarin.Android.Common.targets +++ b/src/Xamarin.Android.Build.Tasks/Xamarin.Android.Common.targets @@ -329,9 +329,9 @@ Copyright (C) 2011-2012 Xamarin. All rights reserved. true True False - True + True - False + False <_AndroidUseMarshalMethods Condition=" '$(AndroidIncludeDebugSymbols)' == 'True' ">False <_AndroidUseMarshalMethods Condition=" '$(AndroidIncludeDebugSymbols)' != 'True' ">$(AndroidEnableMarshalMethods) @@ -1379,7 +1379,7 @@ because xbuild doesn't support framework reference assemblies. DependsOnTargets="_CollectRuntimeJarFilenames;$(_BeforeAddStaticResources);_GetMonoPlatformJarPath"> @@ -1498,7 +1498,7 @@ because xbuild doesn't support framework reference assemblies. @@ -1947,7 +1947,7 @@ because xbuild doesn't support framework reference assemblies.