Skip to content

Commit 599e09a

Browse files
[Xamarin.Android.Build.Tasks] $DOTNET_MODIFIABLE_ASSEMBLIES & FastDev (#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.
1 parent bf1cc73 commit 599e09a

File tree

3 files changed

+13
-5
lines changed

3 files changed

+13
-5
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ properties that determine build ordering.
7272
_ConvertCustomView;
7373
$(_AfterConvertCustomView);
7474
$(AfterGenerateAndroidManifest);
75-
_GenerateEnvironmentFiles;
75+
_ReadAndroidManifest;
7676
_CompileJava;
7777
_CreateApplicationSharedLibraries;
7878
_CompileDex;

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1470,7 +1470,7 @@ because xbuild doesn't support framework reference assemblies.
14701470
</_GenerateJavaStubsDependsOnTargets>
14711471
</PropertyGroup>
14721472

1473-
<Target Name="_GetGenerateJavaStubsInputs">
1473+
<Target Name="_GetGenerateJavaStubsInputs" DependsOnTargets="_GenerateEnvironmentFiles">
14741474
<ItemGroup>
14751475
<_GenerateJavaStubsInputs Include="@(_AndroidMSBuildAllProjects)" />
14761476
<_GenerateJavaStubsInputs Include="$(_ResolvedUserAssembliesHashFile)" />
@@ -1631,7 +1631,7 @@ because xbuild doesn't support framework reference assemblies.
16311631
</PrepareAbiItems>
16321632
</Target>
16331633

1634-
<Target Name="_GenerateEnvironmentFiles" DependsOnTargets="_ReadAndroidManifest">
1634+
<Target Name="_GenerateEnvironmentFiles">
16351635
<ItemGroup>
16361636
<_GeneratedAndroidEnvironment Include="__XA_PACKAGE_NAMING_POLICY__=$(AndroidPackageNamingPolicy)" />
16371637
<_GeneratedAndroidEnvironment Include="mono.enable_assembly_preload=0" Condition=" '$(AndroidEnablePreloadAssemblies)' != 'True' " />
@@ -1812,7 +1812,7 @@ because xbuild doesn't support framework reference assemblies.
18121812
_ManifestMerger;
18131813
_ConvertCustomView;
18141814
$(_AfterConvertCustomView);
1815-
_GenerateEnvironmentFiles;
1815+
_ReadAndroidManifest;
18161816
_GetLibraryImports;
18171817
_CheckDuplicateJavaLibraries;
18181818
UpdateAndroidAssets;

tests/MSBuildDeviceIntegration/Tests/InstallAndRunTests.cs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -951,12 +951,20 @@ public void SupportDesugaringStaticInterfaceMethods ()
951951
}
952952

953953
[Test]
954-
public void FastDeployEnvironmentFiles ([Values (false, true)] bool isRelease)
954+
[TestCase (false, true)]
955+
[TestCase (false, false)]
956+
[TestCase (true, false)]
957+
public void FastDeployEnvironmentFiles (bool isRelease, bool embedAssembliesIntoApk)
955958
{
959+
if (embedAssembliesIntoApk) {
960+
AssertCommercialBuild ();
961+
}
962+
956963
var proj = new XamarinAndroidApplicationProject {
957964
ProjectName = nameof (FastDeployEnvironmentFiles),
958965
RootNamespace = nameof (FastDeployEnvironmentFiles),
959966
IsRelease = isRelease,
967+
EmbedAssembliesIntoApk = embedAssembliesIntoApk,
960968
EnableDefaultItems = true,
961969
OtherBuildItems = {
962970
new BuildItem("AndroidEnvironment", "env.txt") {

0 commit comments

Comments
 (0)