Skip to content

Commit 7d32ef3

Browse files
radekdoulikjonpryor
authored andcommitted
Use complete Java.Interop (#1231)
Start using complete Java.Interop, ie. `Debug` and `Release` configurations instead of `XAIntegrationDebug` and `XAIntegrationRelease`. Add Java.Interop java sources to the list of sources to build mono.android.jar. This is needed for `ManagedPeer` and other classes with java counterparts. Few updates to distinguish between `Android.Runtime.JavaObject` and `Java.Interop.JavaObject`. Added System.Collections reference is for `List<JniSurfacedPeerInfo>` return type in `AndroidValueManager`.
1 parent 0ec02f4 commit 7d32ef3

File tree

7 files changed

+52
-189
lines changed

7 files changed

+52
-189
lines changed

Xamarin.Android.sln

Lines changed: 0 additions & 178 deletions
Large diffs are not rendered by default.

build-tools/scripts/JavaCallableWrappers.targets

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
/>
1818
<ItemGroup>
1919
<_JavaSources Include="$(IntermediateOutputPath)jcw\src\**\*.java" />
20+
<_JavaSources Include="$(JavaInteropSourceDirectory)\src\Java.Interop\java\com\xamarin\**\*.java" />
2021
</ItemGroup>
2122
<WriteLinesToFile
2223
File="$(IntermediateOutputPath)jcw\classes.txt"

external/Java.Interop

src/Mono.Android/Android.Runtime/AndroidRuntime.cs

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ public AndroidRuntimeOptions (IntPtr jnienv, IntPtr vm, bool allocNewObjectSuppo
6666
NewObjectRequired = !allocNewObjectSupported;
6767
ObjectReferenceManager = new AndroidObjectReferenceManager ();
6868
TypeManager = new AndroidTypeManager ();
69+
ValueManager = new AndroidValueManager ();
6970
}
7071
}
7172

@@ -225,5 +226,43 @@ protected override IEnumerable<string> GetSimpleReferences (Type type)
225226
.Concat (Enumerable.Repeat (j, 1));
226227
}
227228
}
229+
230+
class AndroidValueManager : JniRuntime.JniValueManager {
231+
232+
public override void WaitForGCBridgeProcessing ()
233+
{
234+
JNIEnv.WaitForBridgeProcessing ();
235+
}
236+
237+
public override void AddPeer (IJavaPeerable value)
238+
{
239+
throw new NotImplementedException ();
240+
}
241+
242+
public override void RemovePeer (IJavaPeerable value)
243+
{
244+
throw new NotImplementedException ();
245+
}
246+
247+
public override IJavaPeerable PeekPeer (JniObjectReference reference)
248+
{
249+
throw new NotImplementedException ();
250+
}
251+
252+
public override void CollectPeers ()
253+
{
254+
throw new NotImplementedException ();
255+
}
256+
257+
public override void FinalizePeer (IJavaPeerable value)
258+
{
259+
throw new NotImplementedException ();
260+
}
261+
262+
public override List<JniSurfacedPeerInfo> GetSurfacedPeers ()
263+
{
264+
throw new NotImplementedException ();
265+
}
266+
}
228267
}
229268
#endif // JAVA_INTEROP

src/Mono.Android/Java.Interop/JavaConvert.cs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -222,8 +222,7 @@ public static T FromJavaObject<T>(IJavaObject value, out bool set)
222222
set = true;
223223
return value._JavaCast<T>();
224224
}
225-
var o = value as JavaObject;
226-
if (o != null) {
225+
if (value is Android.Runtime.JavaObject o) {
227226
set = true;
228227
if (o.Instance is T)
229228
return (T) o.Instance;
@@ -255,8 +254,7 @@ public static object FromJavaObject (IJavaObject value, Type targetType = null)
255254
return JavaObjectExtensions.JavaCast (value, targetType);
256255
}
257256

258-
var o = value as JavaObject;
259-
if (o != null) {
257+
if (value is Android.Runtime.JavaObject o) {
260258
if (targetType == null)
261259
return o.Instance;
262260
return Convert.ChangeType (o.Instance, targetType);
@@ -306,7 +304,7 @@ public static IJavaObject ToJavaObject<T>(T value)
306304
Func<object, IJavaObject> converter = GetJavaObjectConverter (typeof (T));
307305
if (converter != null)
308306
return converter (value);
309-
return new JavaObject (value);
307+
return new Android.Runtime.JavaObject (value);
310308
}
311309

312310
static Dictionary<Type, Func<object, IntPtr>> LocalJniHandleConverters = new Dictionary<Type, Func<object, IntPtr>> {
@@ -352,8 +350,8 @@ public static IJavaObject ToJavaObject<T>(T value)
352350
using (var v = new Java.Lang.String (value.ToString ()))
353351
return JNIEnv.ToLocalJniHandle (v);
354352
} },
355-
{ typeof (JavaObject), value => {
356-
return value == null ? IntPtr.Zero : JNIEnv.ToLocalJniHandle (new JavaObject (value));
353+
{ typeof (Android.Runtime.JavaObject), value => {
354+
return value == null ? IntPtr.Zero : JNIEnv.ToLocalJniHandle (new Android.Runtime.JavaObject (value));
357355
} },
358356
};
359357

@@ -364,7 +362,7 @@ static Func<object, IntPtr> GetLocalJniHandleConverter<T> (T value, Type sourceT
364362
return converter;
365363
if (value != null && LocalJniHandleConverters.TryGetValue (value.GetType (), out converter))
366364
return converter;
367-
return LocalJniHandleConverters [typeof (JavaObject)];
365+
return LocalJniHandleConverters [typeof (Android.Runtime.JavaObject)];
368366
}
369367

370368
public static TReturn WithLocalJniHandle<TValue, TReturn>(TValue value, Func<IntPtr, TReturn> action)

src/Mono.Android/Mono.Android.csproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,10 @@
5151
<HintPath>$(OutputPath)..\v1.0\System.dll</HintPath>
5252
<Private>False</Private>
5353
</Reference>
54+
<Reference Include="System.Collections">
55+
<HintPath>$(OutputPath)..\v1.0\Facades\System.Collections.dll</HintPath>
56+
<Private>False</Private>
57+
</Reference>
5458
<Reference Include="System.Core">
5559
<HintPath>$(OutputPath)..\v1.0\System.Core.dll</HintPath>
5660
<Private>False</Private>

src/Mono.Android/Mono.Android.targets

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,9 @@
1212
Outputs="$(OutputPath)\..\v1.0\Java.Interop.dll">
1313
<MSBuild
1414
Projects="$(JavaInteropFullPath)\src\Java.Interop\Java.Interop.csproj"
15-
Properties="Configuration=XAIntegration$(Configuration)"
1615
/>
1716
<ItemGroup>
18-
<Assembly Include="$(JavaInteropFullPath)\bin\XAIntegration$(Configuration)\*.dll*" />
17+
<Assembly Include="$(JavaInteropFullPath)\bin\$(Configuration)\*.dll*" />
1918
</ItemGroup>
2019
<Copy
2120
SourceFiles="@(Assembly)"

0 commit comments

Comments
 (0)