Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No longer able to access Android.Widget.ChoiceMode when compiling against v2.3 in d15-6 #1170

Closed
pjcollins opened this issue Jan 9, 2018 · 8 comments
Assignees
Labels
Area: Bindings Issues in Java Library Binding projects. regression
Milestone

Comments

@pjcollins
Copy link
Member

It appears that the ChoiceMode property of Android.Widget.AbsListView https://developer.android.com/reference/android/widget/AbsListView.html#setChoiceMode(int) is no longer accessible when comping against v2.3. This appears to be a regression introduced in d15-6.

Steps to Reproduce

  1. Open the AccessoryViews monodroid sample - https://github.com/xamarin/monodroid-samples/tree/master/AccessoryViews
  2. Ensure you have SDK Platform Version 10 (2.3) installed, and attempt to build the project.

Expected Behavior

The project builds without error when targeting v2.3. This succeeds using d15-5 builds:
https://gist.githubusercontent.com/pjcollins/22ca1e9064404355a0d88e72bb25d929/raw/3d07327d36390d523ac74e1b7d32af4fc63c73f5/15.5%2520Output

Actual Behavior

The project fails to build against monodroid/d15-6:
http://xqa.blob.core.windows.net/gist/report-c995421b88984113bef0729590cdf1cf.txt

(CoreCompile target) -> 
  HomeScreen.cs(31,16): error CS1061: 'ListView' does not contain a definition for 'ChoiceMode' and no extension method 'ChoiceMode' accepting a first argument of type 'ListView' could be found (are you missing a using directive or an assembly reference?) [/Users/xamarinqa/myagent/_work/r1/a/monodroid-samples/AccessoryViews/AccessoryViews.csproj]
  HomeScreen.cs(31,29): error CS0234: The type or namespace name 'ChoiceMode' does not exist in the namespace 'Android.Widget' (are you missing an assembly reference?) [/Users/xamarinqa/myagent/_work/r1/a/monodroid-samples/AccessoryViews/AccessoryViews.csproj]

Interestingly enough, if I update the Target Framework version of my project to v4.0.3 or higher, the type can be resolved and the project builds successfully.

Version Information

https://gist.github.com/pjcollins/03e44af172a79acd68ccf2d25dd129ae

@pjcollins pjcollins added Area: Bindings Issues in Java Library Binding projects. regression labels Jan 9, 2018
@pjcollins pjcollins added this to the d15-6 milestone Jan 9, 2018
@atsushieno
Copy link
Contributor

The Google documentation is a liar: there is NO setChoiceMode() in API Level 10.

image

@atsushieno
Copy link
Contributor

Therefore this is a bugfix. monodroid-samples should be fixed to not invoke nonexistent method.

@pjcollins
Copy link
Member Author

@atsushieno I am not sure about this, perhaps your local documentation is the one that is lying...

Here is a java port that has a min, target, and compile version of 10, and successfully uses the following code:

    String[] items = new String[] { "Vegetables", "Fruits", "Flower Buds", "Legumes", "Bulbs", "Tubers" };
    setListAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_checked, items));
    ListView lv = (ListView)findViewById(android.R.id.list);
    lv.setChoiceMode(1);

LVChoiceModeTest.zip

@pjcollins pjcollins reopened this Jan 10, 2018
@atsushieno
Copy link
Contributor

@jonpryor
Copy link
Member

@atsushieno: It's not AbsListView, it's ListView, which does contain a ListView.getChoiceMode() method.

Furthermore, src/Mono.Android/Profiles/api-10.xml.in contains a ListView.getChoiceMode() method:

    <class abstract="false" deprecated="not deprecated" extends="android.widget.AbsListView" extends-generic-aware="android.widget.AbsListView" final="false" name="ListView" static="false" visibility="publi
      ...
      <method abstract="false" deprecated="not deprecated" final="false" name="getChoiceMode" native="false" return="int" static="false" synchronized="false" visibility="public">

