This is a migrated thread and some comments may be shown as answers.

Button related crash

1 Answer 308 Views
Button
This is a migrated thread and some comments may be shown as answers.
n/a
Top achievements
Rank 1
Iron
n/a asked on 16 Dec 2019, 02:27 PM

Hi,
recently I received crash with describe Unable to activate instance of type Telerik.XamarinForms.InputRenderer.Android.Button.ExtendedAndroidButton.
Below stack trace pasted.
Is it known issue, or ho to find out where this exception was happen?
I got this crash first time after update XF and Telerik.UI.

XF:4.3.0.947036

Telerik:2019.3.1023.1

Sory, but code formatter doesn't work for me here.

Xamarin Exception Stack: System.NotSupportedException: Unable to activate instance of type Telerik.XamarinForms.InputRenderer.Android.Button.ExtendedAndroidButton from native handle 0xbef5af20 (key_handle 0x7b876d1). at Java.Interop.TypeManager.CreateInstance (System.IntPtr handle, Android.Runtime.JniHandleOwnership transfer, System.Type targetType) [0x00182] in <20c7915d69a7451ba5dddbb52e8ee0c2>:0 at Java.Lang.Object.GetObject (System.IntPtr handle, Android.Runtime.JniHandleOwnership transfer, System.Type type) [0x000c1] in <20c7915d69a7451ba5dddbb52e8ee0c2>:0 at Java.Lang.Object._GetObject[T] (System.IntPtr handle, Android.Runtime.JniHandleOwnership transfer) [0x00017] in <20c7915d69a7451ba5dddbb52e8ee0c2>:0 at Java.Lang.Object.GetObject[T] (System.IntPtr handle, Android.Runtime.JniHandleOwnership transfer) [0x00000] in <20c7915d69a7451ba5dddbb52e8ee0c2>:0 at Android.Views.View+IOnClickListenerInvoker.n_OnClick_Landroid_view_View_ (System.IntPtr jnienv, System.IntPtr native__this, System.IntPtr native_v) [0x00009] in <20c7915d69a7451ba5dddbb52e8ee0c2>:0 at (wrapper dynamic-method) Android.Runtime.DynamicMethodNameCounter.44(intptr,intptr,intptr) --- End of inner exception stack trace --- System.MissingMethodException: No constructor found for Telerik.XamarinForms.InputRenderer.Android.Button.ExtendedAndroidButton::.ctor(System.IntPtr, Android.Runtime.JniHandleOwnership) at Java.Interop.TypeManager.CreateProxy (System.Type type, System.IntPtr handle, Android.Runtime.JniHandleOwnership transfer) [0x00055] in <20c7915d69a7451ba5dddbb52e8ee0c2>:0 at Java.Interop.TypeManager.CreateInstance (System.IntPtr handle, Android.Runtime.JniHandleOwnership transfer, System.Type targetType) [0x00116] in <20c7915d69a7451ba5dddbb52e8ee0c2>:0 --- End of inner exception stack trace --- Java.Interop.JavaLocationException: Exception of type 'Java.Interop.JavaLocationException' was thrown. at Java.Lang.Error: Exception of type 'Java.Lang.Error' was thrown. at java.lang.Error: Java callstack: at md51558244f76c53b6aeda52c8a337f2c37.ButtonRenderer_ButtonClickListener.n_onClick(Native Method) at md51558244f76c53b6aeda52c8a337f2c37.ButtonRenderer_ButtonClickListener.onClick(ButtonRenderer_ButtonClickListener.java:30) at android.view.View.performClick(View.java:6300) at android.view.View$PerformClick.run(View.java:24941) at android.os.Handler.handleCallback(Handler.java:790) at android.os.Handler.dispatchMessage(Handler.java:99) at android.os.Looper.loop(Looper.java:164) at android.app.ActivityThread.main(ActivityThread.java:6639) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:583) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:870)

1 Answer, 1 is accepted

Sort by
0
Lance | Manager Technical Support
Telerik team
answered on 16 Dec 2019, 04:44 PM

Hi Maciej,

Thank you for the stack trace. The MissingMethodException, for the Android component ExtendedAndroidButton, is apparently because it cannot find the default constructor.

I have a few thoughts as to why this might be happening:

  1. - The Linker is set to SDK and User Assemblies
  2. - There are custom button renderers that do not have a default constructor
  3. - Telerik UI for Xamarin dependencies were not updated

Let me take you through possible solutions for each consideration

Consideration #1 - Linker

The project has the linker enabled which removed critical code. Telerik UI for Xamarin does not support using the Linker. 

To fix this this, go to Android Project > Properties > Android Options change the linker to None (or SDK Assemblies Only)

Note: Even if you didn't change it, it might be set to SDK and User Assemblies in your Release build. Switch to Release and double check the setting.

Consideration #2 - Default Constructor

If you have custom renderers in the Xamarin.Android project, please go through them all and make sure they are following the modern approach to include a default constructor.

If you're not familiar with this topic, please visit the Microsoft Custom Renderer Tutorial documentation and take a look at the Android renderer. You'll see the constructor passes the context to the base

All custom renderers for Android must be set up this way.

Example

If you have IntelliSense enabled to show these types of problems, you'd see something like this:

So, let's say you have something like this:

public class MyRadButtonRenderer : Telerik.XamarinForms.InputRenderer.Android.ButtonRenderer
{
    protected override void OnElementChanged()
    {
        // my custom renderer stuff in here
    }
}

It now must have this:

public class MyRadButtonRenderer : Telerik.XamarinForms.InputRenderer.Android.ButtonRenderer
{
    public MyRadButtonRenderer(Context context) : base(context)
    {
    }

    protected override void OnElementChanged(...)
    {
        // my custom renderer stuff in here
    }
}

Consideration #3 - Upgrading Dependencies

Let me take you through both the Android and SkiaSharp dependencies, make sure you have the following.

Update all the required Android Support Libraries

Confirm these are all installed to your Android project. They must be at least version 28.0.0.1:

  • Xamarin.Android.Support.v4
  • Xamarin.Android.Support.Design
  • Xamarin.Android.Support.v7.AppCompat
  • Xamarin.Android.Support.v7.CardView
  • Xamarin.Android.Support.v7.MediaRouter
  • Xamarin.Android.Support.Vector.Drawable
  • Xamarin.Android.Support.Animated.Vector.Drawable
  • Xamarin.Android.Support.v7.RecyclerView

Update all the required SkiaSharp libraries

Confirm that the correct packages are installed to each project. They must be at least version 1.68.0:

  • SkiaSharp (install to all projects)
  • SkiaSharp.Views (install to all projects, except class library)
  • SkiaSharp.Views.Forms (install to all projects)

Clean and rebuild the solution

After updating any references or packages, you will want to perform a Clean & Rebuild Solution. This will make sure there are no cached assemblies being used when you build. Xamarin is notorious for this.

Further Investigation

If this still doesn't help, please open a Support Ticket here (you have a current Support License). This is a situation that is explicit to your setup/scenario and needs direct attention that public forum post is not appropriate for.

Attach your project to the ticket so the support team can directly investigate and assist (tip - perform a Clean Solution before zipping it up, this will drastically reduce the solution size).

Regards,
Lance | Team Lead - US DevTools Support
Progress Telerik

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Tags
Button
Asked by
n/a
Top achievements
Rank 1
Iron
Answers by
Lance | Manager Technical Support
Telerik team
Share this question
or