Skip to content

Commit

Permalink
[One .NET] $(AndroidEnablePreloadAssemblies)=False by default (dotnet…
Browse files Browse the repository at this point in the history
…#5790)

Fixes: dotnet#5838
Context: e0da1f1

Partially reverts 522d7fb which
reverted d13d0f9

The [`$(AndroidEnablePreloadAssemblies)`][0] property controls
whether or not *all* `.dll` files contained within a `.apk` are
loaded during process startup.  *Not* doing so reduces process
startup times, which is desirable, but this also caused certain
Xamarin.Forms apps to fail to run as they previously had, as
not loading all assemblies during startup broke their
Dependency Injection infrastructure.

For .NET 6, we feel we have *some* "wiggle-room" to change default
semantics, so for .NET 6 projects set the default value of
`$(AndroidEnablePreloadAssemblies)` to False, so that assemblies are
*not* pre-loaded during process startup.

`$(AndroidEnablePreloadAssemblies)` can be set to True within the
app's `.csproj` file to return to "legacy" semantics.  This will
cause all assemblies to be loaded during startup, with a
commensurate increase in app startup overheads.

[0]: https://docs.microsoft.com/en-us/xamarin/android/deploy-test/building-apps/build-properties#androidenablepreloadassemblies
  • Loading branch information
grendello committed May 5, 2021
1 parent 3840ecc commit 8b1f534
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3938,7 +3938,11 @@ public void PackageNamingPolicy ([Values ("LowercaseMD5", "LowercaseCrc64")] str
Assert.IsTrue (b.Build (proj), "build should have succeeded.");
var environment = b.Output.GetIntermediaryPath (Path.Combine ("__environment__.txt"));
FileAssert.Exists (environment);
Assert.AreEqual ($"__XA_PACKAGE_NAMING_POLICY__={packageNamingPolicy}", File.ReadAllText (environment).Trim ());
if (Builder.UseDotNet) {
Assert.AreEqual ($"__XA_PACKAGE_NAMING_POLICY__={packageNamingPolicy}{Environment.NewLine}mono.enable_assembly_preload=0", File.ReadAllText (environment).Trim ());
} else {
Assert.AreEqual ($"__XA_PACKAGE_NAMING_POLICY__={packageNamingPolicy}", File.ReadAllText (environment).Trim ());
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,8 @@ Copyright (C) 2011-2012 Xamarin. All rights reserved.
<AndroidMakeBundleKeepTemporaryFiles Condition=" '$(AndroidMakeBundleKeepTemporaryFiles)' == '' ">False</AndroidMakeBundleKeepTemporaryFiles>

<!-- If true it will cause all the assemblies in the apk to be preloaded on startup time -->
<_AndroidEnablePreloadAssembliesDefault>True</_AndroidEnablePreloadAssembliesDefault>
<_AndroidEnablePreloadAssembliesDefault Condition=" '$(UsingAndroidNETSdk)' == 'true' ">False</_AndroidEnablePreloadAssembliesDefault>
<_AndroidEnablePreloadAssembliesDefault Condition=" '$(UsingAndroidNETSdk)' != 'true' ">True</_AndroidEnablePreloadAssembliesDefault>
<AndroidEnablePreloadAssemblies Condition=" '$(AndroidEnablePreloadAssemblies)' == '' ">$(_AndroidEnablePreloadAssembliesDefault)</AndroidEnablePreloadAssemblies>
<_NativeAssemblySourceDir>$(IntermediateOutputPath)android\</_NativeAssemblySourceDir>
<_AndroidUseNewTypemaps>True</_AndroidUseNewTypemaps>
Expand Down

0 comments on commit 8b1f534

Please sign in to comment.