Bug 17342 - Bound Java types cannot be accessed using C# fully qualified names in layout files (ClassNotFoundException)
Summary: Bound Java types cannot be accessed using C# fully qualified names in layout ...
Alias: None
Product: Android
Classification: Xamarin
Component: Bindings ()
Version: 4.12.0
Hardware: PC Mac OS
: Normal enhancement
Target Milestone: ---
Assignee: Atsushi Eno
Depends on:
Reported: 2014-01-20 21:12 UTC by Brendan Zagaeski (Xamarin Team, assistant)
Modified: 2017-06-27 17:39 UTC (History)
3 users (show)

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

Test case (582.11 KB, application/zip)
2014-01-20 21:12 UTC, Brendan Zagaeski (Xamarin Team, assistant)

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 for Bug 17342 on Developer Community or GitHub if you have new information to add and do not yet see a matching new report.

If the latest results still closely match this report, you can use the original description:

  • Export the original title and description: Developer Community HTML or GitHub Markdown
  • Copy the title and description into the new report. Adjust them to be up-to-date if needed.
  • Add your new information.

In special cases on GitHub you might also want the comments: GitHub Markdown with public comments

Related Links:

Description Brendan Zagaeski (Xamarin Team, assistant) 2014-01-20 21:12:41 UTC
Created attachment 5877 [details]
Test case

I wouldn't be surprised if this has come up before, but I haven't found another bug report for it. Feel free to mark as a duplicate, or WONTFIX.

## Issue

When a class has an Android Callable Wrapper, it is accessible from .axml layout files using _either_ the fully qualified Java name, or the fully qualified C# name.

When a class does _not_ have an ACW (for example, a bound type from an Android binding project), it is only accessible from .axml files by using the fully qualified Java name.

## Steps to reproduce

1. Build and run the attached test case.

### Result: error

> Android.Views.InflateException: Binary XML file line #1: Error inflating class TestAndroidLib.MyJavaView

... and in the Java stack trace:

> Caused by: java.lang.ClassNotFoundException: TestAndroidLib.MyJavaView

2. Replace "TestAndroidLib.MyJavaView" in Main.axml with each of the following values. In each case, rebuild and run the the app to test.

  A. "com.example.testandroidlib.MyJavaView"
  B. "RegisterLayoutTest.MyView"
  C. "registerlayouttest.MyView"

### Result: success

In all three cases, the app builds and runs without error. Note that the MyView class is a C# subclass of the Android.Views.View class. As a result, the user may refer to MyView in Main.axml using either the fully qualified C# name or the fully qualified Java name.

## Possible improvements

Perhaps some extra trick could be added to allow the use of fully qualified C# names in .axml files for types that lack Android Callable Wrappers?

Comment 1 Atsushi Eno 2014-02-03 06:42:24 UTC
Cannot reproduce with the latest alpha (4.12) on Mac or Windows. I don't think we have changed the resource builds so I doubt in general but could you please try the latest alpha and see if it reproduces?
Comment 2 Brendan Zagaeski (Xamarin Team, assistant) 2014-02-13 23:59:52 UTC
Double-checked on:
XamarinVS.Android 4.12.00022 on Windows
Xamarin.Android 4.12.0-22 on Mac
Xamarin.Android 4.12.0-12 on Mac

Checked with 4.12.0-22 on both and Android 4.1.2 device, and Android 4.4 device. Note that the error only happens at run time. I wasn't too clear about that before.
Comment 3 Brendan Zagaeski (Xamarin Team, assistant) 2014-04-04 18:19:16 UTC
I forgot to set this to "NEW" after replying with the extra information.

To give another small update, I've just checked that the behavior is still the same on Xamarin.Android 4.13.0-180 on Mac, on both an Android 4.3 emulator and an Android 4.1.2 device.
Comment 4 Jonathan Pryor 2014-07-28 15:55:39 UTC
This looks like a dupe of Bug #2257, and may be fixed in 4.16.
Comment 5 Chris Hardy [MSFT] 2017-06-27 17:11:58 UTC
Thank you for taking the time to submit this report. After reviewing the description of this bug, we believe it no longer affects the current version of Xamarin.Android. If you are still experiencing the issue after updating your packages, please reopen this report with an attached reproduction.
Comment 6 Brendan Zagaeski (Xamarin Team, assistant) 2017-06-27 17:39:14 UTC
## Verification status: this enhancement is not currently implemented

> "BAD": Xamarin.Android (5f3167a) (unpublished candidate for the next "15.3 release" Beta version)

## "BAD" results when using "TestAndroidLib.MyJavaView" in Main.axml

Excerpt from the stack trace:

[MonoDroid] Android.Views.InflateException: Binary XML file line #1: Binary XML file line #1: Error inflating class TestAndroidLib.MyJavaView ---> Android.Views.InflateException: Binary XML file line #1: Error inflating class TestAndroidLib.MyJavaView ---> Java.Lang.ClassNotFoundException: Didn't find class "TestAndroidLib.MyJavaView" on path: DexPathList[[zip file "/data/app/RegisterLayoutTest.RegisterLayoutTest-1/base.apk"],nativeLibraryDirectories=[/data/app/RegisterLayoutTest.RegisterLayoutTest-1/lib/x86, /data/app/RegisterLayoutTest.RegisterLayoutTest-1/base.apk!/lib/x86, /vendor/lib, /system/lib]]

## GOOD results when using each of the options A-C from Comment 0

The app builds and runs without error.

## Additional testing environment info

Mono (2017-04/4498dc4) (64-bit)

Android SDK Tools Version: 25.2.5
Android SDK Platform Tools Version: 25.0.3
Android SDK Build Tools Version: 25

Java JDK 8u65 (1.8.0_65), 64-bit

macOS 10.12.5

### Devices

Google Android API 23 x86 emulator