You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

.NET MAUI Blazor App构建报错:找不到指定Android运行时包

问题描述

我构建.NET MAUI Blazor App时遇到报错,之前应用运行正常,现在提示:

There was no runtime pack for Microsoft.AspNetCore.App available for the specified RuntimeIdentifier 'android-...'

我已经搜索了好几个小时都没解决,求恢复运行的方法。

更新:
使用Visual Studio Community 17.8.1,以下是我的.csproj文件:

<Project Sdk="Microsoft.NET.Sdk.Razor">

    <PropertyGroup>
        <TargetFrameworks>net8.0-android</TargetFrameworks>
        <!-- Uncomment to also build the tizen app. You will need to install tizen by following this: https://github.com/Samsung/Tizen.NET -->
        <!-- <TargetFrameworks>$(TargetFrameworks);net8.0-tizen</TargetFrameworks> -->

        <!-- Note for MacCatalyst:
            The default runtime is maccatalyst-x64, except in Release config, in which case the default is maccatalyst-x64;maccatalyst-arm64.
            When specifying both architectures, use the plural <RuntimeIdentifiers> instead of the singular <RuntimeIdentifier>.
            The Mac App Store will NOT accept apps with ONLY maccatalyst-arm64 indicated;
            either BOTH runtimes must be indicated or ONLY macatalyst-x64. -->
        <!-- For example: <RuntimeIdentifiers>maccatalyst-x64;maccatalyst-arm64</RuntimeIdentifiers> -->

        <OutputType>Exe</OutputType>
        <RootNamespace>Erp.Mobile.App</RootNamespace>
        <UseMaui>true</UseMaui>
        <SingleProject>true</SingleProject>
        <ImplicitUsings>enable</ImplicitUsings>
        <EnableDefaultCssItems>false</EnableDefaultCssItems>
        <Nullable>enable</Nullable>

        <!-- Display name -->
        <ApplicationTitle>TW</ApplicationTitle>

        <!-- App Identifier -->
        <ApplicationId>com.tw.erp.mobile.app</ApplicationId>

        <!-- Versions -->
        <ApplicationDisplayVersion>1.0</ApplicationDisplayVersion>
        <ApplicationVersion>1</ApplicationVersion>

        <SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'ios'">14.2</SupportedOSPlatformVersion>
        <SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'maccatalyst'">14.0</SupportedOSPlatformVersion>
        <SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'android'">24.0</SupportedOSPlatformVersion>
        <SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'windows'">10.0.17763.0</SupportedOSPlatformVersion>
        <TargetPlatformMinVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'windows'">10.0.17763.0</TargetPlatformMinVersion>
        <SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'tizen'">6.5</SupportedOSPlatformVersion>
        <PlatformTarget>AnyCPU</PlatformTarget>
    </PropertyGroup>

    <PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Debug|net8.0-android|AnyCPU'">
      <ApplicationTitle>TW</ApplicationTitle>
      <ApplicationId>com.tw.erp.mobile.app</ApplicationId>
    </PropertyGroup>

    <PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Debug|net8.0-maccatalyst|AnyCPU'">
      <ApplicationTitle>TW</ApplicationTitle>
      <ApplicationId>com.tw.erp.mobile.app</ApplicationId>
    </PropertyGroup>

    <PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Release|net8.0-android|AnyCPU'">
      <ApplicationTitle>TW</ApplicationTitle>
      <ApplicationId>com.tw.erp.mobile.app</ApplicationId>
    </PropertyGroup>

    <PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Release|net8.0-maccatalyst|AnyCPU'">
      <ApplicationTitle>TW</ApplicationTitle>
      <ApplicationId>com.tw.erp.mobile.app</ApplicationId>
    </PropertyGroup>

    <ItemGroup>
        <!-- App Icon -->
        <MauiIcon Include="Resources\AppIcon\tw_icon.svg" ForegroundFile="Resources\AppIcon\tw_icon.svg" Color="#231f20" />

        <!-- Splash Screen -->
        <MauiSplashScreen Include="Resources\Splash\tw_splash.svg" Color="#231f20" BaseSize="256,256" />

        <!-- Images -->
        <MauiImage Include="Resources\Images\*" />

        <!-- Custom Fonts -->
        <MauiFont Include="Resources\Fonts\*" />

        <!-- Raw Assets (also remove the "Resources\Raw" prefix) -->
        <MauiAsset Include="Resources\Raw\**" LogicalName="%(RecursiveDir)%(Filename)%(Extension)" />
    </ItemGroup>

    <ItemGroup>
      <Content Remove="wwwroot\css\open-iconic\FONT-LICENSE" />
      <Content Remove="wwwroot\css\open-iconic\font\fonts\open-iconic.svg" />
      <Content Remove="wwwroot\css\open-iconic\ICON-LICENSE" />
      <Content Remove="wwwroot\css\open-iconic\README.md" />
    </ItemGroup>

    <ItemGroup>
      <None Remove="Resources\AppIcon\tw_icon.svg" />
      <None Remove="Resources\Splash\tw_splash.svg" />
    </ItemGroup>

    <ItemGroup>
        <PackageReference Include="Microsoft.Maui.Controls" Version="$(MauiVersion)" />
        <PackageReference Include="Microsoft.Maui.Controls.Compatibility" Version="$(MauiVersion)" />
        <PackageReference Include="Microsoft.AspNetCore.Components.WebView.Maui" Version="$(MauiVersion)" />
        <PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="8.0.0" />
        <PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
        <PackageReference Include="ServiceStack" Version="8.0.0" />
        <PackageReference Include="ServiceStack.Text" Version="8.0.0" />
    </ItemGroup>

    <ItemGroup>
      <None Include="wwwroot\css\open-iconic\FONT-LICENSE" />
      <None Include="wwwroot\css\open-iconic\font\fonts\open-iconic.svg" />
      <None Include="wwwroot\css\open-iconic\ICON-LICENSE" />
      <None Include="wwwroot\css\open-iconic\README.md" />
    </ItemGroup>

    <ItemGroup>
      <ProjectReference Include="..\Erp.Entity\Erp.Entity.csproj" />
    </ItemGroup>

    <ItemGroup>
      <Folder Include="Resources\Images\" />
    </ItemGroup>

