1

I am building a .NET MAUI application using .NET version 7.0.306(x64) and Visual Studio 2022 version 17.6.5. I believe these are the latest versions. Currently, I am focusing on Android.

The Problem: In debug mode, the application works flawlessly. However, the problem occurs when I try to build the app for release and run it on my real physical test device (Samsung). Just at the end of Visual Studio's compiling process, I get the following error message:

Severity    Code    Description Project File    Line    Suppression State
Warning     MSB3073: The command ""C:\Program Files (x86)\Android\android-sdk\platform-tools\adb" -s RFCN30KRB2M uninstall -k "com.company.appname"" exited with code 1.

Visual Studio somehow manages to install the app, but it's in a broken state. I uninstalled the app manually from the device before building it.

What I Have Tried: I have searched for answers online and found an old thread that seems to fit my problem description. However, it's for a Maui Blazor app. MauiIssue

I have tried what the issue mentions as a fix, but it did not resolve the problem.

What does work are the suggestions from this Stack Overflow question:

    <PropertyGroup Condition="'$(TargetFramework)' == 'net7.0-android'">
        <RunAOTCompilation>false</RunAOTCompilation>
        <AndroidLinkMode>None</AndroidLinkMode>
    </PropertyGroup>

However, I have heard that these settings should not be turned off for release mode, as the package can become quite large. I've also heard that AOT (Ahead-of-Time compilation) is really important for iOS.

My Question: Does anybody know what's causing this issue, and if it has been fixed? Which .NET version should I be running if it has already been resolved?

Edit: I just created a new MAUI project from scratch to see if an untouched project would build in release mode from the start. I still get the same error. Am I missing something? Is MAUI ready for production?

The MauiApp1 seems to work, but then again, it doesn't have much logic in it. I tried to build my own app with the linker and AOT turned off, and the main functionality, which uses Azure Cognitive Service, won't work properly. I can't debug either because the debugger won't attach in release mode. Is that how it's supposed to be?

