From 006edd6846ec1df4ec2e8103c030fdaf4aa4d41a Mon Sep 17 00:00:00 2001 From: Jonathan Pryor Date: Wed, 11 Oct 2017 18:00:33 -0400 Subject: [PATCH] [Mono.Android] Bind Build.getVersion() as Build.GetVersion() Fixes: https://bugzilla.xamarin.com/show_bug.cgi?id=60069 Context: https://bugzilla.xamarin.com/attachment.cgi?id=25276 API-26 added an [`android.os.Build.getSerial()`][0] method. Under normal "name mangling" conventions, `generator` binds this as an `Android.OS.Build.Serial` property. [0]: https://developer.android.com/reference/android/os/Build.html#getSerial() There's just one "minor" problem with this: there is *also* an [`android.os.Build.SERIAL`][1] field, since API-9, which `generator` *also* binds as an `Android.OS.Build.Serial` property. [1]: https://developer.android.com/reference/android/os/Build.html#SERIAL Thus, a question: given the Java code: ```java public class Build { public static String SERIAL = "UNKNOWN"; public static String getSerial() {/* ... */ } } ``` What will `generator` do? Answer: the wrong thing: the field is *ignored*, and the `Build.getSerial()` method is used for the `Build.Serial` property. This is problematic. *The managed API has not changed* -- pre-API-26 and post-API-26 both have a string `Build.Serial` property -- but the *behavior* of the method has changed from reading the value of a static field, to invoking a static method. A static method that only exists on devices running API-26 and later. Meaning: 1. Create a new Xamarin.Android app. 2. Set `$(TargetFrameworkVersion)` to v8.0, and `//uses-sdk/@android:minSdkVersion` to 11 within `AndroidManifest.xml`. 3. Within e.g. `MainActivity.OnCreate()`, reference the `Android.OS.Build.Serial` property. 4. Build the app, and run on e.g. an Android 7.1 device. Expected result: it works! Actual result: not so much: Java.Lang.NoSuchMethodError: no static method "Landroid/os/Build;.getSerial()Ljava/lang/String;" @atsushieno has determined that this is the only such behavioral breakage introduced by API-26. His [referenced metadata fixup changes][2] patch lists all the fields which are currently being ignored by the `Mono.Android` build process. [2]: https://bugzilla.xamarin.com/attachment.cgi?id=25276 In the interest of expediency (and getting this merged into d15-4), include *only* the metadata changes that impact `Build.getSerial()`, and force it to be bound as a `Build.GetSerial()` method. This "un-hides" the `Build.Serial` binding of the `Build.SERIAL` field, restoring semantic compatibility. The remaining of the metadata fixup changes should be merged separately. --- src/Mono.Android/metadata | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/Mono.Android/metadata b/src/Mono.Android/metadata index 50af00de490..94d67e455b3 100644 --- a/src/Mono.Android/metadata +++ b/src/Mono.Android/metadata @@ -1381,4 +1381,14 @@ MediaCasEventArgs mediaCas + +