From 9ca6c05b3e088df20ee1e1956fc36267825bb484 Mon Sep 17 00:00:00 2001 From: Marek Habersack Date: Thu, 16 Jan 2025 13:22:50 +0100 Subject: [PATCH] Import changes from https://github.com/dotnet/android/pull/9686/ --- .../Microsoft.Android.Runtime.proj | 1 - ...oft.Android.Sdk.AssemblyResolution.targets | 8 +++---- ...soft.Android.Sdk.DefaultProperties.targets | 14 +++++------ .../targets/Microsoft.Android.Sdk.targets | 2 +- .../Tasks/GenerateJavaStubs.cs | 11 +++++---- .../Utilities/JCWGenerator.cs | 4 ++-- .../Utilities/ManifestDocument.cs | 6 ++--- .../Xamarin.Android.Common.targets | 24 +++++++++---------- 8 files changed, 35 insertions(+), 35 deletions(-) diff --git a/build-tools/create-packs/Microsoft.Android.Runtime.proj b/build-tools/create-packs/Microsoft.Android.Runtime.proj index 5286015eb1f..a0847d27683 100644 --- a/build-tools/create-packs/Microsoft.Android.Runtime.proj +++ b/build-tools/create-packs/Microsoft.Android.Runtime.proj @@ -35,7 +35,6 @@ projects that use the Microsoft.Android framework in .NET 6+. <_RuntimeFlavorDirName Condition=" '$(AndroidRuntime)' == 'Mono' Or '$(AndroidRuntime)' == '' ">mono - <_AndroidRuntimePackAssemblies Include="$(_MonoAndroidNETDefaultOutDir)Java.Interop.dll" /> <_AndroidRuntimePackAssemblies Include="$(_MonoAndroidNETDefaultOutDir)Mono.Android.dll" /> diff --git a/src/Xamarin.Android.Build.Tasks/Microsoft.Android.Sdk/targets/Microsoft.Android.Sdk.AssemblyResolution.targets b/src/Xamarin.Android.Build.Tasks/Microsoft.Android.Sdk/targets/Microsoft.Android.Sdk.AssemblyResolution.targets index f74bada0b5b..e83d752bb8a 100644 --- a/src/Xamarin.Android.Build.Tasks/Microsoft.Android.Sdk/targets/Microsoft.Android.Sdk.AssemblyResolution.targets +++ b/src/Xamarin.Android.Build.Tasks/Microsoft.Android.Sdk/targets/Microsoft.Android.Sdk.AssemblyResolution.targets @@ -234,10 +234,10 @@ _ResolveAssemblies MSBuild target. <_ExcludedNativeLibraries Condition=" '$(_AndroidIncludeSystemGlobalizationNative)' != 'true' " Include="libSystem.Globalization.Native" /> <_ExcludedNativeLibraries Condition=" '$(_AndroidEnableNativeStackTracing)' != 'true' " Include="libxamarin-native-tracing" /> - <_ExcludedNativeLibraries Condition=" '$(AndroidRuntime)' == 'Mono' Or '$(AndroidRuntime)' == '' " Include="libnet-android.debug" /> - <_ExcludedNativeLibraries Condition=" '$(AndroidRuntime)' == 'Mono' Or '$(AndroidRuntime)' == '' " Include="libnet-android.release" /> - <_ExcludedNativeLibraries Condition=" '$(AndroidRuntime)' == 'CoreCLR' " Include="libmono-android.debug" /> - <_ExcludedNativeLibraries Condition=" '$(AndroidRuntime)' == 'CoreCLR' " Include="libmono-android.release" /> + <_ExcludedNativeLibraries Condition=" '$(_AndroidRuntime)' == 'Mono' Or '$(_AndroidRuntime)' == '' " Include="libnet-android.debug" /> + <_ExcludedNativeLibraries Condition=" '$(_AndroidRuntime)' == 'Mono' Or '$(_AndroidRuntime)' == '' " Include="libnet-android.release" /> + <_ExcludedNativeLibraries Condition=" '$(_AndroidRuntime)' == 'CoreCLR' " Include="libmono-android.debug" /> + <_ExcludedNativeLibraries Condition=" '$(_AndroidRuntime)' == 'CoreCLR' " Include="libmono-android.release" /> <_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..7cb847e2c52 100644 --- a/src/Xamarin.Android.Build.Tasks/Tasks/GenerateJavaStubs.cs +++ b/src/Xamarin.Android.Build.Tasks/Tasks/GenerateJavaStubs.cs @@ -93,7 +93,8 @@ public class GenerateJavaStubs : AndroidTask [Output] public ITaskItem[] GeneratedBinaryTypeMaps { get; set; } - public bool NativeAot { get; set; } + [Required] + public string AndroidRuntime { get; set; } = ""; internal const string AndroidSkipJavaStubGeneration = "AndroidSkipJavaStubGeneration"; @@ -296,8 +297,8 @@ Dictionary MaybeGetArchAssemblies (Dictionary additionalProviders) { - if (NativeAot) { - Log.LogDebugMessage ("Skipping MonoRuntimeProvider generation for NativeAot"); + if (!string.Equals (AndroidRuntime, "MonoVM", StringComparison.OrdinalIgnoreCase)) { + Log.LogDebugMessage ($"Skipping MonoRuntimeProvider generation for {AndroidRuntime}"); return; } @@ -354,7 +355,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 = string.Equals (AndroidRuntime, "MonoVM", StringComparison.OrdinalIgnoreCase) ? JavaPeerStyle.XAJavaInterop1 : JavaPeerStyle.JavaInterop1 }; bool success; 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..108bcb88c23 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 string AndroidRuntime { get; set; } = "MonoVM"; 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 (!string.Equals (AndroidRuntime, "MonoVM", StringComparison.OrdinalIgnoreCase)) { + //TODO: implement provider logic for non-Mono runtimes return []; } diff --git a/src/Xamarin.Android.Build.Tasks/Xamarin.Android.Common.targets b/src/Xamarin.Android.Build.Tasks/Xamarin.Android.Common.targets index 802ea2dd1e9..35075edce0f 100644 --- a/src/Xamarin.Android.Build.Tasks/Xamarin.Android.Common.targets +++ b/src/Xamarin.Android.Build.Tasks/Xamarin.Android.Common.targets @@ -298,8 +298,8 @@ Copyright (C) 2011-2012 Xamarin. All rights reserved. <_AndroidFastDeployEnvironmentFiles Condition=" '$(_AndroidFastDeployEnvironmentFiles)' == '' And '$(EmbedAssembliesIntoApk)' == 'False' ">True <_AndroidFastDeployEnvironmentFiles Condition=" '$(_AndroidFastDeployEnvironmentFiles)' == '' ">False - <_AndroidUseCLR Condition=" '$(AndroidRuntime)' == 'CoreCLR' ">True - <_AndroidUseCLR Condition=" '$(AndroidRuntime)' != 'CoreCLR' ">False + <_AndroidUseCLR Condition=" '$(_AndroidRuntime)' == 'CoreCLR' ">True + <_AndroidUseCLR Condition=" '$(_AndroidRuntime)' != 'CoreCLR' ">False @@ -331,9 +331,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) @@ -1359,12 +1359,12 @@ because xbuild doesn't support framework reference assemblies. - + <_RuntimeJar>$(MSBuildThisFileDirectory)\java_runtime_net6.jar <_RuntimeDex>$(MSBuildThisFileDirectory)\java_runtime_net6.dex - + <_RuntimeJar>$(MSBuildThisFileDirectory)\java_runtime_clr.jar <_RuntimeDex>$(MSBuildThisFileDirectory)\java_runtime_clr.dex @@ -1386,7 +1386,7 @@ because xbuild doesn't support framework reference assemblies. DependsOnTargets="_CollectRuntimeJarFilenames;$(_BeforeAddStaticResources);_GetMonoPlatformJarPath"> @@ -1505,7 +1505,7 @@ because xbuild doesn't support framework reference assemblies. @@ -1955,7 +1955,7 @@ because xbuild doesn't support framework reference assemblies. @@ -2032,13 +2032,13 @@ because xbuild doesn't support framework reference assemblies. - + <_ApplicationSharedLibrary Include="$(_AndroidApplicationSharedLibraryPath)%(_BuildTargetAbis.Identity)\libxamarin-app.so"> %(_BuildTargetAbis.Identity) - + <_ApplicationSharedLibrary Include="$(_AndroidApplicationSharedLibraryPath)%(_BuildTargetAbis.Identity)\libxamarin-app-clr.so"> %(_BuildTargetAbis.Identity)