Troubleshooting Release Build Error in .NET MAUI Application for Android

huangapple go评论156阅读模式
英文:

Troubleshooting Release Build Error in .NET MAUI Application for Android

问题

我正在构建一个使用.NET版本7.0.306(x64)和Visual Studio 2022版本17.6.5的.NET MAUI应用程序。我相信这些是最新版本。目前,我正在专注于Android平台。

问题:
在调试模式下,应用程序运行正常。然而,当我尝试构建发布版本并在我的真实物理测试设备(三星)上运行时,问题就出现了。就在Visual Studio编译过程的最后,我收到以下错误消息:

Severity	Code	Description	Project	File	Line	Suppression State
Warning		MSB3073: 命令““C:\Program Files (x86)\Android\android-sdk\platform-tools\adb” -s RFCN30KRB2M uninstall -k “com.company.appname””退出代码为1。

Visual Studio在某种程度上成功安装了应用程序,但它处于损坏状态。我在构建之前手动卸载了设备上的应用程序。

我尝试过的方法:
我在网上搜索答案,并找到了一个似乎适用于我的问题描述的旧帖子。然而,它是针对Maui Blazor应用程序的。MauiIssue

我尝试了该问题中提到的解决方法,但问题没有解决。

这个Stack Overflow问题中的建议确实有效:

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

然而,我听说这些设置在发布模式下不应该关闭,因为包可能会变得非常大。我还听说AOT(Ahead-of-Time)编译对于iOS非常重要。

我的问题是:
有人知道是什么原因导致了这个问题,并且是否已经修复?如果已经修复,我应该使用哪个.NET版本?

编辑:
我刚刚从头开始创建了一个全新的MAUI项目,以查看一个未经修改的项目是否可以从一开始就在发布模式下构建。我仍然收到相同的错误。我是否遗漏了什么?MAUI是否准备好投入生产?

MauiApp1似乎可以工作,但它没有太多的逻辑。我尝试关闭链接器和AOT,构建自己的应用程序,主要功能使用了Azure认知服务,但无法正常工作。我无法调试,因为调试器无法在发布模式下附加。这是正常的吗?

编辑2:
我刚刚升级到Visual Studio 2022版本17.7(于8月8日发布)。我会尝试一下,看看它是否修复了我的问题。但它没有起作用。

编辑3:
我安装了.NET 8.0.100-preview和Visual Studio版本17.8.0 preview 1,但我仍然没有运气。我不知道还能尝试什么。在投入数周的开发之前,我应该尝试在发布模式下构建项目。还有其他人遇到这个问题吗?如果有,你是如何解决的?

按钮样式:

<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>
英文:

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 &quot;&quot;C:\Program Files (x86)\Android\android-sdk\platform-tools\adb&quot; -s RFCN30KRB2M uninstall -k &quot;com.company.appname&quot;&quot; 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:

	&lt;PropertyGroup Condition=&quot;&#39;$(TargetFramework)&#39; == &#39;net7.0-android&#39;&quot;&gt;
		&lt;RunAOTCompilation&gt;false&lt;/RunAOTCompilation&gt;
		&lt;AndroidLinkMode&gt;None&lt;/AndroidLinkMode&gt;
	&lt;/PropertyGroup&gt;

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:

