|Summary:||Build.getSerial is not bound in Android API 26, causes conflict with Build.Serial, which is now deprecated|
|Product:||Android||Reporter:||James Montemagno [MSFT] <james.montemagno>|
|Component:||Bindings||Assignee:||Atsushi Eno <atsushi>|
|Severity:||blocker||CC:||abgarg, adam, alex, clauserik, jimbobbennett, joas, jon.douglas, jonp, kasper, matthew.regul, mono-bugs+monodroid, ramy.zbeidy, sinaly, v-prala, v-sapaun|
|Target Milestone:||15.4 SR2|
|Tags:||Is this bug a regression?:||---|
|Last known good build:|
|Attachments:||reference metadata fixup changes|
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 8 Jonathan Pryor 2017-10-12 17:32:51 UTC
Fixed in: master: https://github.com/xamarin/xamarin-android/commit/36843aefdfcb207c15f6f8d984e87ecfa9eea7fc d15-5: https://github.com/xamarin/xamarin-android/commit/78dc175e5f557549beb9e53ac3e91991bab31399 monodroid/d15-5/d3e59736 d15-4: https://github.com/xamarin/xamarin-android/commit/e2fae29e4006c6f219b4157ee082f92f2b611cf8 monodroid/d15-4/e5c629c7
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.