From c332b74b7da6dc8b73dde8bd8085b6d846b8fa3d Mon Sep 17 00:00:00 2001 From: Radek Doulik Date: Thu, 6 Sep 2018 20:38:38 +0200 Subject: [PATCH 01/21] [Xamarin.Android.Build.Tasks] Generate JNI marshal methods Implementation of https://github.com/xamarin/xamarin-android/issues/2138 Conditionally generate JNI marshal methods for user assemblies and Mono.Android.dll. It is enabled by setting `AndroidGenerateJniMarshalMethods` to *True*. Enable JNI marshal methods in Mono.Android runtime test in Release configuration. --- .../Test/Mono.Android-Tests.csproj | 1 + .../Tasks/ResolveSdksTask.cs | 30 +++++++++++++++++++ .../Xamarin.Android.Common.targets | 20 ++++++++++++- 3 files changed, 50 insertions(+), 1 deletion(-) diff --git a/src/Mono.Android/Test/Mono.Android-Tests.csproj b/src/Mono.Android/Test/Mono.Android-Tests.csproj index 8790afab08e..46fb57dc866 100644 --- a/src/Mono.Android/Test/Mono.Android-Tests.csproj +++ b/src/Mono.Android/Test/Mono.Android-Tests.csproj @@ -43,6 +43,7 @@ false true r8 + True diff --git a/src/Xamarin.Android.Build.Tasks/Tasks/ResolveSdksTask.cs b/src/Xamarin.Android.Build.Tasks/Tasks/ResolveSdksTask.cs index 5492234f690..e5d3d92a94c 100644 --- a/src/Xamarin.Android.Build.Tasks/Tasks/ResolveSdksTask.cs +++ b/src/Xamarin.Android.Build.Tasks/Tasks/ResolveSdksTask.cs @@ -30,6 +30,7 @@ using Microsoft.Build.Utilities; using System; using System.IO; +using System.Linq; namespace Xamarin.Android.Tasks { @@ -49,6 +50,9 @@ public class ResolveSdks : Task [Output] public string JavaSdkPath { get; set; } + [Output] + public string JdkJvmPath { get; set; } + [Output] public string MonoAndroidToolsPath { get; set; } @@ -92,12 +96,38 @@ public override bool Execute () return false; } + try { + Log.LogDebugMessage ($"JavaSdkPath: {JavaSdkPath}"); + Xamarin.Android.Tools.JdkInfo info = null; + try { + info = new Xamarin.Android.Tools.JdkInfo (JavaSdkPath); + } catch { + info = Xamarin.Android.Tools.JdkInfo.GetKnownSystemJdkInfos (this.CreateTaskLogger ()).FirstOrDefault (); + } + + JdkJvmPath = info.JdkJvmPath; + + if (string.IsNullOrEmpty(JdkJvmPath)) { + Log.LogCodedError ("XA5300", $"{nameof (JdkJvmPath)} is blank"); + return false; + } + + if (!File.Exists (JdkJvmPath)) { + Log.LogCodedError ("XA5300", $"JdkJvmPath not found at {JdkJvmPath}"); + return false; + } + } catch (Exception e) { + Log.LogCodedError ("XA5300", $"Unable to find {nameof (JdkJvmPath)}{Environment.NewLine}{e}"); + return false; + } + MonoAndroidHelper.TargetFrameworkDirectories = ReferenceAssemblyPaths; Log.LogDebugMessage ($"{nameof (ResolveSdks)} Outputs:"); Log.LogDebugMessage ($" {nameof (AndroidSdkPath)}: {AndroidSdkPath}"); Log.LogDebugMessage ($" {nameof (AndroidNdkPath)}: {AndroidNdkPath}"); Log.LogDebugMessage ($" {nameof (JavaSdkPath)}: {JavaSdkPath}"); + Log.LogDebugMessage ($" {nameof (JdkJvmPath)}: {JdkJvmPath}"); Log.LogDebugMessage ($" {nameof (MonoAndroidBinPath)}: {MonoAndroidBinPath}"); Log.LogDebugMessage ($" {nameof (MonoAndroidToolsPath)}: {MonoAndroidToolsPath}"); diff --git a/src/Xamarin.Android.Build.Tasks/Xamarin.Android.Common.targets b/src/Xamarin.Android.Build.Tasks/Xamarin.Android.Common.targets index 2da8db85a11..0c57782e73e 100755 --- a/src/Xamarin.Android.Build.Tasks/Xamarin.Android.Common.targets +++ b/src/Xamarin.Android.Build.Tasks/Xamarin.Android.Common.targets @@ -710,6 +710,7 @@ Copyright (C) 2011-2012 Xamarin. All rights reserved. + @@ -1172,6 +1173,7 @@ because xbuild doesn't support framework reference assemblies. <_AndroidResgenFlagFile>$(IntermediateOutputPath)R.cs.flag <_AndroidResFlagFile>$(IntermediateOutputPath)res.flag <_AndroidComponentResgenFlagFile>$(IntermediateOutputPath)Component.R.cs.flag + <_AndroidJniMarshalMethodsFlag>$(IntermediateOutputPath)jnimarshalmethods.flag <_AndroidLinkFlag>$(IntermediateOutputPath)link.flag <_AndroidApkPerAbiFlagFile>$(IntermediateOutputPath)android\bin\apk_per_abi.flag <_AndroidDebugKeyStoreFlag>$(IntermediateOutputPath)android_debug_keystore.flag @@ -2107,7 +2109,23 @@ because xbuild doesn't support framework reference assemblies. + DependsOnTargets="_ResolveAssemblies;_CreatePackageWorkspace;_GenerateJniMarshalMethods;_LinkAssembliesNoShrink;_LinkAssembliesShrink" /> + + + + + + + Date: Thu, 13 Sep 2018 14:49:47 +0200 Subject: [PATCH 02/21] Use --types option when generating marshal methods for Mono.Android --- .../Mono.Android.jnimarshalmethods.types | 10 ++++++++++ src/Mono.Android/Mono.Android.targets | 13 +++++++++++++ .../Xamarin.Android.Common.targets | 7 ++++++- 3 files changed, 29 insertions(+), 1 deletion(-) create mode 100644 src/Mono.Android/Mono.Android.jnimarshalmethods.types diff --git a/src/Mono.Android/Mono.Android.jnimarshalmethods.types b/src/Mono.Android/Mono.Android.jnimarshalmethods.types new file mode 100644 index 00000000000..7b338a6b98b --- /dev/null +++ b/src/Mono.Android/Mono.Android.jnimarshalmethods.types @@ -0,0 +1,10 @@ +# 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 diff --git a/src/Mono.Android/Mono.Android.targets b/src/Mono.Android/Mono.Android.targets index 1d7e0c1ab78..b55074073e4 100644 --- a/src/Mono.Android/Mono.Android.targets +++ b/src/Mono.Android/Mono.Android.targets @@ -159,4 +159,17 @@ AfterTargets="Clean"> + + <_JniMarshalMethodsTypesFile>Mono.Android.jnimarshalmethods.types + <_JniMarshalMethodsTypesInstallDirectory>$(XAInstallPrefix)xbuild\Xamarin\Android + + + + diff --git a/src/Xamarin.Android.Build.Tasks/Xamarin.Android.Common.targets b/src/Xamarin.Android.Build.Tasks/Xamarin.Android.Common.targets index 0c57782e73e..98d3b36cf13 100755 --- a/src/Xamarin.Android.Build.Tasks/Xamarin.Android.Common.targets +++ b/src/Xamarin.Android.Build.Tasks/Xamarin.Android.Common.targets @@ -317,6 +317,8 @@ Copyright (C) 2011-2012 Xamarin. All rights reserved. <_AndroidBuildPropertiesCache>$(IntermediateOutputPath)build.props <_AndroidDesignTimeBuildPropertiesCache>$(_AndroidIntermediateDesignTimeBuildDirectory)build.props False + True + $(MonoAndroidToolsDirectory)\Mono.Android.jnimarshalmethods.types False @@ -2120,8 +2122,11 @@ because xbuild doesn't support framework reference assemblies. + + <_MonoAndroidJniMarshalMethodsTypesOption Condition=" '$(AndroidMonoAndroidJniMarshalTypesEnabled)' == 'True' ">--types="$(AndroidMonoAndroidJniMarshalTypes)" + From 995247ab8585bcb344216d02f7cae2cbafb2d748 Mon Sep 17 00:00:00 2001 From: Radek Doulik Date: Fri, 14 Sep 2018 12:48:58 +0200 Subject: [PATCH 03/21] Added documentation for AndroidMonoAndroidJniMarshalTypes property Also removed the AndroidMonoAndroidJniMarshalTypesEnabled property and introduced special value `All` for AndroidMonoAndroidJniMarshalTypes. --- Documentation/guides/BuildProcess.md | 13 +++++++++++++ .../Xamarin.Android.Common.targets | 3 +-- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/Documentation/guides/BuildProcess.md b/Documentation/guides/BuildProcess.md index f910446adbb..06d81fe6982 100644 --- a/Documentation/guides/BuildProcess.md +++ b/Documentation/guides/BuildProcess.md @@ -723,6 +723,19 @@ when packaing Release applications. **Experimental**. Added in Xamarin.Android 8.4. The default value is False. +- **AndroidMonoAndroidJniMarshalTypes** – A property containing + a path to a file with list of regular expression patterns + describing for which types from Mono.Android assembly to generate + the marshal methods. + + By default it contains the path to the file with list of types + involved in the typical Xamarin.Android applications startup. + + Special value: `All`, means generate marshal methods for all the + types in the Mono.Android assembly + + Added in Xamarin.Android 9.2 + - **AndroidMultiDexClassListExtraArgs** – A string property which allows developers to pass additional arguments to the `com.android.multidex.MainDexListBuilder` when generating the diff --git a/src/Xamarin.Android.Build.Tasks/Xamarin.Android.Common.targets b/src/Xamarin.Android.Build.Tasks/Xamarin.Android.Common.targets index 98d3b36cf13..5b5c3583c02 100755 --- a/src/Xamarin.Android.Build.Tasks/Xamarin.Android.Common.targets +++ b/src/Xamarin.Android.Build.Tasks/Xamarin.Android.Common.targets @@ -317,7 +317,6 @@ Copyright (C) 2011-2012 Xamarin. All rights reserved. <_AndroidBuildPropertiesCache>$(IntermediateOutputPath)build.props <_AndroidDesignTimeBuildPropertiesCache>$(_AndroidIntermediateDesignTimeBuildDirectory)build.props False - True $(MonoAndroidToolsDirectory)\Mono.Android.jnimarshalmethods.types False @@ -2123,7 +2122,7 @@ because xbuild doesn't support framework reference assemblies. Command="MONO_PATH="$(_XATargetFrameworkDirectories)" "$(MonoAndroidBinDirectory)\mono" "$(MonoAndroidToolsDirectory)\jnimarshalmethod-gen.exe" --jvm="$(JdkJvmPath)" @(ResolvedUserAssemblies->'"$(MonoAndroidLinkerInputDir)%(Filename)%(Extension)"', ' ')" /> - <_MonoAndroidJniMarshalMethodsTypesOption Condition=" '$(AndroidMonoAndroidJniMarshalTypesEnabled)' == 'True' ">--types="$(AndroidMonoAndroidJniMarshalTypes)" + <_MonoAndroidJniMarshalMethodsTypesOption Condition=" '$(AndroidMonoAndroidJniMarshalTypes)' != 'All' ">--types="$(AndroidMonoAndroidJniMarshalTypes)" Date: Mon, 17 Sep 2018 15:41:02 +0200 Subject: [PATCH 04/21] Revert "Added documentation for AndroidMonoAndroidJniMarshalTypes property" This reverts commit 47eb647c3de39d936c5b930feb34683333331102. --- Documentation/guides/BuildProcess.md | 13 ------------- .../Xamarin.Android.Common.targets | 3 ++- 2 files changed, 2 insertions(+), 14 deletions(-) diff --git a/Documentation/guides/BuildProcess.md b/Documentation/guides/BuildProcess.md index 06d81fe6982..f910446adbb 100644 --- a/Documentation/guides/BuildProcess.md +++ b/Documentation/guides/BuildProcess.md @@ -723,19 +723,6 @@ when packaing Release applications. **Experimental**. Added in Xamarin.Android 8.4. The default value is False. -- **AndroidMonoAndroidJniMarshalTypes** – A property containing - a path to a file with list of regular expression patterns - describing for which types from Mono.Android assembly to generate - the marshal methods. - - By default it contains the path to the file with list of types - involved in the typical Xamarin.Android applications startup. - - Special value: `All`, means generate marshal methods for all the - types in the Mono.Android assembly - - Added in Xamarin.Android 9.2 - - **AndroidMultiDexClassListExtraArgs** – A string property which allows developers to pass additional arguments to the `com.android.multidex.MainDexListBuilder` when generating the diff --git a/src/Xamarin.Android.Build.Tasks/Xamarin.Android.Common.targets b/src/Xamarin.Android.Build.Tasks/Xamarin.Android.Common.targets index 5b5c3583c02..98d3b36cf13 100755 --- a/src/Xamarin.Android.Build.Tasks/Xamarin.Android.Common.targets +++ b/src/Xamarin.Android.Build.Tasks/Xamarin.Android.Common.targets @@ -317,6 +317,7 @@ Copyright (C) 2011-2012 Xamarin. All rights reserved. <_AndroidBuildPropertiesCache>$(IntermediateOutputPath)build.props <_AndroidDesignTimeBuildPropertiesCache>$(_AndroidIntermediateDesignTimeBuildDirectory)build.props False + True $(MonoAndroidToolsDirectory)\Mono.Android.jnimarshalmethods.types False @@ -2122,7 +2123,7 @@ because xbuild doesn't support framework reference assemblies. Command="MONO_PATH="$(_XATargetFrameworkDirectories)" "$(MonoAndroidBinDirectory)\mono" "$(MonoAndroidToolsDirectory)\jnimarshalmethod-gen.exe" --jvm="$(JdkJvmPath)" @(ResolvedUserAssemblies->'"$(MonoAndroidLinkerInputDir)%(Filename)%(Extension)"', ' ')" /> - <_MonoAndroidJniMarshalMethodsTypesOption Condition=" '$(AndroidMonoAndroidJniMarshalTypes)' != 'All' ">--types="$(AndroidMonoAndroidJniMarshalTypes)" + <_MonoAndroidJniMarshalMethodsTypesOption Condition=" '$(AndroidMonoAndroidJniMarshalTypesEnabled)' == 'True' ">--types="$(AndroidMonoAndroidJniMarshalTypes)" Date: Mon, 17 Sep 2018 15:41:14 +0200 Subject: [PATCH 05/21] Revert "Use --types option when generating marshal methods for Mono.Android" This reverts commit 66d34a1f2cee5e5786dcd3bbdfe5b5e5d35ef16a. --- .../Mono.Android.jnimarshalmethods.types | 10 ---------- src/Mono.Android/Mono.Android.targets | 13 ------------- .../Xamarin.Android.Common.targets | 7 +------ 3 files changed, 1 insertion(+), 29 deletions(-) delete mode 100644 src/Mono.Android/Mono.Android.jnimarshalmethods.types diff --git a/src/Mono.Android/Mono.Android.jnimarshalmethods.types b/src/Mono.Android/Mono.Android.jnimarshalmethods.types deleted file mode 100644 index 7b338a6b98b..00000000000 --- a/src/Mono.Android/Mono.Android.jnimarshalmethods.types +++ /dev/null @@ -1,10 +0,0 @@ -# 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 diff --git a/src/Mono.Android/Mono.Android.targets b/src/Mono.Android/Mono.Android.targets index b55074073e4..1d7e0c1ab78 100644 --- a/src/Mono.Android/Mono.Android.targets +++ b/src/Mono.Android/Mono.Android.targets @@ -159,17 +159,4 @@ AfterTargets="Clean"> - - <_JniMarshalMethodsTypesFile>Mono.Android.jnimarshalmethods.types - <_JniMarshalMethodsTypesInstallDirectory>$(XAInstallPrefix)xbuild\Xamarin\Android - - - - diff --git a/src/Xamarin.Android.Build.Tasks/Xamarin.Android.Common.targets b/src/Xamarin.Android.Build.Tasks/Xamarin.Android.Common.targets index 98d3b36cf13..0c57782e73e 100755 --- a/src/Xamarin.Android.Build.Tasks/Xamarin.Android.Common.targets +++ b/src/Xamarin.Android.Build.Tasks/Xamarin.Android.Common.targets @@ -317,8 +317,6 @@ Copyright (C) 2011-2012 Xamarin. All rights reserved. <_AndroidBuildPropertiesCache>$(IntermediateOutputPath)build.props <_AndroidDesignTimeBuildPropertiesCache>$(_AndroidIntermediateDesignTimeBuildDirectory)build.props False - True - $(MonoAndroidToolsDirectory)\Mono.Android.jnimarshalmethods.types False @@ -2122,11 +2120,8 @@ because xbuild doesn't support framework reference assemblies. - - <_MonoAndroidJniMarshalMethodsTypesOption Condition=" '$(AndroidMonoAndroidJniMarshalTypesEnabled)' == 'True' ">--types="$(AndroidMonoAndroidJniMarshalTypes)" - From 33e49a9991bceb293503673ff058342ecfbdfccb Mon Sep 17 00:00:00 2001 From: Radek Doulik Date: Mon, 17 Sep 2018 16:12:11 +0200 Subject: [PATCH 06/21] Add more framework assemblies we want to process --- .../Xamarin.Android.Common.targets | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/src/Xamarin.Android.Build.Tasks/Xamarin.Android.Common.targets b/src/Xamarin.Android.Build.Tasks/Xamarin.Android.Common.targets index 0c57782e73e..b668bc1f759 100755 --- a/src/Xamarin.Android.Build.Tasks/Xamarin.Android.Common.targets +++ b/src/Xamarin.Android.Build.Tasks/Xamarin.Android.Common.targets @@ -2116,13 +2116,18 @@ because xbuild doesn't support framework reference assemblies. DependsOnTargets="_GetReferenceAssemblyPaths;_SetLatestTargetFrameworkVersion" Inputs="@(ResolvedUserAssemblies->'$(MonoAndroidLinkerInputDir)%(Filename)%(Extension)')" Outputs="$(_AndroidJniMarshalMethodsFlag)"> - - + + <_JniFrameworkAssembly Include="Mono.Android.dll" /> + <_JniFrameworkAssembly Include="OpenTK-1.0.dll" /> + <_JniFrameworkAssembly Include="OpenTK.dll" /> + <_JniFrameworkAssembly Include="Xamarin.Android.NUnitLite.dll" /> + + + <_AssembliesToProcess Include="@(ResolvedUserAssemblies)" /> + <_AssembliesToProcess Include="@(ResolvedAssemblies)" Condition=" '%(Filename)' != '' And '@(_JniFrameworkAssembly)' != '' " /> + From 84594751c83b4dd4e20d394a5ffe8374537116ad Mon Sep 17 00:00:00 2001 From: Radek Doulik Date: Thu, 4 Oct 2018 09:32:20 +0200 Subject: [PATCH 07/21] [Mono.Android] Do not throw in JniValueManager The new marshaling code uses `JniValueManager`, so we don't want to trow here. Just keep it empty to make things work, until we have proper implementation of it. --- src/Mono.Android/Android.Runtime/AndroidRuntime.cs | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/Mono.Android/Android.Runtime/AndroidRuntime.cs b/src/Mono.Android/Android.Runtime/AndroidRuntime.cs index 8cb36d23360..3767a08d64f 100644 --- a/src/Mono.Android/Android.Runtime/AndroidRuntime.cs +++ b/src/Mono.Android/Android.Runtime/AndroidRuntime.cs @@ -363,12 +363,10 @@ public override void WaitForGCBridgeProcessing () public override void AddPeer (IJavaPeerable value) { - throw new NotImplementedException (); } public override void RemovePeer (IJavaPeerable value) { - throw new NotImplementedException (); } public override IJavaPeerable PeekPeer (JniObjectReference reference) @@ -378,17 +376,15 @@ public override IJavaPeerable PeekPeer (JniObjectReference reference) public override void CollectPeers () { - throw new NotImplementedException (); } public override void FinalizePeer (IJavaPeerable value) { - throw new NotImplementedException (); } public override List GetSurfacedPeers () { - throw new NotImplementedException (); + return null; } } } From ffc42deb8633a044cb50844bc0974583e719216c Mon Sep 17 00:00:00 2001 From: Radek Doulik Date: Tue, 9 Oct 2018 10:07:47 +0200 Subject: [PATCH 08/21] Bump Java.Interop and enable new JNI marshal methods in XF test Bump Java.Interop to get all the fixes for jnimarshalmethod-gen.exe and value manager marshaling. That fixes all the remaining issues in the XF test with JNI marshal methods enabled. Finally enable the marshaling in the XF test. --- .../Droid/Xamarin.Forms.Performance.Integration.Droid.csproj | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/Xamarin.Forms-Performance-Integration/Droid/Xamarin.Forms.Performance.Integration.Droid.csproj b/tests/Xamarin.Forms-Performance-Integration/Droid/Xamarin.Forms.Performance.Integration.Droid.csproj index 8ac906b0dca..3221823e9d5 100644 --- a/tests/Xamarin.Forms-Performance-Integration/Droid/Xamarin.Forms.Performance.Integration.Droid.csproj +++ b/tests/Xamarin.Forms-Performance-Integration/Droid/Xamarin.Forms.Performance.Integration.Droid.csproj @@ -42,6 +42,7 @@ false armeabi-v7a;x86 r8 + True From 348ec677b8fff54921c6d23249b3dc2e8d588288 Mon Sep 17 00:00:00 2001 From: Radek Doulik Date: Thu, 11 Oct 2018 13:57:24 +0200 Subject: [PATCH 09/21] Use --debug option when running jnimarshalmethod-gen.exe As new marshaling is an experimental feature, it is convenient to get more information when something breaks. --- src/Xamarin.Android.Build.Tasks/Xamarin.Android.Common.targets | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Xamarin.Android.Build.Tasks/Xamarin.Android.Common.targets b/src/Xamarin.Android.Build.Tasks/Xamarin.Android.Common.targets index b668bc1f759..a74520928d5 100755 --- a/src/Xamarin.Android.Build.Tasks/Xamarin.Android.Common.targets +++ b/src/Xamarin.Android.Build.Tasks/Xamarin.Android.Common.targets @@ -2127,7 +2127,7 @@ because xbuild doesn't support framework reference assemblies. <_AssembliesToProcess Include="@(ResolvedAssemblies)" Condition=" '%(Filename)' != '' And '@(_JniFrameworkAssembly)' != '' " /> From 8d2b9062c9f77d735426ecbeb7c1d02d2cdb3596 Mon Sep 17 00:00:00 2001 From: Radek Doulik Date: Fri, 12 Oct 2018 11:07:36 +0200 Subject: [PATCH 10/21] Bump Java.Interop to get ReflectionTypeLoadException fix --- external/Java.Interop | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/external/Java.Interop b/external/Java.Interop index 8ee34a353f3..adf4c485312 160000 --- a/external/Java.Interop +++ b/external/Java.Interop @@ -1 +1 @@ -Subproject commit 8ee34a353f35021e8639bec3c4b64415462e8b43 +Subproject commit adf4c48531259aa8f555c872df9bb5509f8a4c72 From d85923a24993a00d87bfa400efa8f6c864838730 Mon Sep 17 00:00:00 2001 From: Radek Doulik Date: Fri, 12 Oct 2018 11:36:42 +0200 Subject: [PATCH 11/21] Disable _GenerateJniMarshalMethods target on Windows Until we have the mono[w].exe in the bundle and are able to run jnimarshalmethod-gen.exe on Windows --- src/Xamarin.Android.Build.Tasks/Xamarin.Android.Common.targets | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Xamarin.Android.Build.Tasks/Xamarin.Android.Common.targets b/src/Xamarin.Android.Build.Tasks/Xamarin.Android.Common.targets index a74520928d5..86f38054c40 100755 --- a/src/Xamarin.Android.Build.Tasks/Xamarin.Android.Common.targets +++ b/src/Xamarin.Android.Build.Tasks/Xamarin.Android.Common.targets @@ -2112,7 +2112,7 @@ because xbuild doesn't support framework reference assemblies. DependsOnTargets="_ResolveAssemblies;_CreatePackageWorkspace;_GenerateJniMarshalMethods;_LinkAssembliesNoShrink;_LinkAssembliesShrink" /> From df7ba0cf970d654027717cd95902b9bf1a33436b Mon Sep 17 00:00:00 2001 From: Radek Doulik Date: Fri, 12 Oct 2018 13:00:24 +0200 Subject: [PATCH 12/21] Bump Java.Interop again to get the 2nd type loading fix --- external/Java.Interop | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/external/Java.Interop b/external/Java.Interop index adf4c485312..c04343867cb 160000 --- a/external/Java.Interop +++ b/external/Java.Interop @@ -1 +1 @@ -Subproject commit adf4c48531259aa8f555c872df9bb5509f8a4c72 +Subproject commit c04343867cbf51b20d8c949c29dda9a307b5d27e From 0b0dfb24a80246467ccca6b862653fe73b591a43 Mon Sep 17 00:00:00 2001 From: Radek Doulik Date: Fri, 12 Oct 2018 14:45:26 +0200 Subject: [PATCH 13/21] Add linker input directory to MONO_PATH That might hopefully fix the type loading problems --- src/Xamarin.Android.Build.Tasks/Xamarin.Android.Common.targets | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Xamarin.Android.Build.Tasks/Xamarin.Android.Common.targets b/src/Xamarin.Android.Build.Tasks/Xamarin.Android.Common.targets index 86f38054c40..244dd5995bd 100755 --- a/src/Xamarin.Android.Build.Tasks/Xamarin.Android.Common.targets +++ b/src/Xamarin.Android.Build.Tasks/Xamarin.Android.Common.targets @@ -2127,7 +2127,7 @@ because xbuild doesn't support framework reference assemblies. <_AssembliesToProcess Include="@(ResolvedAssemblies)" Condition=" '%(Filename)' != '' And '@(_JniFrameworkAssembly)' != '' " /> From f166d06f9b9ac7b06b7f9c554b883a1e400efed6 Mon Sep 17 00:00:00 2001 From: Radek Doulik Date: Mon, 15 Oct 2018 11:23:25 +0200 Subject: [PATCH 14/21] [tests] Run apk tests before JI tests JI tests overwrite Java.Runtime.Environment.dll.config. The original updated config file is needed for apk tests as some of them now use jnimarshalmethod-gen.exe tool. --- build-tools/scripts/RunTests.targets | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build-tools/scripts/RunTests.targets b/build-tools/scripts/RunTests.targets index e1f487aa5b4..99cbd0c74b8 100644 --- a/build-tools/scripts/RunTests.targets +++ b/build-tools/scripts/RunTests.targets @@ -147,10 +147,10 @@ <_RunParallelTestTarget Include="RunNUnitTests" /> - <_RunParallelTestTarget Include="RunJavaInteropTests" /> <_RunParallelTestTarget Include="RunApkTests" /> + <_RunTestTarget Include="RunJavaInteropTests" /> <_RunTestTarget Include="RunPerformanceTests" /> From 82c8d0cc7b991b27ea0a002541094ac57776fb9c Mon Sep 17 00:00:00 2001 From: Radek Doulik Date: Tue, 23 Oct 2018 11:14:09 +0200 Subject: [PATCH 15/21] Bump JI --- external/Java.Interop | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/external/Java.Interop b/external/Java.Interop index c04343867cb..23372eafa44 160000 --- a/external/Java.Interop +++ b/external/Java.Interop @@ -1 +1 @@ -Subproject commit c04343867cbf51b20d8c949c29dda9a307b5d27e +Subproject commit 23372eafa446baf93d80e14a58866d75ad557d26 From e349d6046195b46cdeddc8ad1bd744fce9190b48 Mon Sep 17 00:00:00 2001 From: Radek Doulik Date: Wed, 24 Oct 2018 10:13:47 +0200 Subject: [PATCH 16/21] Fix indentation --- src/Xamarin.Android.Build.Tasks/Tasks/ResolveSdksTask.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Xamarin.Android.Build.Tasks/Tasks/ResolveSdksTask.cs b/src/Xamarin.Android.Build.Tasks/Tasks/ResolveSdksTask.cs index e5d3d92a94c..941547548cc 100644 --- a/src/Xamarin.Android.Build.Tasks/Tasks/ResolveSdksTask.cs +++ b/src/Xamarin.Android.Build.Tasks/Tasks/ResolveSdksTask.cs @@ -107,7 +107,7 @@ public override bool Execute () JdkJvmPath = info.JdkJvmPath; - if (string.IsNullOrEmpty(JdkJvmPath)) { + if (string.IsNullOrEmpty (JdkJvmPath)) { Log.LogCodedError ("XA5300", $"{nameof (JdkJvmPath)} is blank"); return false; } From 4fee750ca3865fc5ee6a28efc442c28d373d709c Mon Sep 17 00:00:00 2001 From: Radek Doulik Date: Thu, 25 Oct 2018 14:04:49 +0200 Subject: [PATCH 17/21] Add AndroidGenerateJniMarshalMethodsAdditionalArguments To allow passing of additional arguments to the `jnimarshalmethod-gen.exe` tool. This comes handy when debugging, so that one can pass options like `-v`, `-d` or `--keeptemp` easily. --- src/Xamarin.Android.Build.Tasks/Xamarin.Android.Common.targets | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Xamarin.Android.Build.Tasks/Xamarin.Android.Common.targets b/src/Xamarin.Android.Build.Tasks/Xamarin.Android.Common.targets index 244dd5995bd..b7e41fa41df 100755 --- a/src/Xamarin.Android.Build.Tasks/Xamarin.Android.Common.targets +++ b/src/Xamarin.Android.Build.Tasks/Xamarin.Android.Common.targets @@ -2127,7 +2127,7 @@ because xbuild doesn't support framework reference assemblies. <_AssembliesToProcess Include="@(ResolvedAssemblies)" Condition=" '%(Filename)' != '' And '@(_JniFrameworkAssembly)' != '' " /> From 0b8e786e738a2f181bc397b06b73a02b44cc417b Mon Sep 17 00:00:00 2001 From: Radek Doulik Date: Thu, 25 Oct 2018 14:25:19 +0200 Subject: [PATCH 18/21] [Mono.Android] Add Android.Graphics.Color value marshaler Fixes https://github.com/xamarin/java.interop/issues/387 The custom value marshaler takes care about marshaling the `Color` as `int` and thus avoiding proxy objects and their marshaling. --- src/Mono.Android/Android.Graphics/Color.cs | 52 ++++++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/src/Mono.Android/Android.Graphics/Color.cs b/src/Mono.Android/Android.Graphics/Color.cs index 698b28a5c18..b31b454fd14 100644 --- a/src/Mono.Android/Android.Graphics/Color.cs +++ b/src/Mono.Android/Android.Graphics/Color.cs @@ -1,12 +1,18 @@ using System; using System.Collections.Generic; using System.Linq; +using System.Linq.Expressions; +using System.Reflection; using System.Text; using Android.Runtime; +using Java.Interop; +using Java.Interop.Expressions; + namespace Android.Graphics { + [JniValueMarshaler (typeof (ColorValueMarshaler))] public struct Color { private int color; @@ -386,4 +392,50 @@ public static void RGBToHSV (int red, int green, int blue, float[] hsv) public static Color YellowGreen { get { return new Color (0xFF9ACD32); } } #endregion } + + public class ColorValueMarshaler : JniValueMarshaler + { + public override Type MarshalType { + get { return typeof (int); } + } + + public override Color CreateGenericValue (ref JniObjectReference reference, JniObjectReferenceOptions options, Type targetType) + { + throw new NotImplementedException (); + } + + public override JniValueMarshalerState CreateGenericObjectReferenceArgumentState (Color value, ParameterAttributes synchronize) + { + throw new NotImplementedException (); + } + + public override void DestroyGenericArgumentState (Color value, ref JniValueMarshalerState state, ParameterAttributes synchronize) + { + throw new NotImplementedException (); + } + + public override Expression CreateParameterToManagedExpression (JniValueMarshalerContext context, ParameterExpression sourceValue, ParameterAttributes synchronize, Type targetType) + { + var c = typeof (Color).GetConstructor (new[]{typeof (int)}); + var v = Expression.Variable (typeof (Color), sourceValue.Name + "_val"); + context.LocalVariables.Add (v); + context.CreationStatements.Add (Expression.Assign (v, Expression.New (c, sourceValue))); + + return v; + } + + public override Expression CreateParameterFromManagedExpression (JniValueMarshalerContext context, ParameterExpression sourceValue, ParameterAttributes synchronize) + { + var r = Expression.Variable (MarshalType, sourceValue.Name + "_p"); + context.LocalVariables.Add (r); + context.CreationStatements.Add (Expression.Assign (r, Expression.Field (sourceValue, "color"))); + + return r; + } + + public override Expression CreateReturnValueFromManagedExpression (JniValueMarshalerContext context, ParameterExpression sourceValue) + { + return CreateParameterFromManagedExpression (context, sourceValue, 0); + } + } } From f924ac28dd53c83b6405eaba496e5c1285d1fb18 Mon Sep 17 00:00:00 2001 From: Radek Doulik Date: Fri, 26 Oct 2018 15:33:54 +0200 Subject: [PATCH 19/21] [Mono.Android] Add IJavaObject custom marshaler Once https://github.com/xamarin/java.interop/pull/389 is merged, it should fix https://github.com/xamarin/java.interop/issues/388 Example of updated marshalers: using Android.Runtime; using Java.Interop; using System; public static void n_setAdapter_Landroid_widget_ListAdapter_ (IntPtr __jnienv, IntPtr __this, IntPtr value) { JniTransition jniTransition = new JniTransition (__jnienv); JniRuntime runtime = default(JniRuntime); try { runtime = JniEnvironment.Runtime; JniRuntime.JniValueManager valueManager = runtime.ValueManager; valueManager.WaitForGCBridgeProcessing (); AbsListView value2 = valueManager.GetValue (__this); IListAdapter listAdapter2 = value2.Adapter = Java.Interop.JavaConvert.FromJniHandle (value, JniHandleOwnership.DoNotTransfer); } catch (Exception ex) when (runtime.ExceptionShouldTransitionToJni (ex)) { jniTransition.SetPendingException (ex); } finally { jniTransition.Dispose (); } } and using Android.Runtime; using Java.Interop; using System; public static IntPtr n_getAdapter (IntPtr __jnienv, IntPtr __this) { JniTransition jniTransition = new JniTransition (__jnienv); JniRuntime runtime = default(JniRuntime); try { runtime = JniEnvironment.Runtime; JniRuntime.JniValueManager valueManager = runtime.ValueManager; valueManager.WaitForGCBridgeProcessing (); AbsListView value = valueManager.GetValue (__this); IListAdapter adapter = value.Adapter; return JNIEnv.ToLocalJniHandle (adapter); } catch (Exception ex) when (runtime.ExceptionShouldTransitionToJni (ex)) { jniTransition.SetPendingException (ex); return default(IntPtr); } finally { jniTransition.Dispose (); } IntPtr intPtr = default(IntPtr); return intPtr; } --- .../Android.Runtime/IJavaObject.cs | 1 + .../IJavaObjectValueMarshaler.cs | 54 +++++++++++++++++++ src/Mono.Android/Mono.Android.csproj | 1 + 3 files changed, 56 insertions(+) create mode 100644 src/Mono.Android/Android.Runtime/IJavaObjectValueMarshaler.cs diff --git a/src/Mono.Android/Android.Runtime/IJavaObject.cs b/src/Mono.Android/Android.Runtime/IJavaObject.cs index 3a1154de82d..a3ea6f0a076 100644 --- a/src/Mono.Android/Android.Runtime/IJavaObject.cs +++ b/src/Mono.Android/Android.Runtime/IJavaObject.cs @@ -2,6 +2,7 @@ namespace Android.Runtime { + [Java.Interop.JniValueMarshaler (typeof (IJavaObjectValueMarshaler))] public interface IJavaObject : IDisposable { IntPtr Handle { get; } } diff --git a/src/Mono.Android/Android.Runtime/IJavaObjectValueMarshaler.cs b/src/Mono.Android/Android.Runtime/IJavaObjectValueMarshaler.cs new file mode 100644 index 00000000000..bf73dbd05a9 --- /dev/null +++ b/src/Mono.Android/Android.Runtime/IJavaObjectValueMarshaler.cs @@ -0,0 +1,54 @@ +using System; +using System.Linq; +using System.Linq.Expressions; +using System.Reflection; + +using Java.Interop; +using Java.Interop.Expressions; + +namespace Android.Runtime +{ + sealed class IJavaObjectValueMarshaler : JniValueMarshaler { + + internal static IJavaObjectValueMarshaler Instance = new IJavaObjectValueMarshaler (); + + public override IJavaObject CreateGenericValue (ref JniObjectReference reference, JniObjectReferenceOptions options, Type targetType) + { + throw new NotImplementedException (); + } + + public override JniValueMarshalerState CreateGenericObjectReferenceArgumentState (IJavaObject value, ParameterAttributes synchronize) + { + throw new NotImplementedException (); + } + + public override void DestroyGenericArgumentState (IJavaObject value, ref JniValueMarshalerState state, ParameterAttributes synchronize) + { + throw new NotImplementedException (); + } + + public override Expression CreateReturnValueFromManagedExpression (JniValueMarshalerContext context, ParameterExpression sourceValue) + { + return Expression.Call ( + typeof (JNIEnv), + "ToLocalJniHandle", + null, + sourceValue); + } + + public override Expression CreateParameterToManagedExpression (JniValueMarshalerContext context, ParameterExpression sourceValue, ParameterAttributes synchronize, Type targetType) + { + var r = Expression.Variable (targetType, sourceValue.Name + "_val"); + context.LocalVariables.Add (r); + context.CreationStatements.Add ( + Expression.Assign (r, + Expression.Call ( + typeof (JavaConvert), + "FromJniHandle", + new[]{targetType}, + sourceValue, + Expression.Field (null, typeof (JniHandleOwnership), "DoNotTransfer")))); + return r; + } + } +} diff --git a/src/Mono.Android/Mono.Android.csproj b/src/Mono.Android/Mono.Android.csproj index 9e43a2a5c95..2aa386c6827 100644 --- a/src/Mono.Android/Mono.Android.csproj +++ b/src/Mono.Android/Mono.Android.csproj @@ -83,6 +83,7 @@ JavaNativeTypeManager.cs + From dcf64213e085651f0fa7e299d81e95b76f5c6362 Mon Sep 17 00:00:00 2001 From: Radek Doulik Date: Fri, 26 Oct 2018 18:10:05 +0200 Subject: [PATCH 20/21] Bump Java.Interop to make use of IJavaObject custom marshaler --- external/Java.Interop | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/external/Java.Interop b/external/Java.Interop index 23372eafa44..ec2813acd69 160000 --- a/external/Java.Interop +++ b/external/Java.Interop @@ -1 +1 @@ -Subproject commit 23372eafa446baf93d80e14a58866d75ad557d26 +Subproject commit ec2813acd69b0a7cc35a1eee5a1f2ee10a57dfff From f5ff71c8448e45e35a20f21ffd786e1ccfd97bc5 Mon Sep 17 00:00:00 2001 From: Radek Doulik Date: Wed, 31 Oct 2018 13:12:00 +0100 Subject: [PATCH 21/21] Make sure the Java.Interop dll configs are OK ... when building the tests, which use jnimarshalmethod-gen.exe --- .../scripts/JavaInteropDllConfigs.targets | 26 +++++++++++++++++++ .../Test/Mono.Android-Tests.targets | 5 ++++ src/monodroid/monodroid.targets | 24 +---------------- ...Forms.Performance.Integration.Droid.csproj | 1 + ...orms.Performance.Integration.Droid.targets | 8 ++++++ 5 files changed, 41 insertions(+), 23 deletions(-) create mode 100644 build-tools/scripts/JavaInteropDllConfigs.targets create mode 100644 tests/Xamarin.Forms-Performance-Integration/Droid/Xamarin.Forms.Performance.Integration.Droid.targets diff --git a/build-tools/scripts/JavaInteropDllConfigs.targets b/build-tools/scripts/JavaInteropDllConfigs.targets new file mode 100644 index 00000000000..7be6a690ee4 --- /dev/null +++ b/build-tools/scripts/JavaInteropDllConfigs.targets @@ -0,0 +1,26 @@ + + + + + + + + + + <_DllMaps>@(_JavaInteropDllMapContent->'%(Identity)', '%0a ') + + + + diff --git a/src/Mono.Android/Test/Mono.Android-Tests.targets b/src/Mono.Android/Test/Mono.Android-Tests.targets index 3deadce4d45..107163fab3a 100644 --- a/src/Mono.Android/Test/Mono.Android-Tests.targets +++ b/src/Mono.Android/Test/Mono.Android-Tests.targets @@ -8,6 +8,7 @@ + + + diff --git a/src/monodroid/monodroid.targets b/src/monodroid/monodroid.targets index dc24a5ae8e8..366b643152e 100644 --- a/src/monodroid/monodroid.targets +++ b/src/monodroid/monodroid.targets @@ -4,6 +4,7 @@ + @@ -131,29 +132,6 @@ - - - - - - - <_DllMaps>@(_JavaInteropDllMapContent->'%(Identity)', '%0a ') - - - - diff --git a/tests/Xamarin.Forms-Performance-Integration/Droid/Xamarin.Forms.Performance.Integration.Droid.csproj b/tests/Xamarin.Forms-Performance-Integration/Droid/Xamarin.Forms.Performance.Integration.Droid.csproj index 3221823e9d5..27d0431ad43 100644 --- a/tests/Xamarin.Forms-Performance-Integration/Droid/Xamarin.Forms.Performance.Integration.Droid.csproj +++ b/tests/Xamarin.Forms-Performance-Integration/Droid/Xamarin.Forms.Performance.Integration.Droid.csproj @@ -155,6 +155,7 @@ + diff --git a/tests/Xamarin.Forms-Performance-Integration/Droid/Xamarin.Forms.Performance.Integration.Droid.targets b/tests/Xamarin.Forms-Performance-Integration/Droid/Xamarin.Forms.Performance.Integration.Droid.targets new file mode 100644 index 00000000000..b8651f44a98 --- /dev/null +++ b/tests/Xamarin.Forms-Performance-Integration/Droid/Xamarin.Forms.Performance.Integration.Droid.targets @@ -0,0 +1,8 @@ + + + + + +