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:
DisplayAlert (not hit, see source code)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:

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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With