From 02b19bb1be52eec728a82803caed6b65d0acd79c Mon Sep 17 00:00:00 2001 From: Radek Doulik Date: Mon, 14 Dec 2020 22:40:16 +0100 Subject: [PATCH 1/6] Conditionaly exclude `ManagedPeer.Init` call Driven by `XA_JI_EXCLUDE`, which will be defined in Xamarin.Android.props, when building for XA. --- Directory.Build.props | 4 ++++ src/Java.Interop/Java.Interop-MonoAndroid.csproj | 4 ++-- src/Java.Interop/Java.Interop.csproj | 2 +- src/Java.Interop/Java.Interop/JniRuntime.cs | 4 ++-- 4 files changed, 9 insertions(+), 5 deletions(-) diff --git a/Directory.Build.props b/Directory.Build.props index fa711a23d..60dce41d7 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -23,6 +23,10 @@ Project="$(_OutputPath)MonoInfo.props" Condition="Exists('$(_OutputPath)MonoInfo.props')" /> + False obj\ diff --git a/src/Java.Interop/Java.Interop-MonoAndroid.csproj b/src/Java.Interop/Java.Interop-MonoAndroid.csproj index 4ba37e451..7d7c6d08f 100644 --- a/src/Java.Interop/Java.Interop-MonoAndroid.csproj +++ b/src/Java.Interop/Java.Interop-MonoAndroid.csproj @@ -23,7 +23,7 @@ full false ..\..\bin\Debug - DEBUG;INTEROP;FEATURE_JNIENVIRONMENT_JI_PINVOKES;FEATURE_JNIOBJECTREFERENCE_INTPTRS;INTERNAL_NULLABLE_ATTRIBUTES + DEBUG;INTEROP;FEATURE_JNIENVIRONMENT_JI_PINVOKES;FEATURE_JNIOBJECTREFERENCE_INTPTRS;INTERNAL_NULLABLE_ATTRIBUTES;$(JavaInteropDefineConstants) prompt 4 false @@ -39,7 +39,7 @@ prompt 4 false - INTEROP;FEATURE_JNIENVIRONMENT_JI_PINVOKES;FEATURE_JNIOBJECTREFERENCE_INTPTRS;INTERNAL_NULLABLE_ATTRIBUTES + INTEROP;FEATURE_JNIENVIRONMENT_JI_PINVOKES;FEATURE_JNIOBJECTREFERENCE_INTPTRS;INTERNAL_NULLABLE_ATTRIBUTES;$(JavaInteropDefineConstants) true enable ..\..\bin\Release\Java.Interop.xml diff --git a/src/Java.Interop/Java.Interop.csproj b/src/Java.Interop/Java.Interop.csproj index d3b589f1a..1bffbb24b 100644 --- a/src/Java.Interop/Java.Interop.csproj +++ b/src/Java.Interop/Java.Interop.csproj @@ -5,7 +5,7 @@ 1591 true ..\..\product.snk - INTEROP;FEATURE_JNIENVIRONMENT_JI_PINVOKES;FEATURE_JNIOBJECTREFERENCE_INTPTRS;INTERNAL_NULLABLE_ATTRIBUTES + INTEROP;FEATURE_JNIENVIRONMENT_JI_PINVOKES;FEATURE_JNIOBJECTREFERENCE_INTPTRS;INTERNAL_NULLABLE_ATTRIBUTES;$(JavaInteropDefineConstants) true false $(BaseIntermediateOutputPath)$(Configuration)\$(TargetFramework.ToLowerInvariant())\ diff --git a/src/Java.Interop/Java.Interop/JniRuntime.cs b/src/Java.Interop/Java.Interop/JniRuntime.cs index d61bd172a..57e0e9628 100644 --- a/src/Java.Interop/Java.Interop/JniRuntime.cs +++ b/src/Java.Interop/Java.Interop/JniRuntime.cs @@ -248,9 +248,9 @@ protected JniRuntime (CreationOptions options) } } -#if !XA_INTEGRATION +#if !XA_JI_EXCLUDE ManagedPeer.Init (); -#endif // !XA_INTEGRATION +#endif } T SetRuntime (T value) From 29bab19ea20b56bb02e864160c81b09babd0cd9e Mon Sep 17 00:00:00 2001 From: Radek Doulik Date: Mon, 14 Dec 2020 22:46:06 +0100 Subject: [PATCH 2/6] Remove XA_INTEGRATION #if's They are not used anymore --- .../Java.Interop/JniEnvironment.Errors.cs | 2 -- .../Java.Interop/JniEnvironment.References.cs | 2 -- .../Java.Interop/JniEnvironment.Strings.cs | 2 -- .../Java.Interop/JniObjectReferenceOptions.cs | 3 --- .../JniPeerMembers.JniInstanceMethods.cs | 2 -- src/Java.Interop/Java.Interop/JniPeerMembers.cs | 4 ---- .../Java.Interop/JniRuntime.JniTypeManager.cs | 4 ++-- src/Java.Interop/Java.Interop/JniRuntime.cs | 12 ------------ src/Java.Interop/Java.Interop/JniType.cs | 7 +------ 9 files changed, 3 insertions(+), 35 deletions(-) diff --git a/src/Java.Interop/Java.Interop/JniEnvironment.Errors.cs b/src/Java.Interop/Java.Interop/JniEnvironment.Errors.cs index f88cd8d58..8211771e6 100644 --- a/src/Java.Interop/Java.Interop/JniEnvironment.Errors.cs +++ b/src/Java.Interop/Java.Interop/JniEnvironment.Errors.cs @@ -30,7 +30,6 @@ public static void ThrowNew (JniObjectReference klass, string message) throw new InvalidOperationException (string.Format ("Could not raise an exception; JNIEnv::ThrowNew() returned {0}.", r)); } -#if !XA_INTEGRATION public static void Throw (Exception e) { if (e == null) @@ -41,7 +40,6 @@ public static void Throw (Exception e) } Throw (je.PeerReference); } -#endif // !XA_INTEGRATION } } } diff --git a/src/Java.Interop/Java.Interop/JniEnvironment.References.cs b/src/Java.Interop/Java.Interop/JniEnvironment.References.cs index f1b6e8fdb..974b5cfe5 100644 --- a/src/Java.Interop/Java.Interop/JniEnvironment.References.cs +++ b/src/Java.Interop/Java.Interop/JniEnvironment.References.cs @@ -59,12 +59,10 @@ public static void PushLocalFrame (int capacity) throw new InvalidOperationException (string.Format ("Could not push a frame; JNIEnv::PushLocalFrame() returned {0}.", r)); } -#if !XA_INTEGRATION public static int GetIdentityHashCode (JniObjectReference value) { return JniSystem.IdentityHashCode (value); } -#endif // !XA_INTEGRATION public static IntPtr NewReturnToJniRef (IJavaPeerable value) { diff --git a/src/Java.Interop/Java.Interop/JniEnvironment.Strings.cs b/src/Java.Interop/Java.Interop/JniEnvironment.Strings.cs index e4b555577..f04fbf01a 100644 --- a/src/Java.Interop/Java.Interop/JniEnvironment.Strings.cs +++ b/src/Java.Interop/Java.Interop/JniEnvironment.Strings.cs @@ -17,7 +17,6 @@ public static unsafe JniObjectReference NewString (string? value) return NewString (s, value.Length); } -#if !XA_INTEGRATION public static string? ToString (IntPtr reference) { return ToString (new JniObjectReference (reference)); @@ -28,7 +27,6 @@ public static unsafe JniObjectReference NewString (string? value) Debug.Assert (targetType == typeof (string), "Expected targetType==typeof(string); was: " + targetType); return ToString (ref reference, transfer); } -#endif // !XA_INTEGRATION public static unsafe string? ToString (JniObjectReference value) { diff --git a/src/Java.Interop/Java.Interop/JniObjectReferenceOptions.cs b/src/Java.Interop/Java.Interop/JniObjectReferenceOptions.cs index 5a1169169..367e4157a 100644 --- a/src/Java.Interop/Java.Interop/JniObjectReferenceOptions.cs +++ b/src/Java.Interop/Java.Interop/JniObjectReferenceOptions.cs @@ -19,12 +19,9 @@ partial struct JniObjectReference { const JniObjectReferenceOptions DisposeSource = (JniObjectReferenceOptions) (1 << 1); } -#if !XA_INTEGRATION partial class JniRuntime { partial class JniValueManager { const JniObjectReferenceOptions DoNotRegisterTarget = (JniObjectReferenceOptions) (1 << 2); } } -#endif // !XA_INTEGRATION } - diff --git a/src/Java.Interop/Java.Interop/JniPeerMembers.JniInstanceMethods.cs b/src/Java.Interop/Java.Interop/JniPeerMembers.JniInstanceMethods.cs index be18a9c7b..2a825486c 100644 --- a/src/Java.Interop/Java.Interop/JniPeerMembers.JniInstanceMethods.cs +++ b/src/Java.Interop/Java.Interop/JniPeerMembers.JniInstanceMethods.cs @@ -111,7 +111,6 @@ public unsafe JniObjectReference StartCreateInstance (string constructorSignatur return r; } -#if !XA_INTEGRATION internal JniObjectReference AllocObject (Type declaringType) { var r = GetConstructorsForType (declaringType) @@ -120,7 +119,6 @@ internal JniObjectReference AllocObject (Type declaringType) r.Flags = JniObjectReferenceFlags.Alloc; return r; } -#endif // !XA_INTEGRATION internal unsafe JniObjectReference NewObject (string constructorSignature, Type declaringType, JniArgumentValue* parameters) { diff --git a/src/Java.Interop/Java.Interop/JniPeerMembers.cs b/src/Java.Interop/Java.Interop/JniPeerMembers.cs index 52c8f24c2..29be44adb 100644 --- a/src/Java.Interop/Java.Interop/JniPeerMembers.cs +++ b/src/Java.Interop/Java.Interop/JniPeerMembers.cs @@ -24,14 +24,12 @@ public JniPeerMembers (string jniPeerTypeName, Type managedPeerType) if (!typeof (IJavaPeerable).IsAssignableFrom (managedPeerType)) throw new ArgumentException ("'managedPeerType' must implement the IJavaPeerable interface.", nameof (managedPeerType)); -#if !XA_INTEGRATION Debug.Assert ( JniEnvironment.Runtime.TypeManager.GetTypeSignature (managedPeerType).SimpleReference == jniPeerTypeName, string.Format ("ManagedPeerType <=> JniTypeName Mismatch! javaVM.GetJniTypeInfoForType(typeof({0})).JniTypeName=\"{1}\" != \"{2}\"", managedPeerType.FullName, JniEnvironment.Runtime.TypeManager.GetTypeSignature (managedPeerType).SimpleReference, jniPeerTypeName)); -#endif // !XA_INTEGRATION ManagedPeerType = managedPeerType; } @@ -47,14 +45,12 @@ public JniPeerMembers (string jniPeerTypeName, Type managedPeerType) if (!typeof (IJavaPeerable).IsAssignableFrom (managedPeerType)) throw new ArgumentException ("'managedPeerType' must implement the IJavaPeerable interface.", nameof (managedPeerType)); -#if !XA_INTEGRATION Debug.Assert ( JniEnvironment.Runtime.TypeManager.GetTypeSignature (managedPeerType).SimpleReference == jniPeerTypeName, string.Format ("ManagedPeerType <=> JniTypeName Mismatch! javaVM.GetJniTypeInfoForType(typeof({0})).JniTypeName=\"{1}\" != \"{2}\"", managedPeerType.FullName, JniEnvironment.Runtime.TypeManager.GetTypeSignature (managedPeerType).SimpleReference, jniPeerTypeName)); -#endif // !XA_INTEGRATION } JniPeerTypeName = jniPeerTypeName; diff --git a/src/Java.Interop/Java.Interop/JniRuntime.JniTypeManager.cs b/src/Java.Interop/Java.Interop/JniRuntime.JniTypeManager.cs index 1dd3fd1ac..273256fc8 100644 --- a/src/Java.Interop/Java.Interop/JniRuntime.JniTypeManager.cs +++ b/src/Java.Interop/Java.Interop/JniRuntime.JniTypeManager.cs @@ -201,7 +201,7 @@ IEnumerable CreateGetTypesEnumerator (JniTypeSignature typeSignature) yield return type; continue; } -#if !XA_INTEGRATION + if (typeSignature.ArrayRank > 0) { var rank = typeSignature.ArrayRank; var arrayType = type; @@ -214,7 +214,7 @@ IEnumerable CreateGetTypesEnumerator (JniTypeSignature typeSignature) } yield return arrayType; } -#endif // !XA_INTEGRATION + if (typeSignature.ArrayRank > 0) { var rank = typeSignature.ArrayRank; var arrayType = type; diff --git a/src/Java.Interop/Java.Interop/JniRuntime.cs b/src/Java.Interop/Java.Interop/JniRuntime.cs index 57e0e9628..1071914d3 100644 --- a/src/Java.Interop/Java.Interop/JniRuntime.cs +++ b/src/Java.Interop/Java.Interop/JniRuntime.cs @@ -325,11 +325,9 @@ protected virtual void Dispose (bool disposing) JniObjectReference.Dispose (ref ClassLoader); ClearTrackedReferences (); -#if !XA_INTEGRATION ValueManager.Dispose (); marshalMemberBuilder?.Dispose (); TypeManager.Dispose (); -#endif // !XA_INTEGRATION ObjectReferenceManager.Dispose (); var environments = JniEnvironment.Info.Values; @@ -389,11 +387,7 @@ public void DestroyRuntime () public virtual Exception? GetExceptionForThrowable (ref JniObjectReference reference, JniObjectReferenceOptions options) { -#if XA_INTEGRATION - throw new NotSupportedException ("Do not know h ow to convert a JniObjectReference to a System.Exception!"); -#else // !XA_INTEGRATION return ValueManager.GetValue (ref reference, options); -#endif // !̀£XA_INTEGRATION } public int GlobalReferenceCount { @@ -436,13 +430,7 @@ partial class JniRuntime { public virtual void RaisePendingException (Exception pendingException) { -#if XA_INTEGRATION - if (pendingException == null) - throw new ArgumentNullException (nameof (pendingException)); - throw new NotSupportedException ("Do not know how to marshal System.Exception instances."); -#else // !XA_INTEGRATION JniEnvironment.Exceptions.Throw (pendingException); -#endif // !XA_INTEGRATION } } } diff --git a/src/Java.Interop/Java.Interop/JniType.cs b/src/Java.Interop/Java.Interop/JniType.cs index 9feaacdb9..be6bcd8f0 100644 --- a/src/Java.Interop/Java.Interop/JniType.cs +++ b/src/Java.Interop/Java.Interop/JniType.cs @@ -67,12 +67,7 @@ public override string ToString () return $"JniType(Name='{Name}' PeerReference={PeerReference})"; } -#if XA_INTEGRATION - internal -#else // !XA_INTEGRATION - public -#endif // !XA_INTEGRATION - void RegisterWithRuntime () + public void RegisterWithRuntime () { AssertValid (); From 6891cd2077492efe533be7490046f50e4b36afc7 Mon Sep 17 00:00:00 2001 From: Radek Doulik Date: Fri, 18 Dec 2020 17:27:50 +0100 Subject: [PATCH 3/6] Conditionally import XAConfig.props --- src/Java.Interop/Java.Interop-MonoAndroid.csproj | 4 ++++ src/Java.Interop/Java.Interop.csproj | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/src/Java.Interop/Java.Interop-MonoAndroid.csproj b/src/Java.Interop/Java.Interop-MonoAndroid.csproj index 7d7c6d08f..9a3611ae9 100644 --- a/src/Java.Interop/Java.Interop-MonoAndroid.csproj +++ b/src/Java.Interop/Java.Interop-MonoAndroid.csproj @@ -1,5 +1,9 @@ + + ..\..\bin\Build$(Configuration)\XAConfig.props + + Debug AnyCPU diff --git a/src/Java.Interop/Java.Interop.csproj b/src/Java.Interop/Java.Interop.csproj index 1bffbb24b..88eadd83d 100644 --- a/src/Java.Interop/Java.Interop.csproj +++ b/src/Java.Interop/Java.Interop.csproj @@ -1,5 +1,9 @@ + + ..\..\bin\Build$(Configuration)\XAConfig.props + + netstandard2.0;netcoreapp3.1 1591 From 696d6eb2f183cb83782b56e81d88d339aaeb7416 Mon Sep 17 00:00:00 2001 From: Jonathan Pryor Date: Mon, 4 Jan 2021 13:29:38 -0500 Subject: [PATCH 4/6] add comment --- src/Java.Interop/Java.Interop/JniRuntime.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Java.Interop/Java.Interop/JniRuntime.cs b/src/Java.Interop/Java.Interop/JniRuntime.cs index 1071914d3..5c19e5123 100644 --- a/src/Java.Interop/Java.Interop/JniRuntime.cs +++ b/src/Java.Interop/Java.Interop/JniRuntime.cs @@ -250,7 +250,7 @@ protected JniRuntime (CreationOptions options) #if !XA_JI_EXCLUDE ManagedPeer.Init (); -#endif +#endif // !XA_JI_EXCLUDE } T SetRuntime (T value) From 6c7de91b78b57e7bd69921eedd418da2a7e12b06 Mon Sep 17 00:00:00 2001 From: Radek Doulik Date: Fri, 8 Jan 2021 21:25:28 +0100 Subject: [PATCH 5/6] Remove forgotten import --- Directory.Build.props | 4 ---- 1 file changed, 4 deletions(-) diff --git a/Directory.Build.props b/Directory.Build.props index 60dce41d7..fa711a23d 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -23,10 +23,6 @@ Project="$(_OutputPath)MonoInfo.props" Condition="Exists('$(_OutputPath)MonoInfo.props')" /> - False obj\ From 75f86feb85824a41a461782aba5a3a31c46d45cd Mon Sep 17 00:00:00 2001 From: Radek Doulik Date: Fri, 8 Jan 2021 21:29:19 +0100 Subject: [PATCH 6/6] Move the import of XAConfig.props ...to a place whete `$(Configuration) is already set --- src/Java.Interop/Java.Interop-MonoAndroid.csproj | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Java.Interop/Java.Interop-MonoAndroid.csproj b/src/Java.Interop/Java.Interop-MonoAndroid.csproj index 9a3611ae9..9061a960f 100644 --- a/src/Java.Interop/Java.Interop-MonoAndroid.csproj +++ b/src/Java.Interop/Java.Interop-MonoAndroid.csproj @@ -1,9 +1,5 @@ - - ..\..\bin\Build$(Configuration)\XAConfig.props - - Debug AnyCPU @@ -22,6 +18,10 @@ true + + ..\..\bin\Build$(Configuration)\XAConfig.props + + true full