This is Xamarin's bug tracking system. For product support, please use the support links listed in your Xamarin Account.
Bug 17630 - Bugs with Android Runtime (ART) in 4.12
Summary: Bugs with Android Runtime (ART) in 4.12
Status: RESOLVED FIXED
Alias: None
Product: Android
Classification: Xamarin
Component: Pre-release (show other bugs)
Version: 4.12.0
Hardware: PC Windows
: Normal normal
Target Milestone: 4.12.3
Assignee: Jonathan Pryor
URL:
: 17815 (view as bug list)
Depends on:
Blocks:
 
Reported: 2014-02-05 21:52 UTC by Philipp
Modified: 2014-03-26 09:08 UTC (History)
4 users (show)

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


Attachments
Test app demonstrating the exceptions (button 1 shows exception, button 2 works, button 3 crashes) (13.26 KB, application/x-zip-compressed)
2014-02-05 21:52 UTC, Philipp
Details

Description Philipp 2014-02-05 21:52:11 UTC
Created attachment 5984 [details]
Test app demonstrating the exceptions (button 1 shows exception, button 2 works, button 3 crashes)

I just tested my app with the 4.12 alpha on ART (Nexus 7, Android 4.4.2). I experienced two problems which can are demonstrated by the simple app in the attachment.

1.) This is the same problem as described in https://bugzilla.xamarin.com/show_bug.cgi?id=17414: Calling StartActivity results in "android.util.AndroidRuntimeException: Calling startActivity() from outside of an Activity  context requires the FLAG_ACTIVITY_NEW_TASK flag. Is this really what you want?"
I'd like to add the information that startActivityForResult() works without this problem.

2.) calling AddPreferencesFromResource() (either in PreferenceActivity or PreferenceFragment) results in the exception "This should be called after super.onCreate", even though base.OnCreate() was called before (full stacktrace below)

The app runs fine on Dalvik.


02-06 03:35:09.221 I/MonoDroid( 6361): UNHANDLED EXCEPTION: Java.Lang.RuntimeException: Exception of type 'Java.Lang.RuntimeException' was thrown.
02-06 03:35:09.221 I/MonoDroid( 6361): at Android.Runtime.JNIEnv.CallNonvirtualVoidMethod (intptr,intptr,intptr,Android.Runtime.JValue[]) [0x00084] in /Users/builder/data/lanes/monodroid-mlion-monodroid-4.12-series/56127394/source/monodroid/src/Mono.Android/src/Runtime/JNIEnv.g.cs:895
02-06 03:35:09.221 I/MonoDroid( 6361): at Android.Preferences.PreferenceFragment.AddPreferencesFromResource (int) [0x00070] in /Users/builder/data/lanes/monodroid-mlion-monodroid-4.12-series/56127394/source/monodroid/src/Mono.Android/platforms/android-15/src/generated/Android.Preferences.PreferenceFragment.cs:284
02-06 03:35:09.221 I/MonoDroid( 6361): at ArtTestApp.PrefActivity/AppPreferenceFragment.OnCreate (Android.OS.Bundle) [0x00009] in c:\Users\Philipp\Documents\keepass2android\repo\keepass2android\src\ArtTestApp\PrefActivity.cs:31
02-06 03:35:09.221 I/MonoDroid( 6361): at Android.App.Fragment.n_OnCreate_Landroid_os_Bundle_ (intptr,intptr,intptr) [0x00011] in /Users/builder/data/lanes/monodroid-mlion-monodroid-4.12-series/56127394/source/monodroid/src/Mono.Android/platforms/android-15/src/generated/Android.App.Fragment.cs:873
02-06 03:35:09.221 I/MonoDroid( 6361): at (wrapper dynamic-method) object.728fc937-a61f-4cb0-8140-201bff210f43 (intptr,intptr,intptr) <IL 0x00017, 0x00043>
02-06 03:35:09.221 I/MonoDroid( 6361): 
02-06 03:35:09.221 I/MonoDroid( 6361):   --- End of managed exception stack trace ---
02-06 03:35:09.221 I/MonoDroid( 6361): java.lang.RuntimeException: This should be called after super.onCreate.
02-06 03:35:09.221 I/MonoDroid( 6361): 	at android.preference.PreferenceFragment.requirePreferenceManager(PreferenceFragment.java:318)
02-06 03:35:09.221 I/MonoDroid( 6361): 	at android.preference.PreferenceFragment.addPreferencesFromResource(PreferenceFragment.java:283)
02-06 03:35:09.221 I/MonoDroid( 6361): 	at arttestapp.PrefActivity_AppPreferenceFragment.n_onCreate(Native Method)
02-06 03:35:09.221 I/MonoDroid( 6361): 	at arttestapp.PrefActivity_AppPreferenceFragment.onCreate(PrefActivity_AppPreferenceFragment.java:28)
02-06 03:35:09.221 I/MonoDroid( 6361): 	at android.app.Fragment.performCreate(Fragment.java:1678)
02-06 03:35:09.221 I/MonoDroid( 6361): 	at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:859)
02-06 03:35:09.221 I/MonoDroid( 6361): 	at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1062)
02-06 03:35:09.221 I/MonoDroid( 6361): 	at android.app.BackStackRecord.run(BackStackRecord.java:684)
02-06 03:35:09.221 I/MonoDroid( 6361): 	at android.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1447)
02-06 03:35:09.221 I/MonoDroid( 6361): 	at android.app.Activity.performStart(Activity.java:5240)
02-06 03:35:09.221 I/MonoDroid( 6361): 	at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2168)
02-06 03:35:09.221 I/MonoDroid( 6361): 	at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245)
02-06 03:35:09.221 I/MonoDroid( 6361): 	at android.app.ActivityThread.access$800(ActivityThread.java:135)
02-06 03:35:09.221 I/MonoDroid( 6361): 	at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
02-06 03:35:09.221 I/MonoDroid( 6361): 	at android.os.Handler.dispatchMessage(Handler.java:102)
02-06 03:35:09.221 I/MonoDroid( 6361): 	at android.os.Looper.loop(Looper.java:136)
02-06 03:35:09.221 I/MonoDroid( 6361): 	at android.app.ActivityThread.main(ActivityThread.java:5017)
02-06 03:35:09.221 I/MonoDroid( 6361): 	at java.lang.reflect.Method.invoke(Native Method)
02-06 03:35:09.221 I/MonoDroid( 6361): 	at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
02-06 03:35:09.221 I/MonoDroid( 6361): 	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
Comment 1 PJ 2014-02-06 16:31:18 UTC
Thanks for the report Philipp.

