Skip to content
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

[Mono.Android.Export] Include Java.Interop.DynamicCallbackCodeGenerator #34

Merged
merged 1 commit into from
May 11, 2016

Conversation

jonpryor
Copy link
Member

Mono.Android.Export.dll needs to include the
Java.Interop.DynamicCallbackCodeGenerator type for Mono.Android to
support [Java.Interop.Export] on method declarations, and the
DynamicCallbackCodeGenerator type was missing from
Mono.Android.Export.dll.

Include Callback.cs in the Mono.Android.Export.dll compilation so that
all required types are present to support [Export].

Mono.Android.Export.dll needs to include the
`Java.Interop.DynamicCallbackCodeGenerator` type for Mono.Android to
support [Java.Interop.Export] on method declarations, and the
DynamicCallbackCodeGenerator type was missing from
Mono.Android.Export.dll.

Include Callback.cs in the Mono.Android.Export.dll compilation so that
all required types are present to support [Export].
@dellis1972 dellis1972 merged commit 452d405 into dotnet:master May 11, 2016
radical pushed a commit that referenced this pull request May 8, 2018
…#34)

android.app.Application is special: Android contructs it before the
mono runtime has been initialized, requiring that the
[activation constructor][0] be used for all Android.App.Application
subclasses:

	[Application]
	partial class MyApp : Android.App.Application {
		public MyApp (IntPtr r, JniHandleOwnership transfer)
			: base (r, transfer)
		{
		}
	}

As a consequence of this, the Android.App.Application..ctor() default
constructor *is never used in normal use*, which means that the linker
is free to remove it.

This in turn means that in Release (linked) apps, *no* constructor
would be present in the `MyApp` Java Callable Wrappers, because
constructor generation requires that the binding assembly contain the
constructor to emit.

This is kinda/sorta fine, in that the Java compiler-provided default
constructor would still be emitted, allowing the `MyApp`
Java Callable Wrapper to be constructed, but that's only true so long
as the default constructor is sufficient.

Unfortunately, the default constructor isn't always sufficient: on
certain Android versions (API <= 15), the Application instance isn't
provided to the bootstrap `MonoRuntimeProvider.attachInfo()` method,
which means that the Android.App.Application.Context property returns
the wrong value.

Fixing this requires updating the Java Callable Wrapper of the
Application subclass to contain code to preserve the first Application
instance created in the process, which in turn means the default
Application constructor is no longer sufficient.

Update JavaCallableWrapperGenerator so that (in Debug builds) the
default Application constructor is skipped, and in *all*
configurations a custom constructor is generated within the
Java Callable Wrapper for android.app.Application subclasses.

[0]: https://developer.xamarin.com/guides/android/under_the_hood/architecture/#Java_Activation
@github-actions github-actions bot locked and limited conversation to collaborators Feb 2, 2024
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.

3 participants