maui icon indicating copy to clipboard operation
maui copied to clipboard

App runs fine in Android Emulator or Android Local Device, crashes running on side-installed APK on actual device.

Open tradegear opened this issue 2 years ago • 2 comments

Description

I have a dotnet maui app that runs fine in the Android Emulator and on the Android Local Device (2021 Moto 5G Android 11). I generated signing cert, published the *-signed.apk, uploaded it to my google cloud drive, downloaded it to my same Android 2021 Moto 5G Android 11 phone. The app runs the first couple of screens, then when I navigate to a couple screens that use a Grid layout (that seems to be the common thing), the app completely crashes/disappears/unceremoneosly quits. How do I debug this? Do I just stop using grids? Do I buy Telerik so that I have access to support?

Steps to Reproduce

Build an app that runs on connected Android emulator and Android Local Device. Build release, publish signed *-signed.apk installer, do side install on same Android phone. Does yours crash? If so, how do you debug?

Link to public reproduction project repository

x

Version with bug

6.0.486 (current)

Last version that worked well

Unknown/Other

Affected platforms

Android

Affected platform versions

Android 11

Did you find any workaround?

No workaround. Just disappointment all this weekend.

Relevant log output

Is there someplace on the android phone that would contain crash info?  If there is, is it reasonable that I would be able to make any sense of it?

tradegear avatar Oct 28 '22 22:10 tradegear

Hi. I had the same problem. I found the error using AppCenter.ms. There is a video of @jfversluis on youtube. https://www.youtube.com/watch?v=Bz1XLecJlXc Hope this helps.

FM1973 avatar Oct 29 '22 06:10 FM1973

jfversluis

who follow a stupid person like him.. that so ego ?

PirasathLuxchumykanthan avatar Oct 29 '22 09:10 PirasathLuxchumykanthan

Hi. I had the same problem. I found the error using AppCenter.ms. There is a video of @jfversluis on youtube. https://www.youtube.com/watch?v=Bz1XLecJlXc <

Thank you for this FM1973.
So this means I should debug via the "Windows" device, then just go straight to an actual Android device. Why doesn't the Android Emulator, (and more surprisingly) debugging in VS via the USB-connected local device, suffer the same crash, if there is a program bug?

tradegear avatar Oct 29 '22 20:10 tradegear

Instead of utilizing the suggested debugging tools (which I don't think an application developer should be tasked with dealing with OS-level debugging, IMHO), I chose to employ a "process of elimination" technique to see just what code was causing a full set of similar pages in my app, to blow up on Android running apart from USB debugging. Here is the first thing I found: ----this blows up-------

<?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="MTRClient.Pages.PageDirectLabors"
             xmlns:model="clr-namespace:MTRClient.Models"
             xmlns:viewmodel="clr-namespace:MTRClient.ViewModels"
             x:DataType="viewmodel:DirectLaborsViewModel"
             NavigationPage.HasBackButton="True"
             Title="{Binding ModelTitle}">
    <Shell.BackButtonBehavior>
        <BackButtonBehavior IsVisible="True" IsEnabled="True" />
    </Shell.BackButtonBehavior>
    <Grid
        ColumnDefinitions="*,*"
        ColumnSpacing="5"
        RowSpacing="0">
        <Grid.RowDefinitions>
            <RowDefinition Height="100" />
            <RowDefinition Height="*" />
        </Grid.RowDefinitions>
        <Label Style="{StaticResource MediumLabel}" Text="Active Job - Select to Clock Out"
                Grid.Row="0"
                Grid.ColumnSpan="2" />
    </Grid>
</ContentPage>

remove this: Style="{StaticResource MediumLabel}"

-----this does not blow up------

<?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="MTRClient.Pages.PageDirectLabors"
             xmlns:model="clr-namespace:MTRClient.Models"
             xmlns:viewmodel="clr-namespace:MTRClient.ViewModels"
             x:DataType="viewmodel:DirectLaborsViewModel"
             NavigationPage.HasBackButton="True"
             Title="{Binding ModelTitle}">
    <Shell.BackButtonBehavior>
        <BackButtonBehavior IsVisible="True" IsEnabled="True" />
    </Shell.BackButtonBehavior>
    <Grid
        ColumnDefinitions="*,*"
        ColumnSpacing="5"
        RowSpacing="0">
        <Grid.RowDefinitions>
            <RowDefinition Height="100" />
            <RowDefinition Height="*" />
        </Grid.RowDefinitions>
        <Label Text="Active Job - Select to Clock Out"
                Grid.Row="0"
                Grid.ColumnSpan="2" />
    </Grid>
</ContentPage>


so it looks like there is some resource configuration that needs to be done? Being new to this, and based on the youtube videos that are out there that give the impression that I wouldn't need to worry about simple things like style configurations due to .net Maui's claim of being multi-platform, I am surprised by this. Doesn't seem reasonable. (There were warnings about more low-level configs that would be necessary, however setting text size doesn't seem like a "big ask" to me.)

