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

.NET MAUI 6启动动画实现报错求助:APT2230与APT2000错误

.NET MAUI Android启动动画配置错误修复指南

错误原因分析

你遇到的两个APT错误核心原因如下:

  1. APT2230:最初未将style.xml包裹在<resources>根元素中(你已修复此问题)
  2. APT2000:animated-vector资源的放置路径、生成操作设置错误,或项目SDK版本未满足Android 12(API 31)的要求

分步修复方案

1. 确认资源文件结构与生成操作

  • 将拆分后的vector_icon.xml和avd_anim.xml放在Platforms/Android/Resources/drawable目录下
  • 右键每个资源文件 → 属性 → 设置生成操作为AndroidResource

2. 升级项目SDK版本

windowSplashScreenAnimatedIcon是Android 12新增API,需确保:

  • 在Platforms/Android/AndroidManifest.xml中设置:
    <uses-sdk android:minSdkVersion="21" android:targetSdkVersion="33" />
    
  • 在项目.csproj文件中配置目标框架为Android 33+:
    <TargetFrameworks>net7.0-android33;net7.0-ios;...</TargetFrameworks>
    

3. 拆分animated-vector资源(解决兼容性问题)

避免使用aapt:attr嵌套写法,拆分静态矢量图和动画配置为两个独立文件:

vector_icon.xml(静态矢量图)

<?xml version="1.0" encoding="utf-8"?>
<vector
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:name="vector"
    android:width="96dp"
    android:height="96dp"
    android:viewportWidth="96"
    android:viewportHeight="96">
    <path
        android:name="path"
        android:pathData="M 36 64.8 L 19.2 48 L 13.6 53.6 L 36 76 L 84 28 L 78.4 22.4 Z"
        android:fillColor="#00d910"
        android:strokeWidth="1"
        android:strokeLineCap="square"
        android:strokeLineJoin="round"
        android:fillType="evenOdd"/>
</vector>

avd_anim.xml(动画配置)

<?xml version="1.0" encoding="utf-8"?>
<animated-vector xmlns:android="http://schemas.android.com/apk/res/android">
    <android:drawable="@drawable/vector_icon"/>
    <target android:name="path">
        <android:animation>
            <set>
                <objectAnimator
                    android:propertyName="pathData"
                    android:startOffset="200"
                    android:duration="100"
                    android:valueFrom="M 36 64.8 L 19.2 48 L 13.6 53.6 L 36 76 L 84 28 L 78.4 22.4 Z"
                    android:valueTo="M 36 64.8 L 19.2 48 L 13.6 53.6 L 36 76 L 84 28 L 78.4 22.4 Z"
                    android:valueType="pathType"
                    android:interpolator="@android:interpolator/fast_out_slow_in"/>
                <objectAnimator
                    android:propertyName="pathData"
                    android:startOffset="100"
                    android:duration="100"
                    android:valueFrom="M 36 64.8 L 19.2 48 L 13.6 53.6 L 36 76 L 84 28 L 78.4 22.4 Z"
                    android:valueTo="M 36 64.8 L 19.2 48 L 13.6 53.6 L 36 76 L 84 28 L 78.4 22.4 Z"
                    android:valueType="pathType"
                    android:interpolator="@android:interpolator/fast_out_slow_in"/>
                <objectAnimator
                    android:propertyName="pathData"
                    android:duration="1000"
                    android:valueFrom="M 36 64.8 L 78.4 22.4 L 84 28 L 36 76 L 13.6 53.6 L 19.2 48 L 36 64.8"
                    android:valueTo="M 36 64.8 L 19.2 48 L 13.6 53.6 L 36 76 L 84 28 L 78.4 22.4 L 36 64.8"
                    android:valueType="pathType"
                    android:interpolator="@android:anim/anticipate_interpolator"/>
            </set>
        </android:animation>
    </target>
</animated-vector>

4. 优化style.xml配置

<?xml version="1.0" encoding="utf-8" ?>
<resources>
    <style name="MyAppTheme" parent="Maui.SplashTheme">
        <item name="android:statusBarColor">@android:color/transparent</item>
        <item name="android:windowContentOverlay">@null</item>
        <item name="android:windowSplashScreenAnimatedIcon">@drawable/avd_anim</item>
        <item name="android:windowSplashScreenIconBackgroundColor">@android:color/black</item>
        <!-- 动画时长需与配置中的总时长匹配(200+100+1000=1300ms) -->
        <item name="android:windowSplashScreenAnimationDuration">1300</item>
    </style>
</resources>

验证步骤

  1. 清理项目:点击生成→清理解决方案
  2. 重建项目:点击生成→重建解决方案
  3. 在Android 12+设备或模拟器上运行项目,启动动画将正常播放

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.22 15:56:59