Bug 39267 - Android Exception: DrawerLayout must be measured with MeasureSpec.EXACTLY when rotated
Summary: Android Exception: DrawerLayout must be measured with MeasureSpec.EXACTLY whe...
Status: RESOLVED NOT_REPRODUCIBLE
Alias: None
Product: Forms
Classification: Xamarin
Component: Android ()
Version: 2.0.0
Hardware: PC Windows
: --- normal
Target Milestone: ---
Assignee: Jason Smith [MSFT]
URL:
Depends on:
Blocks:
 
Reported: 2016-03-01 20:46 UTC by Caan Mee
Modified: 2017-06-19 22:39 UTC (History)
4 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:
RESOLVED NOT_REPRODUCIBLE

Description Caan Mee 2016-03-01 20:46:07 UTC
Hello,

we are using Xamarin.Forms 2.0.1 (stable) and experienced a crash using a MasterDetailPage when doing the following:

1) App is sent to background (Portrait mode)
2) SmartPhone is being rotated to landscape mode (90° left)
3) App is being resumed in this landscape orientation
4) The underneath crash occurs

We specified in the manifest to allow only Portrait mode and support no orientation changes.

Java.Lang.RuntimeExceptionDrawerLayout must be measured with MeasureSpec.EXACTLY.

System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
Android.Runtime.JNIEnv.CallVoidMethod(IntPtr jobject, IntPtr jmethod, JValue* parms)
Android.Views.View.Measure(int widthMeasureSpec, int heightMeasureSpec)
Xamarin.Forms.Platform.Android.VisualElementTracker.UpdateLayout()
Xamarin.Forms.Platform.Android.AppCompat.MasterDetailPageRenderer.Xamarin.Forms.Platform.Android.IVisualElementRenderer.UpdateLayout()
Xamarin.Forms.Platform.Android.AppCompat.Platform.Xamarin.Forms.Platform.Android.IPlatformLayout.OnLayout(bool changed, int l, int t, int r, int b)
Xamarin.Forms.Platform.Android.PlatformRenderer.OnLayout(bool changed, int l, int t, int r, int b)
Android.Views.ViewGroup.n_OnLayout_ZIIII(IntPtr jnienv, IntPtr native__this, bool changed, int l, int t, int r, int b)
at (wrapper dynamic-method) System.Object:5c7c337b-5c9c-4af9-8a30-fb2c02b25fe1 (intptr,intptr,bool,int,int,int,int)
--- End of managed exception stack trace ---
java.lang.IllegalArgumentException: DrawerLayout must be measured with MeasureSpec.EXACTLY.
at android.support.v4.widget.DrawerLayout.onMeasure(DrawerLayout.java:903)
at android.view.View.measure(View.java:17387)
md5b60ffeb829f638581ab2bb9b1a7f4f3f.PlatformRenderer.n_onLayout(Native Method)
at md5b60ffeb829f638581ab2bb9b1a7f4f3f.PlatformRenderer.onLayout(PlatformRenderer.java:54)
at android.view.View.layout(View.java:15655)
at android.view.ViewGroup.layout(ViewGroup.java:4856)
at android.widget.RelativeLayout.onLayout(RelativeLayout.java:1055)
at android.view.View.layout(View.java:15655)
at android.view.ViewGroup.layout(ViewGroup.java:4856)
at android.widget.FrameLayout.layoutChildren(FrameLayout.java:453)
at android.widget.FrameLayout.onLayout(FrameLayout.java:388)
at android.view.View.layout(View.java:15655)
at android.view.ViewGroup.layout(ViewGroup.java:4856)
at android.widget.FrameLayout.layoutChildren(FrameLayout.java:453)
at android.widget.FrameLayout.onLayout(FrameLayout.java:388)
at android.view.View.layout(View.java:15655)
at android.view.ViewGroup.layout(ViewGroup.java:4856)
at android.widget.FrameLayout.layoutChildren(FrameLayout.java:453)
at android.widget.FrameLayout.onLayout(FrameLayout.java:388)
at android.view.View.layout(View.java:15655)
at android.view.ViewGroup.layout(ViewGroup.java:4856)
at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1677)
at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1531)
at android.widget.LinearLayout.onLayout(LinearLayout.java:1440)
at android.view.View.layout(View.java:15655)
at android.view.ViewGroup.layout(ViewGroup.java:4856)
at android.widget.FrameLayout.layoutChildren(FrameLayout.java:453)
at android.widget.FrameLayout.onLayout(FrameLayout.java:388)
at android.view.View.layout(View.java:15655)
at android.view.ViewGroup.layout(ViewGroup.java:4856)
at android.view.ViewRootImpl.performLayout(ViewRootImpl.java:2284)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:2004)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1236)
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:6471)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:803)
at android.view.Choreographer.doCallbacks(Choreographer.java:603)
at android.view.Choreographer.doFrame(Choreographer.java:573)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:789)
at android.os.Handler.handleCallback(Handler.java:733)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:157)
at android.app.ActivityThread.main(ActivityThread.java:5356)
java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)


