Search code examples
c#androidxamarinmvvmcross

MvvmCross android linker kills binding


I wrote simple adnroid app using MvvmCross. There are just two activicites. First one is LoginActivity which contains two text boxes and button. It is working fine when using on debug mode. It also works after archive when Linker is set to None. The problem is when I set Linker to SdkAssembilesOnly application run but when button is clicked nothing happens. I think that binding is not working.

  <Button
      android:layout_height="wrap_content"
      android:layout_width="wrap_content"
      android:text="Login"
      local:MvxBind="Click LoginCommand" />

While surfing internet I found some people uses LinkerPleaseInclude.cs - what should I add to this class to make it works ?


Solution

  • Yes - add a LinkerPleaseInclude class with the following method in it:

    public void Include(Button button)
    {
        button.Click += (s, e)
            => button.Text = $"{button.Text}";
    }
    

    Also make sure LinkerPleaseInclude has the [Preserve(AllMembers = true)] attribute on it.