Bug 21159 - Incorrect 'super' constructor in generated Java in class that inherits android.graphics.Canvas
Summary: Incorrect 'super' constructor in generated Java in class that inherits androi...
Status: VERIFIED FIXED
Alias: None
Product: Android
Classification: Xamarin
Component: MSBuild ()
Version: 4.20.0
Hardware: Macintosh Mac OS
: Normal normal
Target Milestone: 5.0
Assignee: Jonathan Pryor
URL:
Depends on:
Blocks:
 
Reported: 2014-07-07 17:01 UTC by Christopher Blackman
Modified: 2015-02-25 19:33 UTC (History)
6 users (show)

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

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:
Status:
VERIFIED FIXED

Comment 2 Udham Singh 2014-07-08 05:51:10 UTC
I have checked this issue with steps provided in bug description and observed the same behavior mentioned in bug description. Please refer the screencast : http://screencast.com/t/BAoCOM0bx02

Error Log : https://gist.github.com/anonymous/9654816cc2628f0f5299
Build Output : https://gist.github.com/anonymous/1f9c586411bf844e7188 

Environment Info : 

=== Xamarin Studio ===

Version 5.3 (build 130)
Installation UUID: 011d70a5-dede-428b-ab04-ef451c2e539d
Runtime:
	Mono 3.4.0 ((no/954ed3c)
	GTK+ 2.24.23 (Raleigh theme)

	Package version: 304000214

=== Xamarin.Android ===

Version: 4.15.0 (Business Edition)
Android SDK: /Users/MM/Desktop/android-sdk-macosx
	Supported Android versions:
		2.1   (API level 7)
		2.2   (API level 8)
		2.3   (API level 10)
		3.1   (API level 12)
		3.2   (API level 13)
		4.0   (API level 14)
		4.0.3 (API level 15)
		4.1   (API level 16)
		4.2   (API level 17)
		4.3   (API level 18)
		4.4   (API level 19)
Java SDK: /usr
java version "1.6.0_65"
Java(TM) SE Runtime Environment (build 1.6.0_65-b14-462-11M4609)
Java HotSpot(TM) 64-Bit Server VM (build 20.65-b04-462, mixed mode)

=== Apple Developer Tools ===

Xcode 5.1 (5084)
Build 5B130a

=== Xamarin.iOS ===

Version: 7.2.5.4 (Business Edition)
Hash: e7f4f92
Branch: 
Build date: 2014-06-18 02:37:27-0400

=== Xamarin.Mac ===

Version:

=== Build Information ===

Release ID: 503000130
Git revision: 79ca5165dbae8f4970e68b0817bd1685aea5a037
Build date: 2014-07-07 12:25:53-04
Xamarin addins: 011e11d01cd00e977a052d9c73f66f0852f379b3

=== Operating System ===

Mac OS X 10.9.2
Darwin MacMini.local 13.1.0 Darwin Kernel Version 13.1.0
    Thu Jan 16 19:40:37 PST 2014
    root:xnu-2422.90.20~2/RELEASE_X86_64 x86_64
Comment 3 Jonathan Pryor 2014-08-08 17:28:22 UTC

*** This bug has been marked as a duplicate of bug 21934 ***
Comment 4 John Pilczak 2014-11-13 16:58:31 UTC
It appears that this bug was not a complete duplicate of 21934 because I am still running into this one while using XA 4.20. The build error appears when attempting to inherit from Canvas and the target framework version is set to anything above Android version 2.3 Gingerbread.

Repro Project: https://www.dropbox.com/s/bq46gpol7suwjkn/CanvasTest.zip?dl=0

Environment Info:
=== Xamarin Studio ===

Version 5.7 (build 527)
Installation UUID: ea2dde6b-0915-4e87-bf59-0163cddeada5
Runtime:
	Mono 3.10.0 ((detached/633e444)
	GTK+ 2.24.23 (Raleigh theme)

	Package version: 310000020

=== Apple Developer Tools ===

Xcode 6.1 (6539)
Build 6A1046a

=== Xamarin.iOS ===

Version: 8.2.0.193 (Business Edition)
Hash: 959c1e4
Branch: 
Build date: 2014-10-03 00:25:37-0400

=== Xamarin.Android ===

Version: 4.20.0.24 (Business Edition)
Android SDK: /Users/johnpilczak/Library/Developer/Xamarin/android-sdk-macosx
	Supported Android versions:
		4.0.3  (API level 15)
		4.4.87 (API level 20)
Java SDK: /usr
java version "1.7.0_65"
Java(TM) SE Runtime Environment (build 1.7.0_65-b17)
Java HotSpot(TM) 64-Bit Server VM (build 24.65-b04, mixed mode)

=== Xamarin.Mac ===

Version: 1.11.1.3 (Starter Edition)

=== Build Information ===

Release ID: 507000527
Git revision: 6aafba2eb053ce9d1454096c864d82b150b176a3
Build date: 2014-11-11 12:24:36-05
Xamarin addins: 52fe8b64c97efd312cc41f00f2854e607454af5c

=== Operating System ===

Mac OS X 10.9.5
Darwin Vinces-xMac.local 13.4.0 Darwin Kernel Version 13.4.0
    Sun Aug 17 19:50:11 PDT 2014
    root:xnu-2422.115.4~1/RELEASE_X86_64 x86_64
Comment 5 Jonathan Pryor 2014-11-13 21:47:51 UTC
This is API breakage performed by Google in Honeycomb. (Kinda funny that we don't notice it until Lollypop...)

Long ago, Google would provide provide the Android API in XML form, and API-4 through 10) contains: https://github.com/android/platform_frameworks_base/blob/froyo/api/4.xml

	<class name="Canvas"
	 extends="java.lang.Object"
	 abstract="false"
	 static="false"
	 final="false"
	 deprecated="not deprecated"
	 visibility="public"
	>
	<constructor name="Canvas"
	 type="android.graphics.Canvas"
	 static="false"
	 final="false"
	 deprecated="not deprecated"
	 visibility="public"
	>
	</constructor>
	<constructor name="Canvas"
	 type="android.graphics.Canvas"
	 static="false"
	 final="false"
	 deprecated="not deprecated"
	 visibility="public"
	>
	<parameter name="bitmap" type="android.graphics.Bitmap">
	</parameter>
	</constructor>
	<constructor name="Canvas"
	 type="android.graphics.Canvas"
	 static="false"
	 final="false"
	 deprecated="not deprecated"
	 visibility="public"
	>
	<parameter name="gl" type="javax.microedition.khronos.opengles.GL">
	</constructor>

Not exactly "readable", but the above XML fragment declares the Canvas type and the Canvas constructors:

    public class Canvas extends java.lang.Object {
        public Canvas ();
        public Canvas (android.graphics.Bitmap bitmap);
        public Canvas (javax.microedition.khronos.opengles.GL gl);
        // ...
    }

So that's where the constructor came from, and (silly us?) we just assumed that the constructor would stick around, because if you built code against API-4 you'd have a reasonable expectation that it would still compile against later versions...

So let us see what API-11 declares: https://github.com/android/platform_frameworks_base/blob/ics-factoryrom-2-release/api/11.xml

	<class name="Canvas"
	 extends="java.lang.Object"
	 abstract="false"
	 static="false"
	 final="false"
	 deprecated="not deprecated"
	 visibility="public"
	>
	<constructor name="Canvas"
	 type="android.graphics.Canvas"
	 static="false"
	 final="false"
	 deprecated="not deprecated"
	 visibility="public"
	>
	</constructor>
	<constructor name="Canvas"
	 type="android.graphics.Canvas"
	 static="false"
	 final="false"
	 deprecated="not deprecated"
	 visibility="public"
	>
	<parameter name="bitmap" type="android.graphics.Bitmap">
	</parameter>
	</constructor>

There is no Canvas(javax.microedition.khronos.opengles.GL) constructor anymore. It's a "hard" API break between API-10 and API-11.
Comment 6 Jonathan Pryor 2014-11-13 21:51:54 UTC
Comment #5 has the explanation for why it's happening.

The only workaround I can think of is to only target API <= 10 in an assembly inheriting from Android.Graphics.Canvas, and *never* use that constructor.

The bigger question is how to fix it. :-(

We could just remove the erroneous constructor entirely. That's simple and straightforward and an API break, but it would be the easiest thing to do.

The only other option that comes to mind is to somehow mark the method as not existing in API >= 11, and have the Java generator skip the method as appropriate. That seems more correct, but also less likely to happen.

(The bigger bigger question is, does this happen for any other APIs? *shudder*)
Comment 7 Jonathan Pryor 2014-11-20 15:59:22 UTC
Fixed in monodroid/2ec5ecb7.

Implementation option (2) wasn't as bad as I feared; we strip out the "normal" JNI-based method in API-11+, and replace it with a hand-written method which is [Obsolete("...", error:true)].

This prevents the ACW generator from emitting that constructor (no [Register] info), and nicely reports an error via CSC if anybody attempts to use the (nonexistent!) constructor.
Comment 8 Udham Singh 2014-11-26 09:46:19 UTC
I have checked this issue with builds below

Mac OS X 10.9.4
Xamarin Studio : 5.7 (build 596)
Mono 3.12.0 ((detached/b75fa2b)
GTK+ 2.24.23 (Raleigh theme)
Xcode 6.1 (6602)
Xamarin.iOS : 8.6.0.5 (Enterprise Edition)

Now this is working fine. Hence closing this issue.

Screencast : http://www.screencast.com/t/xsjHX0xgDvdm