Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Bump to xamarin/Java.Interop/main@bbaeda6f (dotnet#7799)
Changes: dotnet/java-interop@9e0a469...bbaeda6 * dotnet/java-interop@bbaeda6f: [Java.Interop] Support Desugar + interface static methods (dotnet/java-interop#1077) Context: dotnet/java-interop@bbaeda6 Context: dotnet/java-interop@1f27ab5 Context: f6f11a5 [Desugaring][0] is the process of rewriting Java bytecode so that Java 8+ constructs can be used on Android pre-7.0 (API-24), as API-24 is the Android version which added native support for Java 8 features such as [interface default methods][1]. One of the implications of desugaring is that methods can "move"; consider this Java interface: package example; public interface StaticMethodsInterface { static int getValue() { return 3; } } Java.Interop bindings will attempt to invoke the `getValue().I` method on the type `example/StaticMethodsInterface`: public partial interface IStaticMethodsInterface : IJavaObject, IJavaPeerable { private static readonly JniPeerMembers _members = new XAPeerMembers ("example/StaticMethodsInterface", typeof (IStaticMethodsInterface), isInterface: true); static unsafe int Value { get { const string __id = "getValue.()I"; var __rm = _members.StaticMethods.InvokeInt32Method (__id, null); return __rm; } } } The problem is that, after Desugaring, the Java side *actually* looks like this: package example; public interface StaticMethodsInterface { } public class StaticMethodsInterface$-CC { public static int getValue() {return 3;} } Commits dotnet/java-interop@1f27ab55 and f6f11a5 added partial runtime support for this scenario via `AndroidTypeManager.GetStaticMethodFallbackTypesCore()`, which would attempt to lookup types with a `$-CC` suffix. While this was a good start, it wasn't ever actually *tested* end-to-end. Consequently, instead of *working*, this would instead cause the process to *abort*: JNI DETECTED ERROR IN APPLICATION: can't call static int example.StaticMethodsInterface$-CC.getValue() with class java.lang.Class<example.StaticMethodsInterface> in call to CallStaticIntMethodA from void crc….MainActivity.n_onCreate(android.os.Bundle) Oops. dotnet/java-interop@bbaeda6f improves our runtime support for invoking *`static`* methods on interfaces. Add a new `XASdkDeployTests.SupportDesugaringStaticInterfaceMethods()` test which performs an on-device, end-to-end invocation of a static method on a Java interface, to ensure that things *actually* work. *Note*: if `$(SupportedOSPlatformVersion)` is 24 or higher, this test will work even without dotnet/java-interop#1077, as Desugaring is *disabled* in that case. The test `JniPeerMembersTests.DesugarInterfaceStaticMethod()` added in dotnet/java-interop@bbaeda6f attempts to "fake" a Desugar environment for testing on Desktop Java, and this "fakery" doesn't work in the Android environment. Fix execution on Android by updating `AndroidRuntime.GetStaticMethodFallbackTypesCore()` to support type remapping (f6f11a5) -- which was overlooked/not considered -- such that the types returned are *after* calling `AndroidRuntime.GetReplacementTypeCore()`, which looks up `<replace-type/>` values. This allows us to remap `AndroidInterface` to `DesugarAndroidInterface$_CC`, allowing the `DesugarInterfaceStaticMethod()` test to pass. Update the `BuildTestJarFile` target so that it properly builds files that contain `$` on Unixy platforms. [0]: https://developer.android.com/studio/write/java8-support#library-desugaring [1]: https://docs.oracle.com/javase/tutorial/java/IandI/defaultmethods.html
- Loading branch information