4

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>
10
  • Did you try to Publish an Android app using the command line. Commented Aug 9, 2023 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 Commented Aug 9, 2023 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. Commented Aug 9, 2023 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 Commented Aug 10, 2023 at 8: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. Commented Aug 10, 2023 at 9:01

2 Answers 2

2

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.

Sign up to request clarification or add additional context in comments.

Comments

0

The original problem mentioned was a build failure in the Release configuration, and I had the same problem.

When I switched build config to release and checked build progress in the Output/Build window, the last message was

========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

As suggested in the first Edit, I turned off AOT and the release build succeeded.

My app is targeting Net6.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.