Skip to content

Commit 9ca6c05

Browse files
committed
Import changes from #9686
1 parent 394a016 commit 9ca6c05

8 files changed

+35
-35
lines changed

build-tools/create-packs/Microsoft.Android.Runtime.proj

-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ projects that use the Microsoft.Android framework in .NET 6+.
3535
<_RuntimeFlavorDirName Condition=" '$(AndroidRuntime)' == 'Mono' Or '$(AndroidRuntime)' == '' ">mono</_RuntimeFlavorDirName>
3636
</PropertyGroup>
3737

38-
<Message Text="Create packs: AndroidRuntime == '$(AndroidRuntime)'; _RuntimeFlavorDirName == '$(_RuntimeFlavorDirName)' " Importance="High" />
3938
<ItemGroup>
4039
<_AndroidRuntimePackAssemblies Include="$(_MonoAndroidNETDefaultOutDir)Java.Interop.dll" />
4140
<_AndroidRuntimePackAssemblies Include="$(_MonoAndroidNETDefaultOutDir)Mono.Android.dll" />

src/Xamarin.Android.Build.Tasks/Microsoft.Android.Sdk/targets/Microsoft.Android.Sdk.AssemblyResolution.targets

+4-4
Original file line numberDiff line numberDiff line change
@@ -234,10 +234,10 @@ _ResolveAssemblies MSBuild target.
234234
<!-- Filename without extension -->
235235
<_ExcludedNativeLibraries Condition=" '$(_AndroidIncludeSystemGlobalizationNative)' != 'true' " Include="libSystem.Globalization.Native" />
236236
<_ExcludedNativeLibraries Condition=" '$(_AndroidEnableNativeStackTracing)' != 'true' " Include="libxamarin-native-tracing" />
237-
<_ExcludedNativeLibraries Condition=" '$(AndroidRuntime)' == 'Mono' Or '$(AndroidRuntime)' == '' " Include="libnet-android.debug" />
238-
<_ExcludedNativeLibraries Condition=" '$(AndroidRuntime)' == 'Mono' Or '$(AndroidRuntime)' == '' " Include="libnet-android.release" />
239-
<_ExcludedNativeLibraries Condition=" '$(AndroidRuntime)' == 'CoreCLR' " Include="libmono-android.debug" />
240-
<_ExcludedNativeLibraries Condition=" '$(AndroidRuntime)' == 'CoreCLR' " Include="libmono-android.release" />
237+
<_ExcludedNativeLibraries Condition=" '$(_AndroidRuntime)' == 'Mono' Or '$(_AndroidRuntime)' == '' " Include="libnet-android.debug" />
238+
<_ExcludedNativeLibraries Condition=" '$(_AndroidRuntime)' == 'Mono' Or '$(_AndroidRuntime)' == '' " Include="libnet-android.release" />
239+
<_ExcludedNativeLibraries Condition=" '$(_AndroidRuntime)' == 'CoreCLR' " Include="libmono-android.debug" />
240+
<_ExcludedNativeLibraries Condition=" '$(_AndroidRuntime)' == 'CoreCLR' " Include="libmono-android.release" />
241241
</ItemGroup>
242242
<ProcessNativeLibraries
243243
InputLibraries="@(_ResolvedNativeLibraries)"

src/Xamarin.Android.Build.Tasks/Microsoft.Android.Sdk/targets/Microsoft.Android.Sdk.DefaultProperties.targets

+7-7
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,13 @@
2424
See: https://github.com/dotnet/sdk/blob/955c0fc7b06e2fa34bacd076ed39f61e4fb61716/src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.Publish.targets#L16
2525
-->
2626
<_GetChildProjectCopyToPublishDirectoryItems>false</_GetChildProjectCopyToPublishDirectoryItems>
27-
<!-- Define a $(_AndroidNativeAot) property, as the logic detecting NativeAOT may change in the future -->
28-
<_AndroidNativeAot Condition=" '$(PublishAot)' == 'true' ">true</_AndroidNativeAot>
29-
<_AndroidNativeAot Condition=" '$(_AndroidNativeAot)' == '' ">false</_AndroidNativeAot>
30-
<UseMonoRuntime Condition=" '$(_AndroidNativeAot)' == 'true' and '$(UseMonoRuntime)' == '' ">false</UseMonoRuntime>
27+
<UseMonoRuntime Condition=" '$(PublishAot)' == 'true' and '$(UseMonoRuntime)' == '' ">false</UseMonoRuntime>
3128
<UseMonoRuntime Condition=" '$(UseMonoRuntime)' == '' ">true</UseMonoRuntime>
29+
<_AndroidRuntime Condition=" '$(PublishAot)' == 'true' and '$(UseMonoRuntime)' != 'true' ">NativeAOT</_AndroidRuntime>
30+
<_AndroidRuntime Condition=" '$(PublishAot)' != 'true' and '$(UseMonoRuntime)' != 'true' ">CoreCLR</_AndroidRuntime>
31+
<_AndroidRuntime Condition=" '$(_AndroidRuntime)' == '' ">MonoVM</_AndroidRuntime>
3232
<!-- HACK: make dotnet restore include Microsoft.NETCore.App.Runtime.NativeAOT.linux-bionic-arm64 -->
33-
<_IsPublishing Condition=" '$(_IsPublishing)' == '' and '$(_AndroidNativeAot)' == 'true' ">true</_IsPublishing>
33+
<_IsPublishing Condition=" '$(_IsPublishing)' == '' and '$(_AndroidRuntime)' == 'NativeAOT' ">true</_IsPublishing>
3434

3535
<!-- Use $(AndroidMinimumSupportedApiLevel) for $(SupportedOSPlatformVersion) if unset -->
3636
<SupportedOSPlatformVersion Condition=" '$(SupportedOSPlatformVersion)' == '' ">$(AndroidMinimumSupportedApiLevel)</SupportedOSPlatformVersion>
@@ -88,7 +88,7 @@
8888
<AndroidLinkMode Condition=" '$(AndroidLinkMode)' == '' and '$(PublishTrimmed)' == 'true' ">SdkOnly</AndroidLinkMode>
8989
<AndroidLinkMode Condition=" '$(AndroidLinkMode)' == '' ">None</AndroidLinkMode>
9090
<!-- For compat with user code not marked trimmable, only trim opt-in by default. -->
91-
<TrimMode Condition=" '$(TrimMode)' == '' and ('$(AndroidLinkMode)' == 'Full' or '$(_AndroidNativeAot)' == 'true') ">full</TrimMode>
91+
<TrimMode Condition=" '$(TrimMode)' == '' and ('$(AndroidLinkMode)' == 'Full' or '$(_AndroidRuntime)' == 'NativeAOT') ">full</TrimMode>
9292
<TrimMode Condition="'$(TrimMode)' == ''">partial</TrimMode>
9393
<SuppressTrimAnalysisWarnings Condition=" '$(SuppressTrimAnalysisWarnings)' == '' and ('$(TrimMode)' == 'full' or '$(IsAotCompatible)' == 'true') ">false</SuppressTrimAnalysisWarnings>
9494
<SuppressTrimAnalysisWarnings Condition=" '$(SuppressTrimAnalysisWarnings)' == '' ">true</SuppressTrimAnalysisWarnings>
@@ -97,7 +97,7 @@
9797
<RuntimeIdentifier Condition=" '$(RuntimeIdentifiers)' != '' And '$(RuntimeIdentifier)' != '' " />
9898
<GenerateApplicationManifest Condition=" '$(GenerateApplicationManifest)' == '' ">true</GenerateApplicationManifest>
9999
<!-- Default to Mono's AOT in Release mode -->
100-
<RunAOTCompilation Condition=" '$(RunAOTCompilation)' == '' and '$(AotAssemblies)' == '' and '$(Configuration)' == 'Release' and '$(_AndroidNativeAot)' != 'true' ">true</RunAOTCompilation>
100+
<RunAOTCompilation Condition=" '$(RunAOTCompilation)' == '' and '$(AotAssemblies)' == '' and '$(Configuration)' == 'Release' and '$(_AndroidRuntime)' == 'MonoVM' ">true</RunAOTCompilation>
101101
<RunAOTCompilation Condition=" '$(RunAOTCompilation)' == '' and '$(AotAssemblies)' == 'true' ">true</RunAOTCompilation>
102102
<RunAOTCompilation Condition=" '$(RunAOTCompilation)' == '' ">false</RunAOTCompilation>
103103
<_AndroidXA1029 Condition=" '$(AotAssemblies)' != '' ">true</_AndroidXA1029>

src/Xamarin.Android.Build.Tasks/Microsoft.Android.Sdk/targets/Microsoft.Android.Sdk.targets

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,6 @@
2727
<Import Project="Microsoft.Android.Sdk.DefaultProperties.targets" />
2828
<Import Project="$(MSBuildThisFileDirectory)..\tools\Xamarin.Android.Common.Debugging.props"
2929
Condition="Exists('$(MSBuildThisFileDirectory)..\tools\Xamarin.Android.Common.Debugging.props')"/>
30-
<Import Project="Microsoft.Android.Sdk.NativeAOT.targets" Condition=" '$(_AndroidNativeAot)' == 'true' " />
30+
<Import Project="Microsoft.Android.Sdk.NativeAOT.targets" Condition=" '$(_AndroidRuntime)' == 'NativeAOT' " />
3131

3232
</Project>

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

+6-5
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,8 @@ public class GenerateJavaStubs : AndroidTask
9393
[Output]
9494
public ITaskItem[] GeneratedBinaryTypeMaps { get; set; }
9595

96-
public bool NativeAot { get; set; }
96+
[Required]
97+
public string AndroidRuntime { get; set; } = "";
9798

9899
internal const string AndroidSkipJavaStubGeneration = "AndroidSkipJavaStubGeneration";
99100

