【问题标题】:Style.xml file not read in flutter plugin project?颤振插件项目中未读取 Style.xml 文件?
【发布时间】:2018-04-23 23:55:52
【问题描述】:

我正在处理一个颤振项目,iOS 版本运行良好,但 Android 无法构建。它给了我一个关于将我的样式添加到项目中的错误,但它仍然没有读取它们。这是我遇到的错误...

AAPT:错误:资源 drawable/launch_background(又名 com.yourcompany.flutterexample:drawable/launch_background) 没找到。

这是我在 app/src.main/res/values 文件夹中的 styles.xml 文件...

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <style name="LaunchTheme" parent="@android:style/Theme.Black.NoTitleBar">
        <!-- Show a splash screen on the activity. Automatically removed when
             Flutter draws its first frame -->
        <item name="android:windowBackground">@drawable/launch_background</item>
    </style>
</resources>

这就是我在 Manifest 中的阅读方式...

<activity
                android:name=".MainActivity"
                android:launchMode="singleTop"
                android:theme="@style/LaunchTheme"
                android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale|layoutDirection|fontScale|screenLayout|density"
                android:hardwareAccelerated="true"
                android:windowSoftInputMode="adjustResize">
            <!-- This keeps the window background of the activity showing
                 until Flutter renders its first frame. It can be removed if
                 there is no splash screen (such as the default splash screen
                 defined in @style/LaunchTheme). -->
            <meta-data
                    android:name="io.flutter.app.android.SplashScreenUntilFirstFrame"
                    tools:replace="android:value"
                    android:value="true" />
            <intent-filter>
                <action android:name="android.intent.action.MAIN"/>
                <category android:name="android.intent.category.LAUNCHER"/>
            </intent-filter>
        </activity>

【问题讨论】:

  • drawable/launch_background 存在吗?
  • 请尝试删除 android/app/build 文件夹一次

标签: android flutter aapt


【解决方案1】:

AAPT 确实读取了您的 styles.xml 文件,这就是为什么它会抛出有关文件内容的错误。当它尝试链接样式 LaunchTheme 的子 android:windowBackground 时,它会看到对名为 launch_background 的可绘制对象的引用,该引用无法解析。

确保您的任何 res/drawable/ 目录中有一个名为“launch_background”的可绘制对象。

【讨论】:

  • 非常感谢!这节省了我很多时间:)
猜你喜欢
  • 2021-06-09
  • 1970-01-01
  • 2022-08-20
  • 2019-10-19
  • 2020-02-14
  • 2019-07-11
  • 2021-07-08
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多