Confirmed on a Samsung S4 running Android 4.4

I read about similar issues which were reported on former versions:

https://forums.xamarin.com/discussion/22622/error-on-android-when-setpage-new-mymasterdetailpage-drawerlayout-must-be-measured-with

https://bugzilla.xamarin.com/show_bug.cgi?id=22269
Comment 1 Jason Smith [MSFT] 2016-03-10 19:21:44 UTC
Whats interseting here is that we ARE measuring it with EXACTLY. I am not quite sure how to properly reproduce this issue yet. Any ideas?
Comment 2 Tobias Schulz 2016-07-06 04:47:24 UTC
Hi,

It happens quite often for us (~ 15% of our users per week).

That's the stack trace:

System.Exception: CurrentDomainOnUnhandledException ---> Java.Lang.RuntimeException: DrawerLayout must be measured with MeasureSpec.EXACTLY.
  at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () <0xd878d4e8 + 0x00024> in <filename unknown>:0 
  at Java.Interop.JniEnvironment+InstanceMethods.CallNonvirtualVoidMethod (JniObjectReference instance, JniObjectReference type, Java.Interop.JniMethodInfo method, Java.Interop.JniArgumentValue* args) <0xee71eb78 + 0x000d3> in <filename unknown>:0 
  at Java.Interop.JniPeerMembers+JniInstanceMethods.InvokeNonvirtualVoidMethod (System.String encodedMember, IJavaPeerable self, Java.Interop.JniArgumentValue* parameters) <0xdd738d98 + 0x0009f> in <filename unknown>:0 
  at Android.Views.View.Measure (Int32 widthMeasureSpec, Int32 heightMeasureSpec) <0xd864ebf0 + 0x00177> in <filename unknown>:0 
  at Xamarin.Forms.Platform.Android.VisualElementTracker.UpdateLayout () <0xd864dce8 + 0x001e7> in <filename unknown>:0 
  at Xamarin.Forms.Platform.Android.AppCompat.MasterDetailPageRenderer.Xamarin.Forms.Platform.Android.IVisualElementRenderer.UpdateLayout () <0xd604bf28 + 0x0002b> in <filename unknown>:0 
  at Xamarin.Forms.Platform.Android.AppCompat.Platform.Xamarin.Forms.Platform.Android.IPlatformLayout.OnLayout (Boolean changed, Int32 l, Int32 t, Int32 r, Int32 b) <0xd83074a0 + 0x00087> in <filename unknown>:0 
  at Xamarin.Forms.Platform.Android.PlatformRenderer.OnLayout (Boolean changed, Int32 l, Int32 t, Int32 r, Int32 b) <0xd83073e8 + 0x000a3> in <filename unknown>:0 
  at Android.Views.ViewGroup.n_OnLayout_ZIIII (IntPtr jnienv, IntPtr native__this, Boolean changed, Int32 l, Int32 t, Int32 r, Int32 b) <0xd848b1f0 + 0x00087> in <filename unknown>:0 
  at (wrapper dynamic-method) System.Object:3fc899a5-b34f-4567-b7cc-e193882eeaeb (intptr,intptr,bool,int,int,int,int)
  --- End of managed exception stack trace ---