@@ -296,8 +297,8 @@ Dictionary<string, ITaskItem> MaybeGetArchAssemblies (Dictionary<AndroidTargetAr
296297

297298
void GenerateAdditionalProviderSources (NativeCodeGenState codeGenState, IList<string> additionalProviders)
298299
{
299-
if (NativeAot) {
300-
Log.LogDebugMessage ("Skipping MonoRuntimeProvider generation for NativeAot");
300+
if (!string.Equals (AndroidRuntime, "MonoVM", StringComparison.OrdinalIgnoreCase)) {
301+
Log.LogDebugMessage ($"Skipping MonoRuntimeProvider generation for {AndroidRuntime}");
301302
return;
302303
}
303304

@@ -354,7 +355,7 @@ IList<string> MergeManifest (NativeCodeGenState codeGenState, Dictionary<string,
354355
Debug = Debug,
355356
MultiDex = MultiDex,
356357
NeedsInternet = NeedsInternet,
357-
NativeAot = NativeAot,
358+
AndroidRuntime = AndroidRuntime,
358359
};
359360
// Only set manifest.VersionCode if there is no existing value in AndroidManifest.xml.
360361
if (manifest.HasVersionCode) {
@@ -388,7 +389,7 @@ IList<string> MergeManifest (NativeCodeGenState codeGenState, Dictionary<string,
388389
(List<TypeDefinition> allJavaTypes, List<TypeDefinition> javaTypesForJCW) = ScanForJavaTypes (resolver, tdCache, assemblies, userAssemblies, useMarshalMethods);
389390
var jcwContext = new JCWGeneratorContext (arch, resolver, assemblies.Values, javaTypesForJCW, tdCache, useMarshalMethods);
390391
var jcwGenerator = new JCWGenerator (Log, jcwContext) {
391-
NativeAot = NativeAot,
392+
CodeGenerationTarget = string.Equals (AndroidRuntime, "MonoVM", StringComparison.OrdinalIgnoreCase) ? JavaPeerStyle.XAJavaInterop1 : JavaPeerStyle.JavaInterop1
392393
};
393394
bool success;
394395

src/Xamarin.Android.Build.Tasks/Utilities/JCWGenerator.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ class JCWGenerator
4444
readonly TaskLoggingHelper log;
4545
readonly JCWGeneratorContext context;
4646

47-
public bool NativeAot { get; set; }
47+
public JavaPeerStyle CodeGenerationTarget { get; set; } = JavaPeerStyle.XAJavaInterop1;
4848

4949
public MarshalMethodsClassifier? Classifier { get; private set; }
5050

@@ -127,7 +127,7 @@ bool GenerateCode (CallableWrapperType generator, TypeDefinition type, string ou
127127
bool ok = true;
128128
using var writer = MemoryStreamPool.Shared.CreateStreamWriter ();
129129
var writer_options = new CallableWrapperWriterOptions {
130-
CodeGenerationTarget = NativeAot ? JavaPeerStyle.JavaInterop1 : JavaPeerStyle.XAJavaInterop1
130+
CodeGenerationTarget = CodeGenerationTarget
131131
};
132132

133133
try {

src/Xamarin.Android.Build.Tasks/Utilities/ManifestDocument.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ internal class ManifestDocument
9494
public bool ForceDebuggable { get; set; }
9595
public string VersionName { get; set; }
9696
public IVersionResolver VersionResolver { get; set; } = new MonoAndroidHelperVersionResolver ();
97-
public bool NativeAot { get; set; }
97+
public string AndroidRuntime { get; set; } = "MonoVM";
9898

9999
string versionCode;
100100

@@ -673,8 +673,8 @@ XElement CreateApplicationElement (XElement manifest, string applicationClass, L
673673

674674
IList<string> AddMonoRuntimeProviders (XElement app)
675675
{
676-
if (NativeAot) {
677-
//TODO: implement NativeAOT provider logic
676+
if (!string.Equals (AndroidRuntime, "MonoVM", StringComparison.OrdinalIgnoreCase)) {
677+
//TODO: implement provider logic for non-Mono runtimes
678678
return [];
679679
}
680680

src/Xamarin.Android.Build.Tasks/Xamarin.Android.Common.targets

+12-12
Original file line numberDiff line numberDiff line change
@@ -298,8 +298,8 @@ Copyright (C) 2011-2012 Xamarin. All rights reserved.
298298
<_AndroidFastDeployEnvironmentFiles Condition=" '$(_AndroidFastDeployEnvironmentFiles)' == '' And '$(EmbedAssembliesIntoApk)' == 'False' ">True</_AndroidFastDeployEnvironmentFiles>
299299
<_AndroidFastDeployEnvironmentFiles Condition=" '$(_AndroidFastDeployEnvironmentFiles)' == '' ">False</_AndroidFastDeployEnvironmentFiles>
300300

301-
<_AndroidUseCLR Condition=" '$(AndroidRuntime)' == 'CoreCLR' ">True</_AndroidUseCLR>
302-
<_AndroidUseCLR Condition=" '$(AndroidRuntime)' != 'CoreCLR' ">False</_AndroidUseCLR>
301+
<_AndroidUseCLR Condition=" '$(_AndroidRuntime)' == 'CoreCLR' ">True</_AndroidUseCLR>
302+
<_AndroidUseCLR Condition=" '$(_AndroidRuntime)' != 'CoreCLR' ">False</_AndroidUseCLR>
303303
</PropertyGroup>
304304

305305
<Choose>
@@ -331,9 +331,9 @@ Copyright (C) 2011-2012 Xamarin. All rights reserved.
331331
<AndroidUseAssemblyStore Condition=" '$(AndroidUseAssemblyStore)' == '' ">true</AndroidUseAssemblyStore>
332332
<AndroidAotEnableLazyLoad Condition=" '$(AndroidAotEnableLazyLoad)' == '' And '$(AotAssemblies)' == 'true' And '$(AndroidIncludeDebugSymbols)' != 'true' ">True</AndroidAotEnableLazyLoad>
333333
<AndroidEnableMarshalMethods Condition=" '$(AndroidEnableMarshalMethods)' == '' and ('$(UsingMicrosoftNETSdkRazor)' == 'true') ">False</AndroidEnableMarshalMethods>
334-
<AndroidEnableMarshalMethods Condition=" '$(AndroidEnableMarshalMethods)' == '' and '$(_AndroidNativeAot)' != 'true' ">True</AndroidEnableMarshalMethods>
334+
<AndroidEnableMarshalMethods Condition=" '$(AndroidEnableMarshalMethods)' == '' and '$(_AndroidRuntime)' != 'NativeAOT' ">True</AndroidEnableMarshalMethods>
335335
<!-- NOTE: temporarily disable for NativeAOT for now, to get build passing -->
336-
<AndroidEnableMarshalMethods Condition=" '$(AndroidEnableMarshalMethods)' == '' and '$(_AndroidNativeAot)' == 'true' ">False</AndroidEnableMarshalMethods>
336+
<AndroidEnableMarshalMethods Condition=" '$(AndroidEnableMarshalMethods)' == '' and '$(_AndroidRuntime)' == 'NativeAOT' ">False</AndroidEnableMarshalMethods>
337337
<_AndroidUseMarshalMethods Condition=" '$(AndroidIncludeDebugSymbols)' == 'True' ">False</_AndroidUseMarshalMethods>
338338
<_AndroidUseMarshalMethods Condition=" '$(AndroidIncludeDebugSymbols)' != 'True' ">$(AndroidEnableMarshalMethods)</_AndroidUseMarshalMethods>
339339
</PropertyGroup>
@@ -1359,12 +1359,12 @@ because xbuild doesn't support framework reference assemblies.
13591359
</Target>
13601360

13611361
<Target Name="_CollectRuntimeJarFilenames">
1362-
<PropertyGroup Condition=" '$(AndroidRuntime)' == 'Mono' Or '$(AndroidRuntime)' == '' ">
1362+
<PropertyGroup Condition=" '$(_AndroidRuntime)' == 'Mono' Or '$(_AndroidRuntime)' == '' ">
13631363
<_RuntimeJar>$(MSBuildThisFileDirectory)\java_runtime_net6.jar</_RuntimeJar>
13641364
<_RuntimeDex>$(MSBuildThisFileDirectory)\java_runtime_net6.dex</_RuntimeDex>
13651365
</PropertyGroup>
13661366

1367-
<PropertyGroup Condition=" '$(AndroidRuntime)' == 'CoreCLR' ">
1367+
<PropertyGroup Condition=" '$(_AndroidRuntime)' == 'CoreCLR' ">
13681368
<_RuntimeJar>$(MSBuildThisFileDirectory)\java_runtime_clr.jar</_RuntimeJar>
13691369
<_RuntimeDex>$(MSBuildThisFileDirectory)\java_runtime_clr.dex</_RuntimeDex>
13701370
</PropertyGroup>
@@ -1386,7 +1386,7 @@ because xbuild doesn't support framework reference assemblies.
13861386
DependsOnTargets="_CollectRuntimeJarFilenames;$(_BeforeAddStaticResources);_GetMonoPlatformJarPath">
13871387
<CopyResource ResourceName="machine.config" OutputPath="$(MonoAndroidIntermediateAssemblyDir)machine.config" />
13881388
<CopyResource
1389-
Condition=" '$(_AndroidNativeAot)' != 'true' "
1389+
Condition=" '$(_AndroidRuntime)' == 'MonoVM' "
13901390
ResourceName="MonoRuntimeProvider.Bundled.java"
13911391
OutputPath="$(_AndroidIntermediateJavaSourceDirectory)mono\MonoRuntimeProvider.java"
13921392
/>
@@ -1505,7 +1505,7 @@ because xbuild doesn't support framework reference assemblies.
15051505
</ItemGroup>
15061506

15071507
<GenerateJavaStubs
1508-
NativeAot="$(_AndroidNativeAot)"
1508+
AndroidRuntime="$(_AndroidRuntime)"
15091509
ResolvedAssemblies="@(_ResolvedAssemblies)"
15101510
ResolvedUserAssemblies="@(_ResolvedUserMonoAndroidAssemblies)"
15111511
ErrorOnCustomJavaObject="$(AndroidErrorOnCustomJavaObject)"
@@ -1735,7 +1735,7 @@ because xbuild doesn't support framework reference assemblies.
17351735
</Target>
17361736

17371737
<Target Name="_GeneratePackageManagerJava"
1738-
Condition=" '$(_AndroidNativeAot)' != 'true' "
1738+
Condition=" '$(_AndroidRuntime)' != 'NativeAOT' "
17391739
DependsOnTargets="$(_GeneratePackageManagerJavaDependsOn)"
17401740
Inputs="@(_GeneratePackageManagerJavaInputs)"
17411741
Outputs="$(_AndroidStampDirectory)_GeneratePackageManagerJava.stamp">
@@ -1955,7 +1955,7 @@ because xbuild doesn't support framework reference assemblies.
19551955

19561956
<!-- Shrink Mono.Android.dll by removing attribute only needed for GenerateJavaStubs -->
19571957
<RemoveRegisterAttribute
1958-
Condition="'$(AndroidLinkMode)' != 'None' and '$(AndroidIncludeDebugSymbols)' != 'true' and '$(AndroidStripILAfterAOT)' != 'true' and '$(_AndroidNativeAot)' != 'true' "
1958+
Condition="'$(AndroidLinkMode)' != 'None' and '$(AndroidIncludeDebugSymbols)' != 'true' and '$(AndroidStripILAfterAOT)' != 'true' and '$(_AndroidRuntime)' != 'NativeAOT' "
19591959
ShrunkFrameworkAssemblies="@(_ShrunkAssemblies)" />
19601960

19611961
<MakeDir Directories="$(MonoAndroidIntermediateAssemblyDir)shrunk" />
@@ -2032,13 +2032,13 @@ because xbuild doesn't support framework reference assemblies.
20322032
</Target>
20332033

20342034
<Target Name="_PrepareApplicationSharedLibraryItems">
2035-
<ItemGroup Condition=" '$(AndroidRuntime)' != 'CoreCLR' ">
2035+
<ItemGroup Condition=" '$(_AndroidRuntime)' != 'CoreCLR' ">
20362036
<_ApplicationSharedLibrary Include="$(_AndroidApplicationSharedLibraryPath)%(_BuildTargetAbis.Identity)\libxamarin-app.so">
20372037
<abi>%(_BuildTargetAbis.Identity)</abi>
20382038
</_ApplicationSharedLibrary>
20392039
</ItemGroup>
20402040

2041-
<ItemGroup Condition=" '$(AndroidRuntime)' == 'CoreCLR' ">
2041+
<ItemGroup Condition=" '$(_AndroidRuntime)' == 'CoreCLR' ">
20422042
<_ApplicationSharedLibrary Include="$(_AndroidApplicationSharedLibraryPath)%(_BuildTargetAbis.Identity)\libxamarin-app-clr.so">
20432043
<abi>%(_BuildTargetAbis.Identity)</abi>
20442044
</_ApplicationSharedLibrary>

0 commit comments

Comments
 (0)