-
Notifications
You must be signed in to change notification settings - Fork 560
Description
We are now able to generate the Jni marshal methods by jnimarshalmethod-gen.exe. The usage of those can be enabled by AndroidGenerateJniMarshalMethods
property. (added in 106a621)
This specs describes how to also generate the methods by our build process when AndroidGenerateJniMarshalMethods
is true.
Generating the methods
We will generate these just before linking the application/library, by executing jnimarshalmethod-gen.exe
, similar to this:
<Target Name="_GenerateJniMarshalMethods"
Condition="'$(AndroidGenerateJniMarshalMethods)' == 'True' And '$(AndroidLinkMode)' != 'None'"
DependsOnTargets="_GetReferenceAssemblyPaths"
Inputs="@(ResolvedUserAssemblies->'$(MonoAndroidLinkerInputDir)%(Filename)%(Extension)')"
Outputs="$(_AndroidJniMarshalMethodsFlag)">
<Exec
Command="MONO_PATH=$(_XATargetFrameworkDirectories) $(MonoAndroidBinDirectory)\mono $(MonoAndroidBinDirectory)\..\jnimarshalmethod-gen.exe --jvm=$(AndroidJvmPath) -v @(ResolvedUserAssemblies->'$(MonoAndroidLinkerInputDir)%(Filename)%(Extension)', ' ')"
/>
<Exec
Command="MONO_PATH=$(_XATargetFrameworkDirectories) $(MonoAndroidBinDirectory)\mono $(MonoAndroidBinDirectory)\..\jnimarshalmethod-gen.exe --jvm=$(AndroidJvmPath) --types $(MonoAndroidMarshalMethodTypes) @(ResolvedAssemblies->'$(MonoAndroidLinkerInputDir)%(Filename)%(Extension)')"
Condition=" '%(ResolvedAssemblies.Filename)' == 'Mono.Android' "
/>
<Touch Files="$(_AndroidJniMarshalMethodsFlag)" AlwaysCreate="True" />
</Target>
It will generate the methods for user assemblies and also for Mono.Android.dll
.
AndroidJvmPath
We will need to know the AndroidJvmPath
value. We will get it by adding new JdkInfo
task to https://github.com/xamarin/xamarin-android/tree/master/src/Xamarin.Android.Build.Tasks/Tasks and it will use the JdkInfo
class (https://github.com/xamarin/xamarin-android-tools/blob/master/src/Xamarin.Android.Tools.AndroidSdk/JdkInfo.cs)
Mono.Android.dll start-up types
To avoid long builds by generating complete marshal methods for the whole Mono.Android.dll
, we will generate it for only few types, used during application startup. The file containing the list of types will be passed as $(MonoAndroidMarshalMethodTypes)
property and might be overridden
Current list:
# XA template startup, Mono.Android
#
Android.Runtime.UncaughtExceptionHandler
Java.Interop.TypeManager\+JavaTypeManager
Android.Views.View\+IOnClickListenerImplementor
# XForms template, Mono.Android
#
Android.Animation.ValueAnimator\+IAnimatorUpdateListenerImplementor
Java.Lang.Thread\+RunnableImplementor
Tests
To test the feature, we will enable it when building runtime and Xamarin.Forms test in Release and AOT configurations. This will also give use performance plots of the feature on regular basis.