java.lang.IllegalArgumentException: DrawerLayout must be measured with MeasureSpec.EXACTLY.
	at android.support.v4.widget.DrawerLayout.onMeasure(DrawerLayout.java:1036)
	at android.view.View.measure(View.java:20166)
	at md5b60ffeb829f638581ab2bb9b1a7f4f3f.PlatformRenderer.n_onLayout(Native Method)
	at md5b60ffeb829f638581ab2bb9b1a7f4f3f.PlatformRenderer.onLayout(PlatformRenderer.java:55)
	at android.view.View.layout(View.java:17945)
	at android.view.ViewGroup.layout(ViewGroup.java:5812)
	at android.widget.RelativeLayout.onLayout(RelativeLayout.java:1080)
	at android.view.View.layout(View.java:17945)
	at android.view.ViewGroup.layout(ViewGroup.java:5812)
	at android.widget.FrameLayout.layoutChildren(FrameLayout.java:344)
	at android.widget.FrameLayout.onLayout(FrameLayout.java:281)
	at android.view.View.layout(View.java:17945)
	at android.view.ViewGroup.layout(ViewGroup.java:5812)
	at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1742)
	at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1585)
	at android.widget.LinearLayout.onLayout(LinearLayout.java:1494)
	at android.view.View.layout(View.java:17945)
	at android.view.ViewGroup.layout(ViewGroup.java:5812)
	at android.widget.FrameLayout.layoutChildren(FrameLayout.java:344)
	at android.widget.FrameLayout.onLayout(FrameLayout.java:281)
	at android.view.View.layout(View.java:17945)
	at android.view.ViewGroup.layout(ViewGroup.java:5812)
	at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1742)
	at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1585)
	at android.widget.LinearLayout.onLayout(LinearLayout.java:1494)
	at android.view.View.layout(View.java:17945)
	at android.view.ViewGroup.layout(ViewGroup.java:5812)
	at android.widget.FrameLayout.layoutChildren(FrameLayout.java:344)
	at android.widget.FrameLayout.onLayout(FrameLayout.java:281)
	at com.android.internal.policy.PhoneWindow$DecorView.onLayout(PhoneWindow.java:3178)
	at android.view.View.layout(View.java:17945)
	at android.view.ViewGroup.layout(ViewGroup.java:5812)
	at android.view.ViewRootImpl.performLayout(ViewRootImpl.java:2716)
	at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:2417)
	at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1487)
	at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:7450)
	at android.view.Choreographer$CallbackRecord.run(Choreographer.java:920)
	at android.view.Choreographer.doCallbacks(Choreographer.java:695)
	at android.view.Choreographer.doFrame(Choreographer.java:631)
	at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:906)
	at android.os.Handler.handleCallback(Handler.java:739)
	at android.os.Handler.dispatchMessage(Handler.java:95)
	at android.os.Looper.loop(Looper.java:158)
	at android.app.ActivityThread.main(ActivityThread.java:7229)
	at java.lang.reflect.Method.invoke(Native Method)
	at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)

  --- End of inner exception stack trace ---
Comment 3 Tobias Schulz 2016-07-06 04:57:49 UTC
They are having the same problem and they fixed it that way! https://github.com/mikepenz/MaterialDrawer/issues/1167
Comment 4 Tobias Schulz 2016-07-06 05:05:11 UTC
https://github.com/xamarin/Xamarin.Forms/blob/master/Xamarin.Forms.Platform.Android/MeasureSpecFactory.cs

You're saying:

		// Literally does the same thing as the android code, 1000x faster because no bridge cross
		// benchmarked by calling 1,000,000 times in a loop on actual device
		public static int MakeMeasureSpec(int size, MeasureSpecMode mode)
		{
			return size + (int)mode;
		}

That's actually not true:

        public static int makeMeasureSpec(int size, int mode) {
            if (sUseBrokenMakeMeasureSpec) {
                return size + mode;
            } else {
                return (size & ~MODE_MASK) | (mode & MODE_MASK);
            }
        }

With MODE_MASK = 0x3 << 30.

sUseBrokenMakeMeasureSpec is only true for API levels 17 and lower! Maybe that's exactly the problem
Comment 5 Tobias Schulz 2016-07-12 08:41:54 UTC
We NEED this fixed! It happens all the time! This is an urgant bug in case you diidn't realize. There is no way we can work around it!
Comment 6 Chris King 2017-06-19 17:22:21 UTC
Assigned to you as you were last to request additional info.
Comment 7 Samantha Houts [MSFT] 2017-06-19 22:39:02 UTC
Unfortunately, we’re unable to reproduce this report. If this issue is still occurring for you, please reopen this issue and attach a reproduction to the bug by starting with a clean Xamarin.Forms project adding just the code necessary to demonstrate the issue. 
 
Here are some reproduction best practices: https://gist.github.com/jassmith/92405c300e54a01dcc6d