[NativeAOT] set environment variables before the app .so is loaded #10709
+129
−18
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes: #10705
When a NativeAOT application starts up, certain portions of the managed startup
sequence are executed on the shared library load but before the
JNI_OnLoadfunction is invoked by Android.
Both
MonoVMandCoreCLRhosts set environment variables which may affect theway the application behaves before they initialize the managed runtime. Those
variables are set from within native code, using data generated at application
build time.
Until now, the
NativeAOThost followed suit, but it appears that we need toset certain variables (e.g. those related to running the startup hooks) before
the shared library is loaded.
The only location where we can do it is the
NativeAndroidRuntimeProviderJavaclass which is responsible for, eventually, loading the application shared
library.
This commit makes our build process emit application environment variables into
a Java file that's compiled together with the
NativeAndroidRuntimeProviderclass, at the same time removing those variables from the native code so that
we don't set the variables twice (a performance optimization, nothing more).
Testing shows that startup hooks are properly called with only the
DOTNET_STARTUP_HOOKSvariable set, which wasn't previously the case.