-
-
Notifications
You must be signed in to change notification settings - Fork 39
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
XCalendar.Maui 4.4.2 works when debugging, crashes at startup when installed on android phone #136
Comments
May be related to #67.
|
Greetings, to make this debugging easier, i have uploaded a test project to a zip file on wetransfer. As to reply to your questions
NOTE: This information might be important, in order to sign the apk, i use the terminal with the following guide:
In MainProject programming class (example open file explorer go inside project folder and find NewMauiApp1.csproj), add before last line Please dont hesitate to contact me for further details as i am very new to .net MAUI and this is actually my very first .net MAUI project that im trying to build. Best Regards! |
Sorry for the confusion with the point numbering there.... I can "publish" an apk without using any key or any commands from the terminal but then it wont be compatible with my phone as the apk is not published "properly". What i wanted to achieve was actually very simple, i want to make an .apk file that i can manually copy to my phone internal storage and then the user installs said apk from its mobile phone internal memory (Not Google Play Store). All tutorials i've found online shows me that i must sign the android apk with the keytool in order for me to actually be able to generate a proper apk that can install and run in any phone. Is there perhaps something wrong with my process or maybe im missing something? |
I don't know the difference between ARM and the architecure of your emulator and its implications. What do you mean it's not compatible with your phone? At what point do you get a warning or error when you don't publish the app using your method? Have you tried the below method for generating a signed apk? I think it's an alternative to using the terminal.
What result did you get from this:
As far as I'm aware and in my experience you don't need to sign an apk to have it run on devices. I don't know why it doesn't let you install the app on your device. There are some security/developer settings such as "Install from unknown sources" which could prevent the user from installing your app though. I'm out of ideas as to what it could be. In regards to:
I'm out of ideas and can only suggest to try with other packages or with other sample apps on GitHub to see if your apk-signing process works with them. If they do, then its an issue with XCalendar and I don't know why it would cause crashing after its been removed from the project. Maybe you could try to find someone else with a similar issue with their MAUI app, or raise an issue in the MAUI repo to get help from people with more knowledge of the Android OS and MAUI framework. I would suggest Syncfusion's Calendar as an alternative while this issue is present. |
Hi there! Mr Marvin, When using the newest release 4.5.1 (PS im very happy to see you still working on this wonderful project), using the following code on view and model <?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="App1.MainPage"
xmlns:xc="clr-namespace:XCalendar.Maui.Views;assembly=XCalendar.Maui"
xmlns:viewmodel="clr-namespace:App1.Models"
xmlns:xcInterfaces="clr-namespace:XCalendar.Core.Interfaces;assembly=XCalendar.Core"
x:DataType="viewmodel:MainPageModel">
<ScrollView>
<VerticalStackLayout
Spacing="25"
Padding="30,0"
VerticalOptions="Center">
<Image
Source="dotnet_bot.png"
SemanticProperties.Description="Cute dot net bot waving hi to you!"
HeightRequest="200"
HorizontalOptions="Center" />
<Label
Text="Hello, World!"
SemanticProperties.HeadingLevel="Level1"
FontSize="32"
HorizontalOptions="Center" />
<Label
Text="Welcome to .NET Multi-platform App UI"
SemanticProperties.HeadingLevel="Level2"
SemanticProperties.Description="Welcome to dot net Multi platform App U I"
FontSize="18"
HorizontalOptions="Center" />
<Button
x:Name="CounterBtn"
Text="Click me"
SemanticProperties.Hint="Counts the number of times you click"
Clicked="OnCounterClicked"
HorizontalOptions="Center" />
<xc:CalendarView
Background="LightGray"
x:Name="MainCalendarView"
BackwardsArrowCommand="{Binding NavigateCalendarCommand}"
Days="{Binding Calendar.Days}"
DaysOfWeek="{Binding Calendar.DayNamesOrder}"
ForwardsArrowCommand="{Binding NavigateCalendarCommand}"
NavigatedDate="{Binding Calendar.NavigatedDate}"
Style="{StaticResource DefaultCalendarViewStyle}">
<xc:CalendarView.ForwardsArrowCommandParameter>
<x:Int32>1</x:Int32>
</xc:CalendarView.ForwardsArrowCommandParameter>
<xc:CalendarView.BackwardsArrowCommandParameter>
<x:Int32>-1</x:Int32>
</xc:CalendarView.BackwardsArrowCommandParameter>
<xc:CalendarView.NavigationViewTemplate>
<ControlTemplate>
<xc:NavigationView
BackwardsArrowCommand="{Binding BackwardsArrowCommand, Source={RelativeSource TemplatedParent}}"
BackwardsArrowCommandParameter="{Binding BackwardsArrowCommandParameter, Source={RelativeSource TemplatedParent}}"
ForwardsArrowCommand="{Binding ForwardsArrowCommand, Source={RelativeSource TemplatedParent}}"
ForwardsArrowCommandParameter="{Binding ForwardsArrowCommandParameter, Source={RelativeSource TemplatedParent}}"
Style="{StaticResource DefaultNavigationViewStyle}"
Text="{Binding Text, Source={RelativeSource TemplatedParent}}"/>
</ControlTemplate>
</xc:CalendarView.NavigationViewTemplate>
<!-- Not Required, used only for styling. -->
<xc:CalendarView.DayTemplate>
<DataTemplate x:DataType="{x:Type xcInterfaces:ICalendarDay}">
<Border Margin="2.5" BackgroundColor="Transparent">
<Border.StrokeShape>
<RoundRectangle CornerRadius="100"/>
</Border.StrokeShape>
<xc:DayView
DateTime="{Binding DateTime}"
InvalidStyle="{StaticResource DefaultDayViewInvalidStyle}"
IsCurrentMonth="{Binding IsCurrentMonth}"
IsInvalid="{Binding IsInvalid}"
IsSelected="{Binding IsSelected}"
IsToday="{Binding IsToday}"
OtherMonthStyle="{StaticResource DefaultDayViewOtherMonthStyle}">
<xc:DayView.CurrentMonthStyle>
<Style BasedOn="{StaticResource DefaultDayViewCurrentMonthStyle}" TargetType="{x:Type xc:DayView}">
<Setter Property="Command" Value="{Binding BindingContext.ChangeDateSelectionCommand, Source={x:Reference This}}"/>
<Setter Property="CommandParameter" Value="{Binding DateTime}"/>
</Style>
</xc:DayView.CurrentMonthStyle>
<xc:DayView.TodayStyle>
<Style BasedOn="{StaticResource DefaultDayViewTodayStyle}" TargetType="{x:Type xc:DayView}">
<Setter Property="Command" Value="{Binding BindingContext.ChangeDateSelectionCommand, Source={x:Reference This}}"/>
<Setter Property="CommandParameter" Value="{Binding DateTime}"/>
</Style>
</xc:DayView.TodayStyle>
<xc:DayView.SelectedStyle>
<Style BasedOn="{StaticResource DefaultDayViewSelectedStyle}" TargetType="{x:Type xc:DayView}">
<Setter Property="Command" Value="{Binding BindingContext.ChangeDateSelectionCommand, Source={x:Reference This}}"/>
<Setter Property="CommandParameter" Value="{Binding DateTime}"/>
</Style>
</xc:DayView.SelectedStyle>
</xc:DayView>
</Border>
</DataTemplate>
</xc:CalendarView.DayTemplate>
</xc:CalendarView>
</VerticalStackLayout>
</ScrollView>
</ContentPage>
Code Behind MainPage.xaml.cs using App1.Models;
using XCalendar.Core.Models;
namespace App1;
public partial class MainPage : ContentPage
{
int count = 0;
public MainPageModel modelToUse = new MainPageModel();
public MainPage()
{
BindingContext = modelToUse;
InitializeComponent();
}
public Calendar<CalendarDay> MyCalendar { get; set; } = new Calendar<CalendarDay>();
private void OnCounterClicked(object sender, EventArgs e)
{
count++;
if (count == 1)
CounterBtn.Text = $"Clicked {count} time";
else
CounterBtn.Text = $"Clicked {count} times";
SemanticScreenReader.Announce(CounterBtn.Text);
}
} And using this code on the ViewModel using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Input;
using XCalendar.Core.Enums;
using XCalendar.Core.Extensions;
using XCalendar.Core.Models;
namespace App1.Models
{
public class MainPageModel : INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged;
internal MainPage masterWindow = null;
#region Properties
public List<string> CommonFunctionalities { get; } = new List<string>()
{
"None",
"Single",
"Multiple",
"Range"
};
public Calendar<CalendarDay> Calendar { get; set; } = new Calendar<CalendarDay>()
{
SelectionType = SelectionType.Single,
SelectionAction = SelectionAction.Replace
};
#endregion
#region Commands
public ICommand ShowSelectionTypeDialogCommand { get; set; }
public ICommand ShowSelectionActionDialogCommand { get; set; }
public ICommand ShowCommonFunctionalityDialogCommand { get; set; }
public ICommand NavigateCalendarCommand { get; set; }
public ICommand ChangeDateSelectionCommand { get; set; }
#endregion
#region Constructors
public MainPageModel()
{
ShowSelectionTypeDialogCommand = new Command(ShowSelectionTypeDialog);
ShowSelectionActionDialogCommand = new Command(ShowSelectionActionDialog);
ShowCommonFunctionalityDialogCommand = new Command(ShowCommonFunctionalityDialog);
NavigateCalendarCommand = new Command<int>(NavigateCalendar);
ChangeDateSelectionCommand = new Command<DateTime>(ChangeDateSelection);
Calendar.SelectionType = SelectionType.Single;
Calendar.SelectionAction = SelectionAction.Replace;
}
#endregion
#region Methods
public async void ShowSelectionTypeDialog()
{
//Calendar.SelectionType = await PopupHelper.ShowSelectItemDialogAsync(Calendar.SelectionType, PopupHelper.AllSelectionTypes);
}
public async void ShowSelectionActionDialog()
{
//Calendar.SelectionAction = await PopupHelper.ShowSelectItemDialogAsync(Calendar.SelectionAction, PopupHelper.AllSelectionActions);
}
public async void ShowCommonFunctionalityDialog()
{
/*string commonFunctionality = await PopupHelper.ShowSelectItemDialogAsync(CommonFunctionalities[1], CommonFunctionalities);
switch (commonFunctionality)
{
case "None":
Calendar.SelectionType = SelectionType.None;
break;
case "Single":
Calendar.SelectionType = SelectionType.Single;
Calendar.SelectionAction = SelectionAction.Replace;
break;
case "Multiple":
Calendar.SelectionType = SelectionType.Single;
Calendar.SelectionAction = SelectionAction.Modify;
break;
case "Range":
Calendar.SelectionType = SelectionType.Range;
Calendar.SelectionAction = SelectionAction.Replace;
break;
}*/
}
public void NavigateCalendar(int amount)
{
if (Calendar.NavigatedDate.TryAddMonths(amount, out DateTime targetDate))
{
Calendar.Navigate(targetDate - Calendar.NavigatedDate);
}
else
{
Calendar.Navigate(amount > 0 ? TimeSpan.MaxValue : TimeSpan.MinValue);
}
}
public void ChangeDateSelection(DateTime dateTime)
{
Calendar?.ChangeDateSelection(dateTime);
}
#endregion
}
} Using the above code, the project builds fine and works fine in debug mode in android emulator, but still i am unable to run on my android device after installing, as usual the app crashes at the splashscreen. However, if i change both codes of the view and model to this: <?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="App1.MainPage"
xmlns:xc="clr-namespace:XCalendar.Maui.Views;assembly=XCalendar.Maui"
xmlns:viewmodel="clr-namespace:App1.Models"
x:DataType="viewmodel:MainPageModel">
<ScrollView>
<VerticalStackLayout
Spacing="25"
Padding="30,0"
VerticalOptions="Center">
<Image
Source="dotnet_bot.png"
SemanticProperties.Description="Cute dot net bot waving hi to you!"
HeightRequest="200"
HorizontalOptions="Center" />
<Label
Text="Hello, World!"
SemanticProperties.HeadingLevel="Level1"
FontSize="32"
HorizontalOptions="Center" />
<Label
Text="Welcome to .NET Multi-platform App UI"
SemanticProperties.HeadingLevel="Level2"
SemanticProperties.Description="Welcome to dot net Multi platform App U I"
FontSize="18"
HorizontalOptions="Center" />
<Button
x:Name="CounterBtn"
Text="Click me"
SemanticProperties.Hint="Counts the number of times you click"
Clicked="OnCounterClicked"
HorizontalOptions="Center" />
<xc:CalendarView
BackgroundColor="LightGray"
BackwardsArrowCommand="{Binding NavigateCalendarCommand}"
Days="{Binding MyCalendar.Days}"
DaysOfWeek="{Binding MyCalendar.DayNamesOrder}"
ForwardsArrowCommand="{Binding NavigateCalendarCommand}"
NavigatedDate="{Binding MyCalendar.NavigatedDate}">
<xc:CalendarView.ForwardsArrowCommandParameter>
<x:Int32>1</x:Int32>
</xc:CalendarView.ForwardsArrowCommandParameter>
<xc:CalendarView.BackwardsArrowCommandParameter>
<x:Int32>-1</x:Int32>
</xc:CalendarView.BackwardsArrowCommandParameter>
</xc:CalendarView>
</VerticalStackLayout>
</ScrollView>
</ContentPage> Code Behind MainPage.xaml.cs (Same code, no point in duplicating) And using this code on the ViewModel using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Input;
using XCalendar.Core.Enums;
using XCalendar.Core.Models;
namespace App1.Models
{
public class MainPageModel : INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged;
internal MainPage masterWindow = null;
public void OnPropertyChanged([CallerMemberName] string propertyName = null) => this.PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
#region Properties
public Calendar<CalendarDay> MyCalendar { get; set; } = new Calendar<CalendarDay>()
{
SelectionType = SelectionType.Single,
StartOfWeek = DayOfWeek.Monday,
SelectionAction = SelectionAction.Replace,
//DayNamesOrder = new XCalendar.Core.Collections.ObservableRangeCollection<DayOfWeek>() { DayOfWeek.Monday, DayOfWeek.Tuesday, DayOfWeek.Wednesday, DayOfWeek.Thursday, DayOfWeek.Friday, DayOfWeek.Saturday, DayOfWeek.Sunday },
};
#endregion
#region Commands
public ICommand ShowSelectionTypeDialogCommand { get; set; }
public ICommand ShowSelectionActionDialogCommand { get; set; }
public ICommand ShowCommonFunctionalityDialogCommand { get; set; }
public ICommand NavigateCalendarCommand { get; set; }
public ICommand ChangeDateSelectionCommand { get; set; }
#endregion
#region Constructors
#endregion
#region Methods
public async void ShowSelectionTypeDialog()
{
MyCalendar.SelectionType = SelectionType.Single;
}
public async void ShowSelectionActionDialog()
{
MyCalendar.SelectionAction = SelectionAction.Add;
}
public async void ShowCommonFunctionalityDialog()
{
MyCalendar.SelectionType = SelectionType.Single;
MyCalendar.SelectionAction = SelectionAction.Modify;
}
public void ChangeDateSelection(DateTime dateTime)
{
MyCalendar?.ChangeDateSelection(dateTime);
}
#endregion
public MainPageModel()
{
ShowSelectionTypeDialogCommand = new Command(ShowSelectionTypeDialog);
ShowSelectionActionDialogCommand = new Command(ShowSelectionActionDialog);
ShowCommonFunctionalityDialogCommand = new Command(ShowCommonFunctionalityDialog);
ChangeDateSelectionCommand = new Command<DateTime>(ChangeDateSelection);
}
}
} It builds fine, works fine in emulator and even the published apk installs fine on the phone and displays without crashing! PS: Meanwhile, if there is anything else i can do to help you out, please feel free to ask, i will do whatever i can with my very limited experience in .net maui. |
In addition to the last post i made a few mins ago... Im not sure if this is of any interest as im not even sure if it's actually accurate information, but, perhaps .net maui no longer uses relaycommands and probably replaced it with something newer? Again i have really no experience with .net maui and this is my first ever project with it, so take this specific info with a grain of salt. |
Will look at this again, great debugging |
Running first set of codeIssue 1SolutionRemove <xc:CalendarView
Background="LightGray"
x:Name="MainCalendarView"
BackwardsArrowCommand="{Binding NavigateCalendarCommand}"
Days="{Binding Calendar.Days}"
DaysOfWeek="{Binding Calendar.DayNamesOrder}"
ForwardsArrowCommand="{Binding NavigateCalendarCommand}"
NavigatedDate="{Binding Calendar.NavigatedDate}"
Style="{StaticResource DefaultCalendarViewStyle}"> Issue 2SolutionRemove <xc:CalendarView.NavigationViewTemplate>
<ControlTemplate>
<xc:NavigationView
BackwardsArrowCommand="{Binding BackwardsArrowCommand, Source={RelativeSource TemplatedParent}}"
BackwardsArrowCommandParameter="{Binding BackwardsArrowCommandParameter, Source={RelativeSource TemplatedParent}}"
ForwardsArrowCommand="{Binding ForwardsArrowCommand, Source={RelativeSource TemplatedParent}}"
ForwardsArrowCommandParameter="{Binding ForwardsArrowCommandParameter, Source={RelativeSource TemplatedParent}}"
Style="{StaticResource DefaultNavigationViewStyle}"
Text="{Binding Text, Source={RelativeSource TemplatedParent}}"/>
</ControlTemplate>
</xc:CalendarView.NavigationViewTemplate> Issue 3The StaticResources "DefaultDayViewCurrentMonthStyle", "DefaultDayViewTodayStyle", and "DefaultDayViewSelectedStyle" are used in the following code but are not defined: <xc:DayView.CurrentMonthStyle>
<Style BasedOn="{StaticResource DefaultDayViewCurrentMonthStyle}" TargetType="{x:Type xc:DayView}">
<Setter Property="Command" Value="{Binding BindingContext.ChangeDateSelectionCommand, Source={x:Reference This}}"/>
<Setter Property="CommandParameter" Value="{Binding DateTime}"/>
</Style>
</xc:DayView.CurrentMonthStyle>
<xc:DayView.TodayStyle>
<Style BasedOn="{StaticResource DefaultDayViewTodayStyle}" TargetType="{x:Type xc:DayView}">
<Setter Property="Command" Value="{Binding BindingContext.ChangeDateSelectionCommand, Source={x:Reference This}}"/>
<Setter Property="CommandParameter" Value="{Binding DateTime}"/>
</Style>
</xc:DayView.TodayStyle>
<xc:DayView.SelectedStyle>
<Style BasedOn="{StaticResource DefaultDayViewSelectedStyle}" TargetType="{x:Type xc:DayView}">
<Setter Property="Command" Value="{Binding BindingContext.ChangeDateSelectionCommand, Source={x:Reference This}}"/>
<Setter Property="CommandParameter" Value="{Binding DateTime}"/>
</Style>
</xc:DayView.SelectedStyle> SolutionEither don't set "BasedOn", or if you want to use the default look of the DayView, replace them with the values in the XCalendar.Maui.DefaultStyles class. For example: <xc:DayView.CurrentMonthStyle>
<Style BasedOn="{x:Static xcStyles:DefaultStyles.DefaultDayViewCurrentMonthStyle}" TargetType="{x:Type xc:DayView}">
<Setter Property="Command" Value="{Binding BindingContext.ChangeDateSelectionCommand, Source={x:Reference This}}"/>
<Setter Property="CommandParameter" Value="{Binding DateTime}"/>
</Style>
</xc:DayView.CurrentMonthStyle> Where Looking at second set of code:Issues from your first set of code also apply and will not be ammended in the solutions provided. Issue 1
You have defined the <xc:DayView.CurrentMonthStyle>
<Style BasedOn="{StaticResource DefaultDayViewCurrentMonthStyle}" TargetType="{x:Type xc:DayView}">
<Setter Property="Command" Value="{Binding BindingContext.ChangeDateSelectionCommand, Source={x:Reference This}}"/>
<Setter Property="CommandParameter" Value="{Binding DateTime}"/>
</Style>
</xc:DayView.CurrentMonthStyle>
<xc:DayView.TodayStyle>
<Style BasedOn="{StaticResource DefaultDayViewTodayStyle}" TargetType="{x:Type xc:DayView}">
<Setter Property="Command" Value="{Binding BindingContext.ChangeDateSelectionCommand, Source={x:Reference This}}"/>
<Setter Property="CommandParameter" Value="{Binding DateTime}"/>
</Style>
</xc:DayView.TodayStyle>
<xc:DayView.SelectedStyle>
<Style BasedOn="{StaticResource DefaultDayViewSelectedStyle}" TargetType="{x:Type xc:DayView}">
<Setter Property="Command" Value="{Binding BindingContext.ChangeDateSelectionCommand, Source={x:Reference This}}"/>
<Setter Property="CommandParameter" Value="{Binding DateTime}"/>
</Style>
</xc:DayView.SelectedStyle> SolutionThe following code sets the command to use when a day is tapped and is in the <xc:DayView.CurrentMonthStyle>
<Style TargetType="{x:Type xc:DayView}">
<Setter Property="Command" Value="{Binding BindingContext.ChangeDateSelectionCommand, Source={x:Reference This}}"/>
<Setter Property="CommandParameter" Value="{Binding DateTime}"/>
</Style>
</xc:DayView.CurrentMonthStyle> It really is valuable testing with a debugger first to see the errors that cause your app to crash. After that you can delete the app and test without the debugger like you do currently. With XAML there can be many runtime errors so I think its essential that you find out why you're not able to run apps in debug mode on your phone, especially if you're want to use more complex XAML or nuget packages. Are you able to run in debug mode in your emulator instead? I don't know why it worked fine in your emulator as the app still should have crashed/thrown an exception because of the afformentioned issues. Thanks for doing tests and posting what did and didn't work. Made it much easier to spot the difference. |
Hello, sorry for the delay i have been really busy these days and couldnt test your answear untill today. Thank you very much for your reply, great news!
Is there a chance you could help me out make this work on 4.5.1, example: to be able to change months and click on specific days? Once more thank you for your time! |
Stuff from the sample app is almost copy paste but at least a little knowledge is required to recognise what resources that were used need to be removed or replicated in your app like Styles or x:Name or nuget packages. Things can also be done in many ways, and the way I have done it may not always suite your needs. Anyway, if you want to move the month and be able to select days, I recommend looking at the "Date Selection" example in the sample app. The |
Greetings!
After successfully implementing this amazing control and trying to test it on my phone (Realme 8 Pro with Android 13)
The program crashes at startup after installation.
The program works just fine in the emulator when debugging, but when changing to release and trying to manually install the app into my android phone, the program installs fine, however when starting the program up, the .net maui splashscreen appears and then app instantly crashes without any error.
I have tried using a clean project from scratch, same problem persists.
Is there any tip or anything i could do to make it run on a android phone?
Devices and OS Versions:
Realme 8 Pro:
Android 13:
Windows Version: 11 Pro, 22h2 (custom built pc)
Visual Studio 2022 17.6.1 .NET 7
Thanks in advance for all your help!
The text was updated successfully, but these errors were encountered: