Bug 24967 - ApiDemo crashes on launch with ClassNotFoundException
Summary: ApiDemo crashes on launch with ClassNotFoundException
Status: VERIFIED FIXED
Alias: None
Product: Android
Classification: Xamarin
Component: General ()
Version: 5.0
Hardware: PC Mac OS
: High critical
Target Milestone: 5.1
Assignee: Peter Collins
URL:
Depends on:
Blocks:
 
Reported: 2014-12-01 17:27 UTC by Peter Collins
Modified: 2015-04-09 08:12 UTC (History)
2 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

Description Peter Collins 2014-12-01 17:27:23 UTC
This bug is being split off from https://bugzilla.xamarin.com/show_bug.cgi?id=24798#c1. ApiDemo now crashes immediately when attempting to deploy to device. This is a regression from XA 4.20-series. I am able to reproduce this when installing from command line and the IDE.

I did just notice that two identical "ApiDemo (XA)" icons show up in the app drawer after installing this sample, though it appears that only one package is installed when looking through installed packages. The of these icons in the app drawer dies immediately on launch due to this issue. The other does not crash immediately on launch, but does so after a bit of navigation (tap Animation -> Simple Transitions).

Repro:
https://github.com/xamarin/monodroid-samples/tree/master/ApiDemo

Diagnostic install output:
https://gist.github.com/pjcollins/a427b8d4f120242dd25c

Logcat:
https://gist.github.com/pjcollins/b6ad048610f7cf37deb3

Environment:
OSX Yosemite
XA 5.0-branch / bfc383b0
Comment 2 Jonathan Pryor 2014-12-02 11:00:25 UTC
ApiDemo crashes because there is a mismatch between the ACW names and the names used in Properties\AndroidManifest.xml.

For example, Prioperties\AndroidManifest.xml uses monodroid.apidemo.ApiDemo, which no longer exists; it is now md5167e58e8f319da338ec0d9dde0f2b53b.ApiDemo.

ApiDemo needs to be updated.

There are three potential fixes:

1. Update Properties\AndroidManifest.xml to use the new names.

For the love of all that is good and holy, DO NOT DO THIS.

2. Alter the types referenced by Properties\AndroidManifest.xml to specify the names used in Properties\AndroidManifest.xml:

	[Activity (Label = "Api Demo (XA)",
			Name="monodroid.apidemo.ApiDemo",
			MainLauncher = true)]
	public class ApiDemo : ListActivity {...}

3. Update Properties\AndroidManifest.xml to REMOVE elements that can be generated, and update the classes to enable this to work.

(2) works, but I wouldn't prefer it because you're still specifying type information in two separate places that need to be kept in sync: Properties\AndroidManifest.xml and the source code. (3) would be my preference.

(3) should be simple for *most* items in Properties\AndroidManifest.xml, e.g. for monodroid.apidemo.ApiDemo, monodroid.apidemo.AppUpdateReceiver, etc.

Unfortunately, (3) isn't appropriate for all of them, e.g. activities which use //activity/@android:enabled with a resource reference, as ActivityAttribute.Enabled doesn't support resource references:

	<activity
			android:label="@string/action_bar_display_options"
			android:name="monodroid.apidemo.ActionBarDisplayOptionsActivity"
			android:logo="@drawable/apidemo_androidlogo"
			android:enabled="@bool/atLeastHoneycomb">
		<intent-filter>
			<action android:name="android.intent.action.MAIN" />
			<category android:name="mono.apidemo.sample" />
		</intent-filter>
	</activity>

For these situations, (2) will be required.
Comment 3 Peter Collins 2014-12-02 18:44:11 UTC
Fixed in https://github.com/xamarin/monodroid-samples/commit/397b52b0c27c073f38ba8957d648d5b25275ca7b

I'm still unsure as to why nested classes in this sample needed a Register attribute in order to be found, attempts to boil that scenario down into a smaller test case did not fail in the same fashion. This will likely warrant a bit more investigation.
Comment 4 Mohit Kheterpal 2015-04-09 08:12:14 UTC
 I have checked this issue using XA 5.1.0.102 and monodroid samples : 0f42ae69053bc97b4d698f9d5d9443d306b1ec18 and observed that this issue is working fine i.e. APIDemo does not crashes on launching on device.  I have checked it on Moto X Version : 5.0.