Skip to content

Commit

Permalink
[Xamarin.Android.Build.Tasks] $DOTNET_MODIFIABLE_ASSEMBLIES & FastDev (
Browse files Browse the repository at this point in the history
…#9451)

Context: https://devdiv.visualstudio.com/DevDiv/_build/results?buildId=10431207&view=ms.vss-test-web.build-test-results-tab&runId=114098346&resultId=100000&paneView=debug

The `FastDeployEnvironmentFiles(false)` test fails on PRs from forks,
because the "Fast Deployment" feature is not included in OSS builds:

	The Environment variable "DOTNET_MODIFIABLE_ASSEMBLIES" was not set.
	Expected: String containing "DOTNET_MODIFIABLE_ASSEMBLIES=Debug"
	But was:  "--------- beginning of main …

The problem appears to be related to target ordering:

  * `_GetGenerateJavaStubsInputs` : uses `@(AndroidEnvironment)` to
    set `@(_EnvironmentFiles)`

  * `_GetGenerateJavaStubs` : must have same `Inputs` as
    `_GeneratePackageManagerJava`

  * `_GeneratePackageManagerJava`: actually uses `@(_EnvironmentFiles)`

  * `_GenerateEnvironmentFiles` : creates a new
    `@(AndroidEnvironment)` file that won't be used!

But when using either a `Release` build or `Debug` build with
`FastDev` enabled, everything works fine.

To fix this, rework the target ordering:

  * `_GetGenerateJavaStubsInputs` depends on
    `_GenerateEnvironmentFiles`

    Unfortunately, this is now a circular dependency that causes an
    MSBuild error.

  * Break the cycle by updating `_GenerateEnvironmentFiles` to no
    longer depend upon `_ReadAndroidManifest`.

    It does not appear that `_ReadAndroidManifest` is needed by
    `_GenerateEnvironmentFiles`, as no properties created there are
    used.
  • Loading branch information
jonathanpeppers authored Oct 25, 2024
1 parent 69e6ed5 commit ee7c73e
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ properties that determine build ordering.
_ConvertCustomView;
$(_AfterConvertCustomView);
$(AfterGenerateAndroidManifest);
_GenerateEnvironmentFiles;
_ReadAndroidManifest;
_CompileJava;
_CreateApplicationSharedLibraries;
_CompileDex;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1455,7 +1455,7 @@ because xbuild doesn't support framework reference assemblies.
</_GenerateJavaStubsDependsOnTargets>
</PropertyGroup>

<Target Name="_GetGenerateJavaStubsInputs">
<Target Name="_GetGenerateJavaStubsInputs" DependsOnTargets="_GenerateEnvironmentFiles">
<ItemGroup>
<_GenerateJavaStubsInputs Include="@(_AndroidMSBuildAllProjects)" />
<_GenerateJavaStubsInputs Include="$(_ResolvedUserAssembliesHashFile)" />
Expand Down Expand Up @@ -1616,7 +1616,7 @@ because xbuild doesn't support framework reference assemblies.
</PrepareAbiItems>
</Target>

<Target Name="_GenerateEnvironmentFiles" DependsOnTargets="_ReadAndroidManifest">
<Target Name="_GenerateEnvironmentFiles">
<ItemGroup>
<_GeneratedAndroidEnvironment Include="__XA_PACKAGE_NAMING_POLICY__=$(AndroidPackageNamingPolicy)" />
<_GeneratedAndroidEnvironment Include="mono.enable_assembly_preload=0" Condition=" '$(AndroidEnablePreloadAssemblies)' != 'True' " />
Expand Down Expand Up @@ -1796,7 +1796,7 @@ because xbuild doesn't support framework reference assemblies.
_ManifestMerger;
_ConvertCustomView;
$(_AfterConvertCustomView);
_GenerateEnvironmentFiles;
_ReadAndroidManifest;
_GetLibraryImports;
_CheckDuplicateJavaLibraries;
UpdateAndroidAssets;
Expand Down
10 changes: 9 additions & 1 deletion tests/MSBuildDeviceIntegration/Tests/InstallAndRunTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -951,12 +951,20 @@ public void SupportDesugaringStaticInterfaceMethods ()
}

[Test]
public void FastDeployEnvironmentFiles ([Values (false, true)] bool isRelease)
[TestCase (false, true)]
[TestCase (false, false)]
[TestCase (true, false)]
public void FastDeployEnvironmentFiles (bool isRelease, bool embedAssembliesIntoApk)
{
if (embedAssembliesIntoApk) {
AssertCommercialBuild ();
}

var proj = new XamarinAndroidApplicationProject {
ProjectName = nameof (FastDeployEnvironmentFiles),
RootNamespace = nameof (FastDeployEnvironmentFiles),
IsRelease = isRelease,
EmbedAssembliesIntoApk = embedAssembliesIntoApk,
EnableDefaultItems = true,
OtherBuildItems = {
new BuildItem("AndroidEnvironment", "env.txt") {
Expand Down

0 comments on commit ee7c73e

Please sign in to comment.