So if an app can't find a resource, it just quits. This doesn't seem like a reasonable behavior. It would be better if it (a) ignored the missing resource (b) gave some warning about the fact it is being ignored (c) behavior was consistent whether running the app in debugger via USB or fully installed on the Android device.

tradegear avatar Oct 30 '22 21:10 tradegear

I stripped out all styling and started over. The application runs fine on the disconnected Android physical device.

I created a new "Application.Resources" node in App.XAML and began sizing and colorizing fonts, etc.:

<?xml version = "1.0" encoding = "UTF-8" ?>
<Application xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             xmlns:local="clr-namespace:MTRClient"
             x:Class="myClient.App">
    <Application.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="Resources/Styles/Colors.xaml" />
                <ResourceDictionary Source="Resources/Styles/Styles.xaml" />
            </ResourceDictionary.MergedDictionaries>
            <Color x:Key="greyColor">#C0C0C0</Color>
            <Color x:Key="mapBlueBase">#0357A6</Color> 
            <Color x:Key="mapBlueLight">#D4EAFE</Color>
            <Color x:Key="mapBlueEmph">#0305A6</Color>
            <Color x:Key="mapBlueEmphLight">#d2d3fe</Color>
            <Color x:Key="mapBlueDemph">#03A6A4</Color>
            <Color x:Key="mapBrown">#A65203</Color>
            <Color x:Key="mapPurple">#A60357</Color>
            <Color x:Key="otherColor">#0000AD</Color>
            <x:Double x:Key="fontSizeButton">20</x:Double>
            <x:Double x:Key="fontSizeTitle">20</x:Double>
            <x:Double x:Key="fontSizeText">16</x:Double>
            <Style TargetType="Button">
                <Setter Property="FontSize" Value="{StaticResource fontSizeButton}"/>
                <Setter Property="BackgroundColor" Value="{StaticResource mapBlueEmphLight}"/>
                <Setter Property="TextColor" Value="{StaticResource mapBlueEmph}"/>
                <Setter Property="HorizontalOptions" Value="Center" />
                <Setter Property="VerticalOptions" Value="Center" />
                <Setter Property="BorderColor" Value="{StaticResource mapBlueBase}"/>
                <Setter Property="BorderWidth" Value="5" />
            </Style> 
            <Style x:Key="titleLabel" TargetType="Label">
                <Setter Property="HorizontalOptions" Value="Center" />
                <Setter Property="VerticalOptions" Value="Center" />
                <Setter Property="TextColor" Value="{StaticResource mapBlueBase}"/>
                <Setter Property="FontSize" Value="{StaticResource fontSizeTitle}" />
            </Style>
            <Style TargetType="Label">
                <Setter Property="HorizontalOptions" Value="Center" />
                <Setter Property="VerticalOptions" Value="Center" />
                <Setter Property="TextColor" Value="{StaticResource mapBlueBase}"/>
                <Setter Property="FontSize" Value="{StaticResource fontSizeText}" />
            </Style>
            <Style x:Key="subDetlLabel" TargetType="Label">
                <Setter Property="HorizontalOptions" Value="Start" />
                <Setter Property="VerticalOptions" Value="Center" />
                <Setter Property="TextColor" Value="{StaticResource mapBlueBase}"/>
                <Setter Property="FontSize" Value="{StaticResource fontSizeText}" />
            </Style>
            <Style TargetType="Entry">
                <Setter Property="HorizontalOptions" Value="Start" />
                <Setter Property="VerticalOptions" Value="Center" />
                <Setter Property="TextColor" Value="{StaticResource mapBrown}"/>
                <Setter Property="FontSize" Value="{StaticResource fontSizeText}" />
            </Style>
            <Style TargetType="ActivityIndicator">
                <Setter Property="HorizontalOptions" Value="FillAndExpand" />
                <Setter Property="VerticalOptions" Value="CenterAndExpand" />
            </Style>
            <Style TargetType="Frame">
                <Setter Property="HeightRequest" Value="150"/>
                <Setter Property="BorderColor" Value="{StaticResource mapPurple}"/>
                <Setter Property="HasShadow" Value="True"/>
            </Style>
            <Style TargetType="Shadow">
                <Setter Property="Radius" Value="15" />
                <Setter Property="Opacity" Value="0.5" />
                <Setter Property="Brush" Value="{StaticResource mapBlueLight}" />
                <Setter Property="Offset" Value="10,10" />
            </Style>
        </ResourceDictionary>
    </Application.Resources>
