Xamarin.Android TextView doesn’t raise change events when “Link SDK Assemblies” is selected

Issue

I’m working on a project in Xamarin with MvvmCross, trying to use the linker to get the app size down for release on Android and iOS (no Forms.)

On Android, when I selected “Link SDK Assemblies Only”, the project builds and runs with no crashes or error messages. But none of the EditText controls responds correctly when their text changes, their data bindings don’t get updated, and their Changed event handlers don’t get called.

When I select “Don’t Link”, everything works fine. Bindings are updated and event handlers are called.

I have looked at the Xamarin Linker documentation, and I’m aware of how to ensure various assemblies, types and methods are preserved. My problem is I simply don’t know what needs to be preserved, nor do I have any idea how to find out. I’ve tried tools like bitdiffer with no success.

Can anyone help me figure out what I need to preserve if anything?

Solution

Add a LinkerPleaseInclude.cs file to your Android project containing the following code:

public class LinkerPleaseInclude
{
    public void Include(TextView text)
    {
        text.AfterTextChanged + (sender, args) > text.Text  "" + text.Text;
        text.Hint  "" + text.Hint;
    }
}

EditText is inheriting from TextView so this will take care of your problem by making the linker think you reference the TextView.AfterTextChanged event. You can find a reference Android LinkerPleaseInclude.cs file here.

Answered By – Trevor Balcom

Leave a Comment