Skip to content

[Mono.Android] pass in Context at startup #9776

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 6 commits into from

Conversation

jonathanpeppers
Copy link
Member

Calling Android.App.Application.Context currently reads the mono.MonoPackageManager.Context field, which is set on startup by a ContentProvider. mono.MonoPackageManager does not exist in NativeAOT (or CoreCLR), so let's approach this differently.

Each ContentProvider can pass in the context to JNIEnvInit on startup, then the first call to Android.App.Application.Context does not have to read a field any longer as we already have the handle in managed code.

Calling `Android.App.Application.Context` currently reads the
`mono.MonoPackageManager.Context` field, which is set on startup by a
`ContentProvider`. `mono.MonoPackageManager` does not exist in
NativeAOT (or CoreCLR), so let's approach this differently.

Each `ContentProvider` can pass in the context to `JNIEnvInit` on
startup, then the first call to `Android.App.Application.Context` does
not have to read a field any longer as we already have the handle in
managed code.
@jonathanpeppers
Copy link
Member Author

APK tests crash on launch:

02-10 19:17:10.878  7036  7057 F droid.NET_Test: java_vm_ext.cc:570] JNI DETECTED ERROR IN APPLICATION: use of invalid jobject 0x7ffc54212520
02-10 19:17:10.878  7036  7057 F droid.NET_Test: java_vm_ext.cc:570]     from void crc643df67da7b13bb6b1.TestInstrumentation_1.n_onStart()

@jonathanpeppers
Copy link
Member Author

Going to close this in favor of:

I think the other PR is just simpler and changes no semantics / ordering.

@github-actions github-actions bot locked and limited conversation to collaborators Mar 14, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant