I cannot publish my MAUI app
Hello
My MAUI app runs fine in Debug - in the emulator or while deployed on my Phone.
In Release mode, on both my emulator and my phone, after a looooong compile and deploy, it won't even start. The only message I get in the "Error List" in Visual Studio is
MSB3073: The command ""C:\Program Files (x86)\Android\android-sdk\platform-tools\adb" -s emulator-5554 uninstall -k "com.MyCompanyEtc.ExpensesMobile"" exited with code 1.
This is a simplified code
public partial class AppShell : Shell
{
public AppShell()
{
InitializeComponent();
Routing.RegisterRoute("Login", typeof(View.Login.Login));
Routing.RegisterRoute("DocumentScan", typeof(DocumentScan));
.....
CurrentItem = Login;
}
}
[QueryProperty(nameof(Login), "Login")]
public partial class Login_VM : Base_VM
{
public readonly LoginService loginService;
private readonly IConnectivity connectivity;
[ObservableProperty]
private string password;
public Login_VM(LoginService loginService, IConnectivity connectivity)
{
try
{
this.loginService = loginService;
this.connectivity = connectivity;
username = "MyName";
password = "000";
}
catch (Exception ex)
{
ErrorHandling.HandleError(ex);
}
}
[RelayCommand]
private async Task LoginAsync()
{
if (IsBusy)
{
return;
}
try
{
if (connectivity.NetworkAccess != NetworkAccess.Internet)
{
await Shell.Current.DisplayAlert(AppRes.MsgConnectivity1, AppRes.MsgConnectivity2, "OK"); //No connectivity....etc;
return;
}
IsBusy = true;
LoginStatus loginStatus = LoginService.Login(username, password);
if (loginStatus == LoginStatus.loginAcceptedAdmin)
{
Globals.User ??= new User()
{
Name = username
};
....
await Shell.Current.GoToAsync($"//{nameof(Pending)}");
}
else if (LoginService.Login(username, password) == LoginStatus.loginAcceptedRegularUser)
{
Globals.User ??= new User()
{
Name = username
};
....
await Shell.Current.GoToAsync($"//{nameof(Pending)}");
}
else if (LoginService.Login(username, password) == LoginStatus.loginRefused)
{
await Shell.Current.DisplayAlert(AppRes.Login, AppRes.LoginWrongUsernameOrPass, "OK"); //Wrong username and/or password !
}
Globals.loginStatus = loginStatus;
}
catch (Exception ex)
{
ErrorHandling.HandleError(ex);
}
finally
{
IsBusy = false;
}
}
}
In the Tools/Android/DeviceLog I have this (snip):
at ExpensesMobile.View.Login.Login..ctor(Login_VM viewModel)
at System.Reflection.RuntimeConstructorInfo.InternalInvoke(Object , Object[] , Boolean )
at System.Reflection.RuntimeConstructorInfo.DoInvoke(Object , BindingFlags , Binder , Object[] , CultureInfo )
at System.Reflection.RuntimeConstructorInfo.Invoke(BindingFlags , Binder , Object[] , CultureInfo )
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitConstructor(ConstructorCallSite , RuntimeResolverContext )
02-15 15:24:20.473 pixel_5_-_api_33 Info 5453 MonoDroid android.runtime.JavaProxyThrowable: System.FieldAccessException: Field `Microsoft.Maui.Controls.VisualElement:ZIndexProperty' is inaccessible from method `ExpensesMobile.View.Login.Login:InitializeComponent ()'
................
02-15 15:24:20.444 pixel_5_-_api_33 Error 5453 AndroidRuntime
at ExpensesMobile.View.Login.Login..ctor(Login_VM viewModel)
Thank you Alex