The oddity here is that the d15-6 binding of API-10 in Mono.Android.dll doesn't contain any mention of ChoiceMode:

# From extracted output of xamarin.android-8.2.0-4.pkg
$ monodis --method .../lib/xbuild-frameworks/MonoAndroid/v2.3/Mono.Android.dll | grep ChoiceMode
# no matches

Compare to e.g. 8.1:

$ monodis --method /Library/Frameworks/Xamarin.Android.framework/Versions/8.1.2-0/lib/xbuild-frameworks/MonoAndroid/v2.3/Mono.Android.dll | grep ChoiceMode
28486: default class [mscorlib]System.Delegate GetGetChoiceModeHandler ()  (param: 32420 impl_flags: cil managed )
28487: default int32 n_GetChoiceMode (native int jnienv, native int native__this)  (param: 32420 impl_flags: cil managed )
28488: default class [mscorlib]System.Delegate GetSetChoiceMode_IHandler ()  (param: 32422 impl_flags: cil managed )
28489: default void n_SetChoiceMode_I (native int jnienv, native int native__this, int32 native_choiceMode)  (param: 32422 impl_flags: cil managed )
28490: instance default valuetype Android.Widget.ChoiceMode get_ChoiceMode ()  (param: 32425 impl_flags: cil managed )
28491: instance default void set_ChoiceMode (valuetype Android.Widget.ChoiceMode 'value')  (param: 32425 impl_flags: cil managed )

I do not currently understand where the ListView.ChoiceMode property went: Profiles/api-10.xml.in mentions it, methodmap.csv mentions it...

...and I think I have the cause:

$ pwd
…/xamarin-android/src/Mono.Android

# Build API-10:
$ xbuild /v:diag /p:AndroidFrameworkVersion=v2.3 /p:AndroidApiLevel=10 > b.txt

The resulting b.txt contains:

                warning BG8700: Unknown return type Android.Widget.ChoiceMode in method GetChoiceMode in managed type Android.Widget.ListView.
                warning BG8800: Unknown parameter type Android.Widget.ChoiceMode in method SetChoiceMode in managed type Android.Widget.ListView.

The cause of this bug is a301764, which changed Android.Widget.ChoiceMode from being declared in API-1 to being declared in API-15.

@jonpryor jonpryor reopened this Jan 10, 2018
@jonpryor jonpryor changed the title No longer able to access Android.Widget.AbsListView.ChoiceMode when compiling against v2.3 in d15-6 No longer able to access Android.Widget.ChoiceMode when compiling against v2.3 in d15-6 Jan 10, 2018
@atsushieno
Copy link
Contributor

ChoiceMode was removed because they were generated from AbsListView fields which DOES NOT EXIST in API Level 10. And getChoiceMode() and setChoiceMode are removed because they expect NONEXISTENT enums.

Fortunately they are in ListView in API Level 10, so they can be generated from there.

Although, while I can build Mono.Android.dll for the profiles including android-10, make framework-assemblies fails and I cannot verify the entire build locally.

Build FAILED.
Errors:

src/Xamarin.Android.NUnitLite/Xamarin.Android.NUnitLite.csproj: error : /sources/xamarin-android/src/Xamarin.Android.NUnitLite/Xamarin.Android.NUnitLite.csproj: /sources/xamarin-android/src/Xamarin.Android.NUnitLite/Xamarin.Android.NUnitLite.csproj could not import "$(OutputPath)\..\..\..\xbuild\Xamarin\Android\Xamarin.Android.CSharp.targets"

	 0 Warning(s)
	 1 Error(s)

@atsushieno
Copy link
Contributor

To make sure: (1) ChoiceMode being removed in API Level 10 was correct. (2) Leaving ListView.SetChoiceMode() and .GetChoiceMode() to point to non-existent enum and not converting ListView. flelds to ChoiceMode is wrong (only when both conditions are met).

jonpryor pushed a commit to xamarin/xamarin-android-api-compatibility that referenced this issue Jan 17, 2018
Context: dotnet/android#1170
Context: dotnet/android#1183
Context: dotnet/android@a301764