</Project>
解决方案

针对这个报错,尝试以下几个步骤:

1. 安装对应Android版本的.NET运行时包

打开Visual Studio的工具 > 获取工具和功能,在工作负载中确认已安装**.NET Multi-platform App UI开发**,检查右侧组件列表,确保你目标Android版本对应的.NET 8 runtime pack已安装(比如报错里的RuntimeIdentifier是android-34,就确认Android 14.0 (API 34)的.NET SDK组件已勾选)。

2. 手动指定RuntimeIdentifiers

在项目的<PropertyGroup>中添加复数形式的RuntimeIdentifiers,指定Android支持的架构,示例:

<RuntimeIdentifiers>android-arm64;android-x64;android-x86</RuntimeIdentifiers>

3. 清理并重建项目

  • 右键项目,选择清理
  • 再选择重建
  • 手动删除项目目录下的bin和obj文件夹,清理残留编译文件

4. 检查NuGet包版本一致性

确认所有Microsoft相关包版本匹配:Microsoft.Maui.Controls、Microsoft.AspNetCore.Components.WebView.Maui都使用$(MauiVersion),Microsoft.Extensions.Logging.Debug保持8.0.0与.NET 8兼容。可以尝试更新所有NuGet包到最新兼容版本,或回退到之前能正常运行的版本。

5. 检查引用的类库兼容性

确认你引用的Erp.Entity项目目标框架与MAUI项目兼容(比如同为net8.0或net8.0-android),如果类库引用了不兼容的ASP.NET Core组件,也可能触发该报错。


内容的提问来源于stack exchange,提问作者Nesse

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.05 13:44:54