&lt;Style TargetType=&quot;Button&quot; x:Key=&quot;ButtonStyle&quot;&gt;
    &lt;Setter Property=&quot;FontFamily&quot; Value=&quot;OpenSansRegular&quot;/&gt;
    &lt;Setter Property=&quot;FontSize&quot; Value=&quot;16&quot;/&gt;
    &lt;Setter Property=&quot;Padding&quot; Value=&quot;10,10&quot;/&gt;

    &lt;Setter Property=&quot;Margin&quot; Value=&quot;5&quot; /&gt;
    &lt;Setter Property=&quot;MinimumHeightRequest&quot; Value=&quot;65&quot;/&gt;
    &lt;Setter Property=&quot;MinimumWidthRequest&quot; Value=&quot;65&quot;/&gt;
    &lt;Setter Property=&quot;BackgroundColor&quot; Value=&quot;{StaticResource Primary}&quot; /&gt;
    &lt;Setter Property=&quot;TextColor&quot; Value=&quot;{StaticResource Black}&quot; /&gt;
    &lt;Setter Property=&quot;CornerRadius&quot; Value=&quot;10&quot;/&gt;
    &lt;Setter Property=&quot;Shadow&quot;&gt;
        &lt;Setter.Value&gt;
            &lt;Shadow Brush=&quot;{StaticResource TertiaryBrush}&quot; Offset=&quot;10,10&quot; Radius=&quot;40&quot; Opacity=&quot;0.80&quot;/&gt;
        &lt;/Setter.Value&gt;
    &lt;/Setter&gt;

    &lt;Setter Property=&quot;VisualStateManager.VisualStateGroups&quot;&gt;
        &lt;VisualStateGroupList&gt;
            &lt;VisualStateGroup x:Name=&quot;CommonStates&quot;&gt;
                &lt;VisualState x:Name=&quot;Normal&quot; /&gt;
                &lt;VisualState x:Name=&quot;Disabled&quot;&gt;
                    &lt;VisualState.Setters&gt;
                        &lt;Setter Property=&quot;TextColor&quot; Value=&quot;{AppThemeBinding Light={StaticResource Gray950}, Dark={StaticResource Gray200}}&quot; /&gt;
                        &lt;Setter Property=&quot;BackgroundColor&quot; Value=&quot;{AppThemeBinding Light={StaticResource Gray200}, Dark={StaticResource Gray600}}&quot; /&gt;
                    &lt;/VisualState.Setters&gt;
                &lt;/VisualState&gt;
            &lt;/VisualStateGroup&gt;
        &lt;/VisualStateGroupList&gt;
    &lt;/Setter&gt;
&lt;/Style&gt;

答案1

得分: 0

我可以在我的项目中重现你的问题。当我在发布模式下进行测试时,我发现TextColor会改变,但BackgroundColor不会改变。

因此,我使用了Background属性而不是BackgroundColor属性,并且它起作用了。例如:

&lt;Style TargetType=&quot;Button&quot; x:Key=&quot;ButtonStyle&quot;&gt;
    &lt;Setter Property=&quot;FontFamily&quot; Value=&quot;OpenSansRegular&quot;/&gt;
    &lt;Setter Property=&quot;FontSize&quot; Value=&quot;16&quot;/&gt;
    &lt;Setter Property=&quot;Padding&quot; Value=&quot;10,10&quot;/&gt;

    &lt;Setter Property=&quot;Margin&quot; Value=&quot;5&quot; /&gt;
    &lt;Setter Property=&quot;MinimumHeightRequest&quot; Value=&quot;65&quot;/&gt;
    &lt;Setter Property=&quot;MinimumWidthRequest&quot; Value=&quot;65&quot;/&gt;
    &lt;Setter Property=&quot;Background&quot; Value=&quot;{StaticResource Primary}&quot; /&gt;
    &lt;Setter Property=&quot;TextColor&quot; Value=&quot;{StaticResource Black}&quot; /&gt;
    &lt;Setter Property=&quot;CornerRadius&quot; Value=&quot;10&quot;/&gt;
    &lt;Setter Property=&quot;Shadow&quot;&gt;
        &lt;Setter.Value&gt;
            &lt;Shadow Brush=&quot;{StaticResource TertiaryBrush}&quot; Offset=&quot;10,10&quot; Radius=&quot;40&quot; Opacity=&quot;0.80&quot;/&gt;
        &lt;/Setter.Value&gt;
    &lt;/Setter&gt;

    &lt;Setter Property=&quot;VisualStateManager.VisualStateGroups&quot;&gt;
        &lt;VisualStateGroupList&gt;
            &lt;VisualStateGroup x:Name=&quot;CommonStates&quot;&gt;
                &lt;VisualState x:Name=&quot;Normal&quot; /&gt;
                &lt;VisualState x:Name=&quot;Disabled&quot;&gt;
                    &lt;VisualState.Setters&gt;
                        &lt;Setter Property=&quot;TextColor&quot; Value=&quot;{AppThemeBinding Light={StaticResource Gray950}, Dark={StaticResource Gray200}}&quot; /&gt;
                        &lt;Setter Property=&quot;Background&quot; Value=&quot;{AppThemeBinding Light={StaticResource Gray200}, Dark={StaticResource Gray600}}&quot; /&gt;
                    &lt;/VisualState.Setters&gt;
                &lt;/VisualState&gt;
            &lt;/VisualStateGroup&gt;
        &lt;/VisualStateGroupList&gt;
    &lt;/Setter&gt;
