Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Command not triggered in release build

I've got a button on my MainPage that navigates to the next view. This works great in debug build on the simulated android device (Android 8.1 accelerated x86) on my windows PC (Visual Studio 2017).

The button is bound to my viewmodel from my view like that:

<Button Text="Report error" Command="{Binding NewErrorCommand}" />

The viewmodel code:

public Command NewErrorCommand
{
    get
    {
        return _newErrorCommand ?? (_newErrorCommand = new Command(ExecuteNewErrorCommand, CanNewErrorCommand));
    }
}

private bool CanNewErrorCommand(object arg)
{
    return true;
}

private async void ExecuteNewErrorCommand(object obj)
{
    try
    {
        // I'll get here in simulation/debug build but not in release build on device
        await Application.Current.MainPage.DisplayAlert("Go", "Go", "Ok");

        await _navigation.PushAsync(new TestView(), false);
    }
    catch (Exception exc)
    {
        await Application.Current.MainPage.DisplayAlert("Error", exc.Message, "Cancel");
    }        
}

My whole App is running just fine with the simulator. If I hit the button on my real physical device, I see the visual feedback (button changes color) but nothing happens at all.

What I tried so far:

  • apllied some printf debugging with DisplayAlert (not hit, see source code)
  • connected a bluetooth mouse to my android device (android 6.0) in case there are differences between mouse click and finger tap (still no working button)

Can you help a Xamarin.Forms beginner?


Update

I connected my android phone via USB to debug. The button works in debug mode (is hitting breakpoints, opening new page) but still not functional in release build.

Linker settings as per request:

enter image description here enter image description here

like image 426
nabulke Avatar asked Mar 06 '26 13:03

nabulke


1 Answers

The release version will work if you set the linking options to "SDK assemblies only", in the Build section of the Android project properties.

When the linker is enabled and set to "SDK and User assemblies", a lot of code (which is pressumed not to be used) is removed. In your case, the NewErrorCommand property is being stripped out because the tool assumes you are not using it.

It works if you set it to "SDK assemblies only" because under that configuration the linker won't touch any of your own assemblies.

like image 98
nmilcoff Avatar answered Mar 08 '26 21:03

nmilcoff