Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

On Android 4.2.2 an exception Java.Lang.NoSuchMethodError: no method with name='getDrawable' is thrown. #2

Closed
agat366 opened this issue Aug 31, 2018 · 4 comments

Comments

@agat366
Copy link

agat366 commented Aug 31, 2018

The components are pretty nice, and they work fine for me on newer Android.
But when I also test it on 4.2.2, I receive the following exception:

Java.Lang.NoSuchMethodError: no method with name = 'getDrawable' signature='()Landroid/graphics/drawable/Drawable;' in class Landroid/graphics/drawable/InsetDrawable;
  at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() [0x0000c] in <f32579baafc1404fa37ba3ec1abdc0bd>:0 
  at Java.Interop.JniEnvironment+InstanceMethods.GetMethodID (Java.Interop.JniObjectReference type, System.String name, System.String signature)[0x0005b] in <09bf3e262b934ffab2ba01f9fc7fd54d>:0 
 at Java.Interop.JniType.GetInstanceMethod(System.String name, System.String signature) [0x0000c] in <09bf3e262b934ffab2ba01f9fc7fd54d>:0 
  at Java.Interop.JniPeerMembers+JniInstanceMethods.GetMethodInfo (System.String encodedMember)[0x00031] in <09bf3e262b934ffab2ba01f9fc7fd54d>:0 
 at Java.Interop.JniPeerMembers+JniInstanceMethods.InvokeVirtualObjectMethod (System.String encodedMember, Java.Interop.IJavaPeerable self, Java.Interop.JniArgumentValue* parameters)[0x0001c] in <09bf3e262b934ffab2ba01f9fc7fd54d>:0 
 at Android.Graphics.Drawables.InsetDrawable.get_Drawable() [0x0000a] in <25661073a35344a89f215a4cf81af37c>:0 
  at XF.Material.Droid.Renderers.MaterialButtonRenderer.CreateOutlinedButtonDrawable() [0x000ce] in C:\Users\cadn\source\repos\XF.Material\src\XF.Material\XF.Material.Droid\Renderers\MaterialButtonRenderer.cs:132 
  at XF.Material.Droid.Renderers.MaterialButtonRenderer.UpdateDrawable() [0x0003a] in C:\Users\cadn\source\repos\XF.Material\src\XF.Material\XF.Material.Droid\Renderers\MaterialButtonRenderer.cs:263 
  at XF.Material.Droid.Renderers.MaterialButtonRenderer.OnElementChanged(Xamarin.Forms.Platform.Android.ElementChangedEventArgs`1[TElement] e) [0x00095] in C:\Users\cadn\source\repos\XF.Material\src\XF.Material\XF.Material.Droid\Renderers\MaterialButtonRenderer.cs:46 
  at Xamarin.Forms.Platform.Android.VisualElementRenderer`1[TElement].SetElement (TElement element)[0x000d5] in D:\a\1\s\Xamarin.Forms.Platform.Android\VisualElementRenderer.cs:178 
 at Xamarin.Forms.Platform.Android.VisualElementRenderer`1[TElement].Xamarin.Forms.Platform.Android.IVisualElementRenderer.SetElement (Xamarin.Forms.VisualElement element)[0x00027] in D:\a\1\s\Xamarin.Forms.Platform.Android\VisualElementRenderer.cs:126 

In my particular case I rather use only MaterialButton component.

The issue looks like this issue mentioned on stackoverflow:
https://stackoverflow.com/questions/30266971/why-getdrawable-doesnt-work-on-some-android-devices

My current version of XF.Material library: 1.0.4

@contrix09
Copy link

Thanks for reporting this, I will look into it.

@contrix09
Copy link

contrix09 commented Sep 1, 2018

Found the problem. InsetDrawable.Drawable is not available for Android 4.2 (Jellybean). I changed the the drawable to use StateListDrawable. Doing this will make the buttons bigger for Jellybean devices.

Originally, MaterialButtonRenderer on Android uses a template InsetDrawable to provide padding around the button. That InsetDrawable is wrapped arround the StateListDrawable, which is the drawable that provides the visible part of the button.

As per Material guidelines, Buttons have an additional touch target (padding) of 6 units on all sides. This additional values are included in the view's total height and total width.

Below you can see the changes. The device on the left side is runnning Android 4.2, the right is running Android 4.4.

image

I may able to push and release this change, along with other features, sooner or later this day.

@contrix09
Copy link

Version 1.0.5 has been released.

@agat366
Copy link
Author

agat366 commented Sep 1, 2018

I think, the visual differences for earlier Androids is not an issue these days at all, as they still have pretty cool "bonus" that the app even works (launches) on such devices. (Especially, in comparison to iOS world).

martijn00 pushed a commit that referenced this issue Oct 9, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant