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...
Alias: None
Product: Android
Classification: Xamarin
Component: Bindings ()
Version: 8.0 (15.4)
Hardware: PC Windows
: Highest blocker
Target Milestone: 15.4 SR2
Assignee: Atsushi Eno
: 60197 ()
Depends on:
Reported: 2017-10-09 19:53 UTC by James Montemagno [MSFT]
Modified: 2017-12-01 18:03 UTC (History)
15 users (show)

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

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

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.

Please create a new report on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:

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: 
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:


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


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.