Edit 2: I just updated to Visual Studio 2022 version 17.7 (came out 8 aug, patch thuesday). I`ll give it a try and see if it fixes the issues I have. It did not work.

Edit 3: I installed .NET 8.0.100-preview and Visual Studio version 17.8.0 preview 1, but I had no luck there either. I don't know what to try anymore. I should have tried to build the project in release mode before pouring weeks of development into my app. Is anyone else having this problem, and if so, how did you solve it?

Button style:

<Style TargetType="Button" x:Key="ButtonStyle">
    <Setter Property="FontFamily" Value="OpenSansRegular"/>
    <Setter Property="FontSize" Value="16"/>
    <Setter Property="Padding" Value="10,10"/>

    <Setter Property="Margin" Value="5" />
    <Setter Property="MinimumHeightRequest" Value="65"/>
    <Setter Property="MinimumWidthRequest" Value="65"/>
    <Setter Property="BackgroundColor" Value="{StaticResource Primary}" />
    <Setter Property="TextColor" Value="{StaticResource Black}" />
    <Setter Property="CornerRadius" Value="10"/>
    <Setter Property="Shadow">
        <Setter.Value>
            <Shadow Brush="{StaticResource TertiaryBrush}" Offset="10,10" Radius="40" Opacity="0.80"/>
        </Setter.Value>
    </Setter>

    <Setter Property="VisualStateManager.VisualStateGroups">
        <VisualStateGroupList>
            <VisualStateGroup x:Name="CommonStates">
                <VisualState x:Name="Normal" />
                <VisualState x:Name="Disabled">
                    <VisualState.Setters>
                        <Setter Property="TextColor" Value="{AppThemeBinding Light={StaticResource Gray950}, Dark={StaticResource Gray200}}" />
                        <Setter Property="BackgroundColor" Value="{AppThemeBinding Light={StaticResource Gray200}, Dark={StaticResource Gray600}}" />
                    </VisualState.Setters>
                </VisualState>
            </VisualStateGroup>
        </VisualStateGroupList>
    </Setter>
</Style>
AllramEst
  • 1,319
  • 4
  • 23
  • 47
  • Did you try to [Publish an Android app using the command line](https://learn.microsoft.com/en-us/dotnet/maui/android/deployment/publish-cli). – Liyun Zhang - MSFT Aug 09 '23 at 10:03
  • Yes, I did, and it worked. It's running on the device downloaded from the Play Store with an invite. However, I have a button control with the IsEnabled attribute bound to a property that has the [ObservableProperty] attribute from the Community.Toolkit.Mvvm.ComponentModel. The button gets activated, but the state colors, which are defined in the style.xml, don't update. Again, it works fine in debug mode – AllramEst Aug 09 '23 at 10:28
  • I have now tested without binding to the IsEnabled attribute. The button still appears disabled even though it is clickable. The connected command also works. Somehow, it loses the style and state triggers, or atleast the trigger that applys the active style. I've added the style XML to the question. – AllramEst Aug 09 '23 at 10:52
  • Yes! I am trying to get your solution to work. But the button refuses to change color. i`ll try to create a new project from scratch. will update – AllramEst Aug 10 '23 at 08:45
  • Did you mean you met the same problem when you used the `Background` instead of the `BackgroundColor`? But it worked correctly in my project which target framework is .Net 6.0 in the release mode. – Liyun Zhang - MSFT Aug 10 '23 at 09:01
  • Yes, I got it working in a new project by directly inheriting the INotifyPropertyChanged in the ViewModel, rather than using the Community.Toolkit as in the app I am building. – AllramEst Aug 10 '23 at 10:35
  • i am on dotnet 7.0 – AllramEst Aug 10 '23 at 10:36
  • I am using the community.toolkit.Mvvm for binding properties – AllramEst Aug 10 '23 at 10:36
  • You can check [this known issue about Commands do not Properly Enable Buttons in Release Builds (Android)](https://github.com/dotnet/maui/issues/10825). So you may need to use the Backgound property and the INotifyPropertyChanged to make it work for now. – Liyun Zhang - MSFT Aug 11 '23 at 03:23
  • Or you can try to create a new .net 6.0 project to test. In my .net 6.0 project, the Background property and the Community.Toolkit work correctly. – Liyun Zhang - MSFT Aug 11 '23 at 03:25

1 Answers1

0

I can reproduce your problem in my project. And I found the TextColor will change but the BackgroundColor not when I test it in the release mode.

So I use the Background property instead of the BackgroundColor property and it worked. Such as:

<Style TargetType="Button" x:Key="ButtonStyle">
    <Setter Property="FontFamily" Value="OpenSansRegular"/>
    <Setter Property="FontSize" Value="16"/>
    <Setter Property="Padding" Value="10,10"/>

    <Setter Property="Margin" Value="5" />
    <Setter Property="MinimumHeightRequest" Value="65"/>
    <Setter Property="MinimumWidthRequest" Value="65"/>
    <Setter Property="Background" Value="{StaticResource Primary}" />
    <Setter Property="TextColor" Value="{StaticResource Black}" />
    <Setter Property="CornerRadius" Value="10"/>
    <Setter Property="Shadow">
        <Setter.Value>
            <Shadow Brush="{StaticResource TertiaryBrush}" Offset="10,10" Radius="40" Opacity="0.80"/>
        </Setter.Value>
    </Setter>

    <Setter Property="VisualStateManager.VisualStateGroups">
        <VisualStateGroupList>
            <VisualStateGroup x:Name="CommonStates">
                <VisualState x:Name="Normal" />
                <VisualState x:Name="Disabled">
                    <VisualState.Setters>
                        <Setter Property="TextColor" Value="{AppThemeBinding Light={StaticResource Gray950}, Dark={StaticResource Gray200}}" />
                        <Setter Property="Background" Value="{AppThemeBinding Light={StaticResource Gray200}, Dark={StaticResource Gray600}}" />
                    </VisualState.Setters>
                </VisualState>
            </VisualStateGroup>
        </VisualStateGroupList>
    </Setter>
</Style>

For more information, you can refer to this known issue about iOS and Android in releasemode does not change background color on button when changing states.

Liyun Zhang - MSFT
  • 8,271
  • 1
  • 2
  • 14