Xamarin.Android 8.1 (d15-5) provides an `Android.Widget.ChoiceMode`
enum type in API-10+. `ChoiceMode` contains the
`android.widget.ListView.CHOICE_MODE_*` constants from API-10, which
were moved to `android.widget.AbsListView` in API-15.

Xamarin.Android 8.2 (d15-6) inadvertently *removed* the
`Android.Widget.ChoiceMode` enum, because
[xamarin-android/a301764a][xa-a301764a] altered the mapping of the
`CHOICE_MODE` constants so that they were only bound into the
`Android.Widget.ChoiceMode` enum for API-15+.

[xa-a301764a]: dotnet/android@a301764

[xamarin-android PR #1183][xa-1183] fixes `ChoiceMode` generation so
that it applies to API-10+, and in the process alters the API tracked
within xamarin-android-api-compatibility.

[xa-1183]: dotnet/android#1183

Add the `ChoiceMode` API changes so that [PR #1183][xa-1183] passes
the API compatibility tests.
jonpryor pushed a commit to xamarin/xamarin-android-api-compatibility that referenced this issue Jan 17, 2018
Context: dotnet/android#1170
Context: dotnet/android#1183
Context: dotnet/android@a301764

Xamarin.Android 8.1 (d15-5) provides an `Android.Widget.ChoiceMode`
enum type in API-10+. `ChoiceMode` contains the
`android.widget.ListView.CHOICE_MODE_*` constants from API-10, which
were moved to `android.widget.AbsListView` in API-15.

Xamarin.Android 8.2 (d15-6) inadvertently *removed* the
`Android.Widget.ChoiceMode` enum, because
[xamarin-android/a301764a][xa-a301764a] altered the mapping of the
`CHOICE_MODE` constants so that they were only bound into the
`Android.Widget.ChoiceMode` enum for API-15+.

[xa-a301764a]: dotnet/android@a301764

[xamarin-android PR #1183][xa-1183] fixes `ChoiceMode` generation so
that it applies to API-10+, and in the process alters the API tracked
within xamarin-android-api-compatibility.

[xa-1183]: dotnet/android#1183

Add the `ChoiceMode` API changes so that [PR #1183][xa-1183] passes
the API compatibility tests.
jonpryor pushed a commit that referenced this issue Jan 18, 2018
Fixes: #1170
Context: a301764

Bumps to xamarin-android-api-compatibility/master/6874e3f3

Xamarin.Android 8.1 (d15-5) provides an `Android.Widget.ChoiceMode`
enum type in API-10+, used by the
`Android.Widget.ListView.ChoiceMode` property.
`ChoiceMode` contains the `android.widget.ListView.CHOICE_MODE_*`
constants from API-10, which were moved to
`android.widget.AbsListView` in API-15.

Xamarin.Android 8.2 (d15-6) inadvertently *removed* the
`Android.Widget.ChoiceMode` enum, because
[xamarin-android/a301764a][xa-a301764a] altered the mapping of the
`CHOICE_MODE` constants so that they were only bound into the
`Android.Widget.ChoiceMode` enum for API-15+.

[xa-a301764a]: a301764

Removing the `ChoiceMode` enum in turn caused the
`ListView.ChoiceMode` property to be removed, as the
`ListView.getChoiceMode()` and `ListView.setChoiceMode()` methods
expected the (now nonexistent) `ChoiceMode` enum type.

Update `map.csv` so that the `CHOICE_MODE_*` values are mapped to the
`ChoiceMode` enum in API-10+, not API-15+, which restores the
`Android.Widget.ChoiceMode` enum type and the `ListView.ChoiceMode`
property.
@pjcollins
Copy link
Member Author

Verified fixed in monodroid/d15-6/09b922fe.

@ghost ghost locked as resolved and limited conversation to collaborators Jun 9, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Area: Bindings Issues in Java Library Binding projects. regression
Projects
None yet
Development

No branches or pull requests

3 participants