Bug 60069 - Build.getSerial is not bound in Android API 26, causes conflict with Build.Serial, which is now deprecated
Summary: Build.getSerial is not bound in Android API 26, causes conflict with Build.Se...
Status: VERIFIED FIXED
Alias: None
Product: Android
Classification: Xamarin
Component: Bindings (show other bugs)
Version: 8.0 (15.4)
Hardware: PC Windows
: Highest blocker
Target Milestone: 15.4 SR2
Assignee: Atsushi Eno
URL:
: 60197 (view as bug list)
Depends on:
Blocks:
 
Reported: 2017-10-09 19:53 UTC by James Montemagno [MSFT]
Modified: 2017-10-19 19:48 UTC (History)
14 users (show)

See Also:
Tags:
Is this bug a regression?: ---
Last known good build:


Attachments
reference metadata fixup changes (20.55 KB, patch)
2017-10-11 17:31 UTC, Atsushi Eno
Details | Diff

Description James Montemagno [MSFT] 2017-10-09 19:53:53 UTC
You must be compiling against SDK 26 (aka Android 8.0);


Run this code: 
var id = Build.Serial;

It will blow up with Java.Lang.NoSuchMethodError: no static method "Landroid/os/Build;.getSerial()Ljava/lang/String;"

Now, be aware that there is already a Build.Serial: 
https://developer.android.com/reference/android/os/Build.html#SERIAL with https://developer.android.com/reference/android/os/Build.html#getSerial()

So the correct thing to do is NOT to re-map it to Serial as we already re-mapped SERIAL with Serial... so it should remain -> GetSerial();

Issue found here: 
https://github.com/jamesmontemagno/DeviceInfoPlugin/issues/34
Comment 2 Jonathan Pryor 2017-10-09 20:07:53 UTC
Likely fallout from this: We need to fixup generator + apimerge behavior so that `Build.getSerial()` (since API-26) doesn't *replace* `Build.SERIAL` (since API-9).
Comment 3 Atsushi Eno 2017-10-11 17:28:55 UTC
There is no chance that api-merge can handle this.

This rather exposes the problem in the Java.Interop (or Android.Runtime, I don't know exactly which) behavior regarding unified API. What happens if SERIAL is removed at API Level X and there is completely valid getSerial() in API Level X? Java.Interop or Android.Runtime must handle it as if it were a method call in API Level X or later and a field reference in older API Levels.

Rephrase: it is a bug in interop layer.

Adding workaround for this issue is doable, but what really has to be done is above.

jonp told me that there could be more of the same kind of problems, but to verify that (note that it's not ONLY about detecting those) he needs to implement attribute value level API comparison that checks [Register] properties anyways.

I have many changes to "workaround" these kind of field overrides in ALL the API Levels (it is NOT DOABLE to detect "breaking" changes in API Level 26 as generator member comparison does not report the conflict details, only reporting "there is conflict", and making changes to give further details is a LOT of changes), but even if I made those changes there is no way to verify that the changes are valid and sufficient, without implementing attribute properties comparer.
Comment 4 Atsushi Eno 2017-10-11 17:31:48 UTC
Created attachment 25276 [details]
reference metadata fixup changes
Comment 5 alex 2017-10-11 22:00:21 UTC
Would be great to ping James with his plugin: https://github.com/jamesmontemagno/DeviceInfoPlugin
Comment 6 alex 2017-10-11 22:01:59 UTC
Alex should read whole thread with better attention :)
Comment 7 Jonathan Pryor 2017-10-11 22:25:18 UTC
PR: https://github.com/xamarin/xamarin-android/pull/930

It's based in part on Attachment #25276 [details], but *only* fixes `Build.getSerial()`, so that we can easily merge this into d15-4 for a future service release.

The rest of Attachment #25276 [details] should be applied to xamarin-android separately.
Comment 10 abgarg 2017-10-13 21:06:36 UTC
how to get this fix, i installed xamarin with VS2017 on 9 oct and since then I am getting this error, need immediate help
Comment 11 Jonathan Pryor 2017-10-14 12:19:54 UTC
@abgarg: There are two workarounds until an official release containing the fix is available:

1. *Do not* set `$(TargetFrameworkVersion)`=v8.0. Using v7.1 or any earlier version will suffice.

Unfortunately this means you can't easily access the new Oreo APIs. :-(

2. If *you* are accessing the `Android.OS.Build.Serial` property -- and not some 3rd party library -- you can instead use JNI to reimplement the previous behavior:

https://github.com/jamesmontemagno/DeviceInfoPlugin/commit/032f34e913c48dbce12ee8c753f32ae38f0ce8db#diff-126e10e516f5be6551423a8b49bddfc5R56

Alternatively, you can try the *unreleased* installers, available at:

https://github.com/xamarin/xamarin-android#downloads

You want the installers from: Commercial Xamarin.Android 8.0 (d15-4)
Comment 12 Jon Douglas [MSFT] 2017-10-15 23:30:10 UTC
*** Bug 60197 has been marked as a duplicate of this bug. ***
Comment 14 Jon Douglas [MSFT] 2017-10-19 19:48:15 UTC
This bug did not make 15.4 SR1 due to a conflict with insertion. It will be included in 15.4 SR2. Thus I am setting the milestone accordingly.

Note You need to log in before you can comment on or make changes to this bug.