Commit 24a9abd
[Xamarin.Android.Tools.ApiXmlAdjuster] Find app.android.IntentService (#718)
Fixes: #717
A long time ago (2011-Jan-28), [Novell Bug #655342][0] was filed:
the following fragment was expected to work, but didn't:
// C#
[Service]
class MyService : Android.App.IntentService {
public MyService()
{
}
protected override void OnHandleIntent(Intent intent)
{
}
}
Why didn't it work? Two reasons:
1. `android.app.IntentService` has no default constructor; it only
has an [`IntentService(String)`][1] constructor.
2. In 2011, there was no way for a C# type to provide constructor
parameters to the Java constructor.
The result is that the Java Callable Wrapper for `MyService` was not
valid Java code, as it attempted to use a non-existent constructor:
// Java
/* partial */ class MyService extends android.app.IntentService {
public MyService() {
super(); // javac error; no such constructor exists
// …
}
}
Note that there's no way to make `MyService() : base("name")` work,
which would be the "obvious" solution, unless `jcw-gen` contains an
IL interpreter to determine what parameters were provided to the base
class constructor, and…no. Too complicated. Not happening.
Note: (2) later got "solved" [in 2013][2] by adding the
[`ExportAttribute.SuperArgumentsString` property][3], which would allow:
[Service]
partial class MyService : Android.App.IntentService {
[Export(SuperArgumentsString="\"name\"")]
public MyService() : base ("name")
{
}
}
--End note.
Lacking a time machine, [the 2011 fix][4] was to "fudge" it:
1. Add a new [`mono.android.app.IntentService`][5] Java type which
contains a default constructor.
2. ["Rename"][6] `android.app.IntentService` as
`mono.android.app.IntentService`.
That way, the original C# declaration would generate a Java Callable
Wrapper resembling:
// Java
/* partial */ class MyService extends mono.android.app.IntentService {
public MyService() {
super(); // now valid; it exists!
// …
}
}
Unfortunately, this doesn't properly address *bindings*: what happens
if a *Java* type inherits `android.app.IntentService`, as is the case
in [`Microsoft.Intune.MAM.SDK.aar`][7], and that type is bound?
In the original `jar2xml` world order, it worked: [`jar2xml`][8] is a
Java app, and for it to run `$CLASSPATH` needed to contain
`android.jar`, which *did* have `android.app.IntentService`. Thus,
all required types could be resolved.
In the new `class-parse` world order, this isn't the case:
`class-parse` directly reads Java bytecode; no JVM is used.
The result is that binding projects which move from `jar2xml` to
`class-parse` could now get a new error:
Error while processing type '[Class] com.microsoft.intune.mam.client.app.MAMIntentService':
Type 'android.app.IntentService' was not found.
`android.app.IntentService` wasn't found because `Mono.Android.dll`
doesn't contain a binding for that type; it only binds
`mono.android.app.IntentService`.
The fix for this unfortunate state of affairs is Yet Another Kludge
to maintain backward compatibility: update
`JavaApiTypeResolverExtensions.FindNonGenericType()` so that it knows
about the 2011 kludge: if `android.app.IntentService` is requested,
hand it back the `JavaType` instance for
`mono.android.app.IntentService`.
[0]: http://bugzilla.novell.com/show_bug.cgi?id=655342
[1]: https://developer.android.com/reference/android/app/IntentService#IntentService(java.lang.String)
[2]: https://github.com/xamarin/monodroid/commit/a6c3497f4db9f628e086493580c908c6f05098fa
[3]: https://docs.microsoft.com/en-us/dotnet/api/java.interop.exportattribute.superargumentsstring
[4]: https://github.com/xamarin/monodroid/commit/7a42b46a39
[5]: https://github.com/xamarin/xamarin-android/blob/a7bda88d05b58efd26c17be3956c7140d05868e1/src/Mono.Android/java/mono/android/app/IntentService.java
[6]: https://github.com/xamarin/xamarin-android/blob/a7bda88d05b58efd26c17be3956c7140d05868e1/src/Mono.Android/metadata#L570-L583
[7]: https://github.com/msintuneappsdk/ms-intune-app-sdk-android/blob/master/Microsoft.Intune.MAM.SDK.aar
[8]: https://github.com/xamarin/jar2xml1 parent a807961 commit 24a9abd
File tree
3 files changed
+41
-2
lines changed- src/Xamarin.Android.Tools.ApiXmlAdjuster
- tests/Xamarin.Android.Tools.ApiXmlAdjuster-Tests
3 files changed
+41
-2
lines changedLines changed: 8 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
44 | 44 | | |
45 | 45 | | |
46 | 46 | | |
47 | | - | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
48 | 53 | | |
| 54 | + | |
| 55 | + | |
49 | 56 | | |
50 | 57 | | |
51 | 58 | | |
| |||
Lines changed: 1 addition & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
14 | | - | |
| 14 | + | |
15 | 15 | | |
16 | 16 | | |
17 | 17 | | |
| |||
Lines changed: 32 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
| 2 | + | |
| 3 | + | |
2 | 4 | | |
| 5 | + | |
3 | 6 | | |
4 | 7 | | |
5 | 8 | | |
| |||
65 | 68 | | |
66 | 69 | | |
67 | 70 | | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
68 | 100 | | |
69 | 101 | | |
70 | 102 | | |
0 commit comments