&lt;/Style&gt;

有关更多信息,你可以参考这个已知问题:iOS和Android在发布模式下在更改状态时不会更改按钮的背景颜色

英文:

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:

&lt;Style TargetType=&quot;Button&quot; x:Key=&quot;ButtonStyle&quot;&gt;
    &lt;Setter Property=&quot;FontFamily&quot; Value=&quot;OpenSansRegular&quot;/&gt;
    &lt;Setter Property=&quot;FontSize&quot; Value=&quot;16&quot;/&gt;
    &lt;Setter Property=&quot;Padding&quot; Value=&quot;10,10&quot;/&gt;

    &lt;Setter Property=&quot;Margin&quot; Value=&quot;5&quot; /&gt;
    &lt;Setter Property=&quot;MinimumHeightRequest&quot; Value=&quot;65&quot;/&gt;
    &lt;Setter Property=&quot;MinimumWidthRequest&quot; Value=&quot;65&quot;/&gt;
    &lt;Setter Property=&quot;Background&quot; Value=&quot;{StaticResource Primary}&quot; /&gt;
    &lt;Setter Property=&quot;TextColor&quot; Value=&quot;{StaticResource Black}&quot; /&gt;
    &lt;Setter Property=&quot;CornerRadius&quot; Value=&quot;10&quot;/&gt;
    &lt;Setter Property=&quot;Shadow&quot;&gt;
        &lt;Setter.Value&gt;
            &lt;Shadow Brush=&quot;{StaticResource TertiaryBrush}&quot; Offset=&quot;10,10&quot; Radius=&quot;40&quot; Opacity=&quot;0.80&quot;/&gt;
        &lt;/Setter.Value&gt;
    &lt;/Setter&gt;

    &lt;Setter Property=&quot;VisualStateManager.VisualStateGroups&quot;&gt;
        &lt;VisualStateGroupList&gt;
            &lt;VisualStateGroup x:Name=&quot;CommonStates&quot;&gt;
                &lt;VisualState x:Name=&quot;Normal&quot; /&gt;
                &lt;VisualState x:Name=&quot;Disabled&quot;&gt;
                    &lt;VisualState.Setters&gt;
                        &lt;Setter Property=&quot;TextColor&quot; Value=&quot;{AppThemeBinding Light={StaticResource Gray950}, Dark={StaticResource Gray200}}&quot; /&gt;
                        &lt;Setter Property=&quot;Background&quot; Value=&quot;{AppThemeBinding Light={StaticResource Gray200}, Dark={StaticResource Gray600}}&quot; /&gt;
                    &lt;/VisualState.Setters&gt;
                &lt;/VisualState&gt;
            &lt;/VisualStateGroup&gt;
        &lt;/VisualStateGroupList&gt;
    &lt;/Setter&gt;
&lt;/Style&gt;

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.

huangapple
  • 本文由 发表于 2023年8月8日 23:22:39
  • 转载请务必保留本文链接:https://go.coder-hub.com/76860987.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定