</Application>

I made reference to the styles implicitly or explicitly throughout the XAML in my project. The project runs in the Android debugger, or as long as my Android phone is being debugged as a "local device". Once I try to run it on the disconnected Android phone, it immediately blows up. Because I added ALL of my styling to the app.XAML, and because by definition all resources are then defined within this file, it would seem a reasonable expectation that any dependent resources necessary on any targeted framework would be handled, no?

Is there a way to get styling to work on Android phones?

BTW - I couldn't get the "add code" button to work. It either adds a bunch of space, or it removes all formatting. I left it with the formatting removed.

tradegear avatar Oct 31 '22 20:10 tradegear

Hi @tradegear. We have added the "s/needs-repro" label to this issue, which indicates that we require steps and sample code to reproduce the issue before we can take further action. Please try to create a minimal sample project/solution or code samples which reproduce the issue, ideally as a GitHub repo that we can clone. See more details about creating repros here: https://github.com/dotnet/maui/blob/main/.github/repro.md

This issue will be closed automatically in 7 days if we do not hear back from you by then - please feel free to re-open it if you come back to this issue after that time.

ghost avatar Nov 01 '22 19:11 ghost

I have already wasted many many hours working around this issue. I don't plan on taking the additional time to work up a project. I'm too busy trying to figure out why my iOS device simulator won't run. All that is necessary is make reference to a static resource, like: Style="{StaticResource MediumLabel}" and the code will blow on android device.

tradegear avatar Nov 02 '22 23:11 tradegear

As a workaround, I added styling to every control in my Maui app. Just the way we are not supposed to do it. But I have a project to deliver and I have to make it work however I can make it work. From what I see, StaticResource doesn't work on Android, so I have jumped over it.

tradegear avatar Nov 03 '22 14:11 tradegear

I have already wasted many many hours working around this issue. I don't plan on taking the additional time to work up a project. I'm too busy trying to figure out why my iOS device simulator won't run.

While I understand your situation, I hope you also understand that this means it will be much harder for us to prioritize and diagnose this issue properly. We cannot see what you're seeing and doing. Having a reproduction project will greatly help speed that us. If this is actually an issue with us, running your reproduction will make that clear immediately. Instead, if we don't have that we might be spending hours trying to read through your comments and what you are trying to explain to us, basically mind reading and back tracking what you are trying to do. Time that we rather spend on fixing your actual issue(s).

Also see: https://github.com/dotnet/maui/blob/main/.github/repro.md#but-i-dont-have-time-for-this

It seems that you have resolved the issue for now. It you still think there is a bug on our side that you'd like to see fixed, please open a new issue and attach a reproduction.

Thanks!

jfversluis avatar Nov 06 '22 15:11 jfversluis