Skip to content
Closed
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 @@ -13,13 +13,28 @@ This file contains the CoreCLR-specific MSBuild logic for .NET for Android.
</PropertyGroup>
<!-- Properties for $(OutputType)=Exe (Android Applications) -->
<PropertyGroup Condition=" '$(AndroidApplication)' == 'true' ">
<!-- Default to R2R Composite for CoreCLR Release mode -->
<PublishReadyToRun Condition=" '$(PublishReadyToRun)' == '' and '$(Configuration)' == 'Release' ">true</PublishReadyToRun>
<PublishReadyToRunComposite Condition=" '$(PublishReadyToRunComposite)' == '' and '$(PublishReadyToRun)' == 'true' ">true</PublishReadyToRunComposite>
<PublishReadyToRun Condition=" '$(PublishReadyToRun)' == '' ">true</PublishReadyToRun>
<PublishReadyToRunComposite Condition=" '$(PublishReadyToRunComposite)' == '' and '$(PublishReadyToRun)' == 'true' and '$(Configuration)' == 'Release' ">true</PublishReadyToRunComposite>
<PublishReadyToRunComposite Condition=" '$(PublishReadyToRunComposite)' == '' ">false</PublishReadyToRunComposite>
<_IsPublishing Condition=" '$(_IsPublishing)' == '' and '$(PublishReadyToRun)' == 'true' ">true</_IsPublishing>
<AllowReadyToRunWithoutRuntimeIdentifier Condition=" '$(PublishReadyToRun)' == 'true' and '$(RuntimeIdentifiers)' != '' ">true</AllowReadyToRunWithoutRuntimeIdentifier>
</PropertyGroup>

<Target Name="_ConfigureDebugReadyToRun"
Condition=" '$(AndroidApplication)' == 'true' and '$(Configuration)' == 'Debug' and '$(PublishReadyToRun)' == 'true' "
BeforeTargets="_PrepareForReadyToRunCompilation">
<ItemGroup>
<!-- Runtime-pack managed assemblies are the stable framework and Android SDK implementation set. -->
<_AndroidDebugReadyToRunFrameworkAssembly Include="@(RuntimePackAsset)"
Condition=" '%(RuntimePackAsset.AssetType)' == 'runtime' and '%(RuntimePackAsset.Extension)' == '.dll' " />
<_AndroidDebugReadyToRunExcludedAssembly Include="@(ResolvedFileToPublish->WithMetadataValue('PostprocessAssembly', 'true'))" />
<_AndroidDebugReadyToRunExcludedAssembly Remove="@(_AndroidDebugReadyToRunFrameworkAssembly)"
MatchOnMetadata="Filename;Extension"
MatchOnMetadataOptions="CaseInsensitive" />
<PublishReadyToRunExclude Include="@(_AndroidDebugReadyToRunExcludedAssembly->'%(Filename)%(Extension)')" />
</ItemGroup>
</Target>
Comment thread
kotlarmilos marked this conversation as resolved.

<!-- Default feature switches -->
<ItemGroup>
<RuntimeHostConfigurationOption Include="Microsoft.Android.Runtime.RuntimeFeature.IsMonoRuntime"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,43 @@ public void BuildBasicApplication ([Values] bool isRelease, [Values ("", "en_US.
}
}

[Test]
public void DebugReadyToRunCompilesOnlyFrameworkAssemblies ([Values ("android-x64", "android-arm64")] string rid)
{
if (IgnoreUnsupportedConfiguration (AndroidRuntime.CoreCLR)) {
return;
}

var proj = new XamarinAndroidApplicationProject ();
proj.SetRuntime (AndroidRuntime.CoreCLR);
proj.SetProperty ("RuntimeIdentifier", rid);

using var b = CreateApkBuilder ();
Assert.IsTrue (b.Build (proj), "Build should have succeeded.");

var abi = MonoAndroidHelper.RidToAbi (rid);
var assemblyDirectory = Path.Combine (Root, b.ProjectDirectory, proj.IntermediateOutputPath, "android", "assets", abi);
var frameworkAssembly = Path.Combine (assemblyDirectory, "System.Private.CoreLib.dll");
var userAssembly = Path.Combine (assemblyDirectory, $"{proj.ProjectName}.dll");
AssertReadyToRun (frameworkAssembly, expected: true, "System.Private.CoreLib.dll should be a ReadyToRun image.");
AssertReadyToRun (userAssembly, expected: false, $"{proj.ProjectName}.dll should remain IL.");

proj.MainActivity += Environment.NewLine + "// Force an incremental C# rebuild.";
proj.Touch ("MainActivity.cs");
Assert.IsTrue (b.Build (proj, doNotCleanupOnUpdate: true, saveProject: false), "Second build should have succeeded.");
Assert.IsTrue (b.Output.IsTargetSkipped ("_CreateR2RImages"),
"Changing a user assembly should not rerun crossgen2.");
AssertReadyToRun (frameworkAssembly, expected: true, "Cached System.Private.CoreLib.dll should remain a ReadyToRun image.");

static void AssertReadyToRun (string assembly, bool expected, string message)
{
FileAssert.Exists (assembly);
using var stream = File.OpenRead (assembly);
using var peReader = new System.Reflection.PortableExecutable.PEReader (stream);
Assert.AreEqual (expected, peReader.PEHeaders.CorHeader.ManagedNativeHeaderDirectory.Size > 0, message);
}
}

[Test]
public void BasicApplicationPublishReadyToRun ([Values] bool isComposite, [Values ("android-x64", "android-arm64")] string rid)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -517,6 +517,11 @@ Copyright (C) 2011-2012 Xamarin. All rights reserved.
/>
</Target>

<PropertyGroup>
<_AndroidWarnAboutReadyToRunFastDeployment
Condition=" '$(EmbedAssembliesIntoApk)' != 'True' And '$(PublishReadyToRun)' == 'True' And ('$(_AndroidRuntime)' != 'CoreCLR' Or '$(Configuration)' != 'Debug') ">true</_AndroidWarnAboutReadyToRunFastDeployment>
</PropertyGroup>

<Target Name="_CheckNonIdealAppConfigurations"
Condition=" '$(AndroidApplication)' == 'true' ">
<AndroidWarning Code="XA0119"
Expand All @@ -537,7 +542,7 @@ Copyright (C) 2011-2012 Xamarin. All rights reserved.
/>
<AndroidWarning Code="XA0119"
ResourceName="XA0119_ReadyToRun"
Condition=" '$(EmbedAssembliesIntoApk)' != 'True' And '$(PublishReadyToRun)' == 'True' "
Condition=" '$(_AndroidWarnAboutReadyToRunFastDeployment)' == 'true' "
/>
<AndroidWarning Code="XA1027"
ResourceName="XA1027"
Expand Down
Loading