You've probably seen this already, but it's worth re-adding the info from bug 17414#c1

> Note: I know XA 4.12 has a workaround to better run on ART, but you still
> shouldn't actually use ART unless you're a Google Partner or, well, me:
> http://source.android.com/devices/tech/dalvik/art.html

>> Important: Dalvik must remain the default runtime or you risk breaking your
>> Android implementations and third-party applications.

Appreciate the test case as well, thanks!
Comment 2 Jonathan Pryor 2014-02-07 16:17:31 UTC
The "Calling startActivity() from outside of an Activity context requires the FLAG_ACTIVITY_NEW_TASK flag" error  has been filed upstream as:

https://code.google.com/p/android/issues/detail?id=65710

(Apparently ART implements JNIEnv::CallNonvritualVoidMethod() differently from Dalvik.)
Comment 3 Jonathan Pryor 2014-02-07 16:35:25 UTC
I don't see a problem with the "StartActivityForResult" button (is there anything I need to do other than tap the button?).

I believe that the issue with the "Start Preference Activity" button is the same as Comment #2: ART is FUBAR wrt JNIEnv::CallNonvirtualVoidMethod().
Comment 4 Philipp 2014-02-08 00:22:14 UTC
@jonp: thanks for the fast reply and forwarding!

I just added the StartActivityForResult button to demonstrate that there is no problem with it (in contrast to StartActivity()) because I thought this might help. So this bug is completely resolved (upstream)! Thanks!
Comment 5 Jonathan Pryor 2014-02-10 12:07:00 UTC
Further investigation (see also the Android Issue in Comment #2) shows that this is a Xamarin.Android bug, in that we've been calling JNIEnv::CallNonvirtual*Method() incorrectly (since ~forever).

This is fixed in monodroid/3155f27b9 and monodroid-4.12-series/0f028e1ba.
Comment 6 narayanp 2014-02-12 10:22:12 UTC
I have checked this issue with following builds:

All Windows
X.S 4.2.4(build 17)
X.Android 4.12.0-22

I have run attached sample on physical device and after clicking on three buttons, I am not seeing any exception.
Comment 7 Jonathan Pryor 2014-02-14 17:00:55 UTC
Reopening, as the fix is wrong; see also:

https://bugzilla.xamarin.com/show_bug.cgi?id=17750#c6
Comment 8 Jonathan Pryor 2014-02-20 12:19:50 UTC
Fixed (for reals this time?) in monodroid/4d1cf981.
Comment 9 Jonathan Pryor 2014-03-26 09:08:28 UTC
*** Bug 17815 has been marked as a duplicate of this bug. ***

Note You need to log in before you can comment on or make changes to this bug.