【问题标题】:Image Asset NOT generating ic_launcher_foreground.xml file图像资产未生成 ic_launcher_foreground.xml 文件
【发布时间】:2023-03-12 23:13:01
【问题描述】:

我已经在图像资产工具中创建了所有自适应图标,但它没有创建 ic_launcher_foreground.xml 文件 - 这反过来又导致我的构建失败,因为在 ic_launcher.xml 和 ic_launcher_round 中引用了foreground.xml 文件.xml 文件。

我已经阅读了许多关于如何解决此问题的主题,但没有一个有效。

同样,ic_launcher.xml 和 ic_launcher_round.xml 文件都专门引用了这两个文件:

<background android:drawable="@drawable/ic_launcher_background" />
<foreground android:drawable="@mipmap/ic_launcher_foreground" />

/drawable 文件夹正在使用 ic_launcher_background.xml 文件创建,但图像资产工具并未创建 /mipmap 文件夹 - 它似乎正在创建所有其他 /mipmap-XYZdpi 文件夹和图标。

我提出这个问题是因为很多其他线程显示 ic_launcher.xml 和 ic_launcher_round.xml 文件引用了同一 /drawable 文件夹中的 background.xml 和 foreground.xml 文件,这与我上面的不同。

在图像资源中: 前景选项卡: 图层名称:ic_launcher_foreground 资产类型:图片 路径:/dev/myApp/resources/myCustomIcon.png 背景选项卡: 图层名称:ic_launcher_background 资产类型:图片 路径:res/drawable/ic_launcher_background.xml

我唯一能让ic_launcher_foreground.xml 文件出现在“输出文件”屏幕中的情况是,如果在前台选项卡上选择Asset Type: Clip Art

更新:

我在与我的项目相关的 Android Studio 文件夹深处的 drawable (v24) 文件夹中找到了一个 ic_launcher_foreground.xml 文件。我将该文件复制到我的项目 res/drawable 文件夹中 - 现在,当我的应用程序编译到我的测试设备时,我得到了 Android 半机器人图标。

【问题讨论】:

  • 猜猜我想做相反的事情:让我的新图标被使用。在 Image Asset Studio 中制作新图标后,我将 ic_launcher_foreground 从 res/drawable 复制到 res/drawable-v24,在那里覆盖了 Android 半机器人。 (最好在项目视图而不是 Android 视图中完成。)
  • 不确定在创建图像资产时将名称更改为“ic_launcher_foreground_something”是否有帮助

标签: android-studio cordova android-icons


【解决方案1】:

好吧,我终于想通了。为遇到相同问题的其他人发布我的答案。

使用图像资产工具 - ic_launcher_foreground.xmlic_launcher_background.xml 仅在每种类型(前景选项卡/背景选项卡)资产类型定义为除图像类型之外的任何内容时才会生成。 PNG/JPG 资产类型不会生成这些 xml 文件。

无论资产类型如何,都会生成ic_launcher.xmlic_launcher_round.xml。如果资产类型是颜色/艺术/文本,这两个 xml 文件都只是引用其他文件 - 引用将指向位于 @drawable/ 文件夹或 @values/ 文件夹中的其他 XML 文件。

<background android:drawable="@drawable/ic_launcher_background" /> OR 
<background android:drawable="@values/ic_launcher_background" /> 
//@drawable - is the root of all your drawables folders
//   - and references only XML, ie: ie_launcher_background.xml

如果资产类型是图像 (png/jpg),则引用将指向存在于任何 @mipmap 文件夹中的新创建的 png/jpg 文件。

<foreground android:drawable="@mipmap/ic_launcher_foreground" />
// @mipmap is simply root of all your mipmap folders
// references actual png files, ie: ic_launcher_foreground.png

最后,如果您使用的是 Cordova,您需要修改 config.xml 以反映要使用的图标文件:

<edit-config file="app/src/main/AndroidManifest.xml" mode="merge" target="/manifest/application">
     <application android:icon="@mipmap/ic_launcher"  android:roundIcon="@mipmap/ic_launcher_round" />
</edit-config>
// this telling the app to find those two XML files in the mipmap-anydpi-v26 folder
// and those files in turn tell the app to find all the png files in the other "mipmap" folders

// if it were this:
<edit-config file="app/src/main/AndroidManifest.xml" mode="merge" target="/manifest/application">
     <application android:icon="@drawable/ic_launcher"  android:roundIcon="@drawable/ic_launcher_round" />
</edit-config>
// this telling the app to use the XML files sourced in the drawable folders
// if you used png as foreground and color as background
// ic_launcher.xml/ic_launcher_round.xml would both point to:
//      @mipmap/ic_launcher_foreground   (ie: png images)
//      @drawable/ic_launcher_background  (ie: xml files)

我希望这对其他人有所帮助,因为我觉得以上所有内容在其他文档中都没有得到很好的解释。

【讨论】:

    【解决方案2】:

    现在很简单:通过右键单击“res”或“mipmap”文件夹启动“Image Asset Studio”,然后从弹出菜单中选择“New > Image Asset”。 Image Asset Studio 现在将打开。现在您可以根据自己的要求创建自适应启动器图标或仅旧版启动器图标。

    要更新现有图标,只需选择现有的 ic_launcher_foreground.xml 文件和 ic_launcher_background.xml 文件,然后点击“下一步”创建新定义,覆盖旧定义。

    【讨论】:

      【解决方案3】:

      嗯,做了什么......(经常发生的情况是,其他人的解决方案说他们最终修复了它对我不起作用,所以我想我会提供另一个可能只起作用的解决方案对我来说:))

      首先,我按原样生成了图像资产文件。我右键单击 res 文件夹,单击“新建”,然后单击“图像资产”。我保留了“源资产”路径(保留了 launcher_foreground.xml 文件的路径)并创建了资产。

      然后我返回并再次生成图像资源,但这次使用的是我自己的 png 图像。到目前为止似乎一直有效,至少在下一次更新使该解决方案过时之前。

      【讨论】:

        【解决方案4】:

        在资产工作室向导的第二页,有一个名为“Res Directory”的下拉菜单。

        我必须在单击完成之前选择调试。之后我就可以构建了。

        【讨论】:

          【解决方案5】:

          打开您的 Android Studio 并转到您的项目并转到 android->app->scr->main->res->mipmap-anydpi-v26 右键单击​​->新建->图像资产->配置图像资产->路径->mipmap-hdpi->ic_launcher_foreground.png 按照这些步骤,你的问题就解决了。

          【讨论】:

            猜你喜欢
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 2020-10-07
            • 1970-01-01
            • 2015-05-25
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            相关资源
            最近更新 更多