Commit 77678eb
authored
Bump to xamarin/Java.Interop/main@bbaeda6f (#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.html1 parent 5137dc7 commit 77678eb
8 files changed
Lines changed: 82 additions & 4 deletions
File tree
- build-tools/scripts
- external
- src
- Mono.Android/Android.Runtime
- Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/Utilities
- tests
- MSBuildDeviceIntegration
- Resources
- Tests
- Mono.Android-Tests/Runtime-Microsoft.Android.Sdk
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
35 | 35 | | |
36 | 36 | | |
37 | 37 | | |
| 38 | + | |
38 | 39 | | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
39 | 45 | | |
40 | | - | |
| 46 | + | |
| 47 | + | |
41 | 48 | | |
42 | 49 | | |
43 | 50 | | |
| |||
Submodule Java.Interop updated from 9e0a469 to bbaeda6
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
314 | 314 | | |
315 | 315 | | |
316 | 316 | | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
317 | 320 | | |
318 | | - | |
319 | | - | |
| 321 | + | |
| 322 | + | |
320 | 323 | | |
321 | 324 | | |
322 | 325 | | |
| |||
Lines changed: 2 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
21 | 21 | | |
22 | 22 | | |
23 | 23 | | |
| 24 | + | |
24 | 25 | | |
25 | 26 | | |
26 | 27 | | |
| |||
34 | 35 | | |
35 | 36 | | |
36 | 37 | | |
| 38 | + | |
37 | 39 | | |
38 | 40 | | |
39 | 41 | | |
| |||
Lines changed: 3 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
31 | 31 | | |
32 | 32 | | |
33 | 33 | | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
34 | 37 | | |
35 | 38 | | |
36 | 39 | | |
| |||
Lines changed: 7 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
155 | 155 | | |
156 | 156 | | |
157 | 157 | | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
158 | 211 | | |
159 | 212 | | |
160 | 213 | | |
| |||
Lines changed: 3 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
5 | 8 | | |
6 | 9 | | |
7 | 10 | | |
| |||
0 commit comments