Skip to content

Commit 706e4cc

Browse files
jonpryorgrendello
authored andcommitted
[Java.Interop] Make Java.Interop.Export use optional (#401)
The probing for `Java.Interop.Export.dll` performed within `JniRuntime.SetMarshalMemberBuilder()` can be costly if the `Java.Interop.Export.dll` assembly isn't present or cannot be found, which is *always* the case (currently) in Xamarin.Android, adding -- depending on device and profiler in use -- ~100ms to app startup (!). Add a new `JniRuntime.CreationOptions.UseMarshalMemberBuilder` property which controls whether `Java.Interop.Export.dll` is loaded *at all*. If true -- the default -- then `JniRuntime` *will* attempt to load `Java.Interop.Export.dll`, allowing the `JniRuntime.MarshalMemberBuilder` property to not throw a `NotSupportedException`. If `JniRuntime.CreationOptions.UseMarshalMemberBuilder` is false -- which will become the default in Xamarin.Android -- then `JniRuntime.SetMarshalMemberBuilder()` will do nothing.
1 parent 8337615 commit 706e4cc

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

src/Java.Interop/Java.Interop/JniRuntime.JniMarshalMemberBuilder.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ namespace Java.Interop {
1010
partial class JniRuntime {
1111

1212
partial class CreationOptions {
13+
public bool UseMarshalMemberBuilder {get; set;} = true;
1314
public JniMarshalMemberBuilder MarshalMemberBuilder {get; set;}
1415
}
1516

@@ -24,6 +25,10 @@ public JniMarshalMemberBuilder MarshalMemberBuilder {
2425

2526
partial void SetMarshalMemberBuilder (CreationOptions options)
2627
{
28+
if (!options.UseMarshalMemberBuilder) {
29+
return;
30+
}
31+
2732
if (options.MarshalMemberBuilder != null) {
2833
marshalMemberBuilder = SetRuntime (options.MarshalMemberBuilder);
2934
return;

0 commit comments

Comments
 (0)