Bug 29263

Summary: Experiencing android.view.InflateException when defining a custom preference via class.
Product: Android Reporter: David Thornley <david.thornley>
Component: GeneralAssignee: dean.ellis
Severity: normal CC: mono-bugs+monodroid, nicholas.spagnola, peter.collins, prashantm
Priority: Normal    
Version: 5.1   
Target Milestone: 5.1.1 (C5SR1)   
Hardware: PC   
OS: Mac OS   
Tags: Is this bug a regression?: ---
Last known good build:
Attachments: Code Sample Project

Description David Thornley 2015-04-21 01:45:55 UTC
Created attachment 10835 [details]
Code Sample Project

Supplied code sample works fine on Android Stable (4.20.x) but noticed it failing in Alpha a few weeks ago. It seems the Alpha has recently been promoted to Beta (5.1.x) and the issue still remains, hence this report. :)

Code is simple, PreferenceActivity with custom preference element defined as "testinflateexception.CustomPreference". The class is present in TestInflateException.CustomPreference. 

Compiles and runs fine in but fails with exception in Exception indicates android runtime is stuck in an infinite loop looking for the class. The IDE does not seem to always catch the exception. See below: -


[AndroidRuntime] Process: com.companyname.test, PID: 15037
[AndroidRuntime] java.lang.RuntimeException: Unable to start activity ComponentInfo{com.companyname.test/md5cdc4636fb26ffe0d36b110f63734d668.MainActivity}: android.view.InflateException: Binary XML file line #8: Error inflating class testinflateexception.CustomPreference
[AndroidRuntime] 	at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2298)
[AndroidRuntime] 	at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2360)
[AndroidRuntime] 	at android.app.ActivityThread.access$800(ActivityThread.java:144)
[AndroidRuntime] 	at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1278)
[AndroidRuntime] 	at android.os.Handler.dispatchMessage(Handler.java:102)
[AndroidRuntime] 	at android.os.Looper.loop(Looper.java:135)
[AndroidRuntime] 	at android.app.ActivityThread.main(ActivityThread.java:5221)
[AndroidRuntime] 	at java.lang.reflect.Method.invoke(Native Method)
[AndroidRuntime] 	at java.lang.reflect.Method.invoke(Method.java:372)
[AndroidRuntime] 	at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
[AndroidRuntime] 	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
[AndroidRuntime] Caused by: android.view.InflateException: Binary XML file line #8: Error inflating class testinflateexception.CustomPreference
[AndroidRuntime] 	at android.preference.GenericInflater.createItemFromTag(GenericInflater.java:441)
[AndroidRuntime] 	at android.preference.GenericInflater.rInflate(GenericInflater.java:481)
[AndroidRuntime] 	at android.preference.GenericInflater.inflate(GenericInflater.java:326)
[AndroidRuntime] 	at android.preference.GenericInflater.inflate(GenericInflater.java:263)
[AndroidRuntime] 	at android.preference.PreferenceManager.inflateFromResource(PreferenceManager.java:272)
[AndroidRuntime] 	at android.preference.PreferenceActivity.addPreferencesFromResource(PreferenceActivity.java:1513)
[AndroidRuntime] 	at md5cdc4636fb26ffe0d36b110f63734d668.MainActivity.n_onCreate(Native Method)
[AndroidRuntime] 	at md5cdc4636fb26ffe0d36b110f63734d668.MainActivity.onCreate(MainActivity.java:28)
[AndroidRuntime] 	at android.app.Activity.performCreate(Activity.java:5933)
[AndroidRuntime] 	at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1105)
[AndroidRuntime] 	at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2251)
[AndroidRuntime] 	... 10 more

=== Xamarin Studio ===

Version 5.9 (build 427)
Installation UUID: 9f6e6705-d675-4efd-bef2-cddbf8240838
	Mono 4.0.0 ((detached/d136b79)
	GTK+ 2.24.23 (Raleigh theme)

	Package version: 400000143

=== Apple Developer Tools ===

Xcode 6.3 (7569)
Build 6D570

=== Xamarin.iOS ===

Version: (Starter Edition)
Hash: c2c0012
Branch: master
Build date: 2015-04-14 17:26:21-0400

=== Xamarin.Android ===

Version: (Business Edition)
Android SDK: /Users/davidthornley/dev/android/android-sdk-macosx
	Supported Android versions:
		2.3    (API level 10)
		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)
		4.4.87 (API level 20)
		5.0    (API level 21)
Java SDK: /usr
java version "1.6.0_65"
Java(TM) SE Runtime Environment (build 1.6.0_65-b14-466.1-11M4716)
Java HotSpot(TM) 64-Bit Server VM (build 20.65-b04-466.1, mixed mode)

=== Xamarin Android Player ===

Version: Unknown version
Location: /Applications/Xamarin Android Player.app

=== Xamarin.Mac ===

Not Installed

=== Build Information ===

Release ID: 509000427
Git revision: 04666fd43a57b4782529cad9723ce1f54926fe6c
Build date: 2015-04-14 18:06:43-04
Xamarin addins: 791954691dfbc403676a103e52a0bb9754b9af29

=== Operating System ===

Mac OS X 10.10.2
Darwin SYD234MBP 14.1.0 Darwin Kernel Version 14.1.0
    Thu Feb 26 19:26:47 PST 2015
    root:xnu-2782.10.73~1/RELEASE_X86_64 x86_64
Comment 1 Jonathan Pryor 2015-04-21 14:39:15 UTC
The cause for the crash is that XML Resources do not partake in typename fixup:

> Task "ConvertResourcesCases"
> 	Using task ConvertResourcesCases from Xamarin.Android.Tasks.ConvertResourcesCases, Xamarin.Android.Build.Tasks, Version=, Culture=neutral, PublicKeyToken=null
> 	ConvertResourcesCases Task
> 	  ResourceDirectories: obj/Debug/res/
> 	  AcwMapFile: obj/Debug/acw-map.txt
> 	  Processing: obj/Debug/res/layout/main.xml
> 	  Processing: obj/Debug/res/values/strings.xml

Note that `obj/Debug/res/xml/preferences.xml` is not listed in the above diagnostic output fragment.

Dean: Why doesn't the <ConvertResourcesCases/> task fixup XML resources? Doing so fixes the bug.
Comment 2 dean.ellis 2015-04-21 14:59:29 UTC
I'll double check and add a Unit test for this so we don't miss this case again
Comment 3 dean.ellis 2015-04-22 10:29:26 UTC
Fixed in monodroid/master/1db60316

will look at back porting to 5.1
Comment 5 David Thornley 2015-04-30 20:46:54 UTC
Will this be back ported to Xamario.Android 5.1.0 as mentioned above? Since XS 5.9 and consequently XA 5.1.0 are now promoted to the 'stable' channel, this is a show-stopper for us...

Lastly, how do I get access to XS 6? It doesn't seem to be in the alpha channel yet.