Commit a9312d2
[Java.Interop.Tools.JavaCallableWrappers] Fix android.app.Application (#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_Activation1 parent 73eaddc commit a9312d2
File tree
1 file changed
+19
-1
lines changed- src/Java.Interop.Tools.JavaCallableWrappers/Java.Interop.Tools.JavaCallableWrappers
1 file changed
+19
-1
lines changedLines changed: 19 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
543 | 543 | | |
544 | 544 | | |
545 | 545 | | |
546 | | - | |
| 546 | + | |
| 547 | + | |
| 548 | + | |
547 | 549 | | |
| 550 | + | |
| 551 | + | |
| 552 | + | |
548 | 553 | | |
549 | 554 | | |
550 | 555 | | |
| |||
755 | 760 | | |
756 | 761 | | |
757 | 762 | | |
| 763 | + | |
| 764 | + | |
| 765 | + | |
| 766 | + | |
| 767 | + | |
| 768 | + | |
| 769 | + | |
| 770 | + | |
| 771 | + | |
| 772 | + | |
| 773 | + | |
| 774 | + | |
| 775 | + | |
758 | 776 | | |
759 | 777 | | |
760 | 778 | | |
| |||
0 commit comments