android - Cordova 自适应图标链接文件资源错误

标签 android xml cordova

我使用 android studio 生成我的图像 Assets 并将文件移动到 res/android 并遵循此处概述的对 config.xml 的更改:Android Oreo - how do I set Adaptive Icons in Cordova?

马上我得到一个错误:Source path does not exist: res/android/drawable/ic_launcher_background.xml因为我的图像 Assets 没有生成可绘制文件夹。如果我注释掉这些行:

<!-- <resource-file src="res/android/drawable/ic_launcher_background.xml" target="app/src/main/res/drawable/ic_launcher_background.xml" /> -->
<!-- <resource-file src="res/android/drawable/ic_launcher_foreground.xml" target="app/src/main/res/drawable/ic_launcher_foreground.xml" /> -->


构建能够开始,但我收到链接错误:
* What went wrong:
Execution failed for task ':app:processDebugResources'.
> Android resource linking failed
  /home/jaimeandres/git/firebones/FireBonesMobileApp/platforms/android/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml:4: AAPT: error: resource mipmap/ic_launcher_foreground (aka com.firebones.app:mipmap/ic_launcher_foreground) not found.

  /home/jaimeandres/git/firebones/FireBonesMobileApp/platforms/android/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml:4: AAPT: error: resource mipmap/ic_launcher_foreground (aka com.firebones.app:mipmap/ic_launcher_foreground) not found.

  error: failed linking file resources.


下面是Android Studio生成的资源

Image of resources generated

最佳答案

必须单独将 foreground.png 添加到每个 dpi


    <platform name="android">
        <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>
        <resource-file src="res/android/values/ic_launcher_background.xml" target="app/src/main/res/values/ic_launcher_background.xml" />
        <!-- <resource-file src="res/android/drawable/ic_launcher_foreground.xml" target="app/src/main/res/drawable/ic_launcher_foreground.xml" /> -->
        <resource-file src="res/android/mipmap-anydpi-v26/ic_launcher.xml" target="app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml" />
        <resource-file src="res/android/mipmap-anydpi-v26/ic_launcher_round.xml" target="app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml" />
        <!-- hdpi -->
        <resource-file src="res/android/mipmap-hdpi/ic_launcher.png" target="app/src/main/res/mipmap-hdpi/ic_launcher.png" />
        <resource-file src="res/android/mipmap-hdpi/ic_launcher_round.png" target="app/src/main/res/mipmap-hdpi/ic_launcher_round.png" />
        <resource-file src="res/android/mipmap-hdpi/ic_launcher_foreground.png" target="app/src/main/res/mipmap-hdpi/ic_launcher_foreground.png" />
        <!-- mdpi -->
        <resource-file src="res/android/mipmap-mdpi/ic_launcher.png" target="app/src/main/res/mipmap-mdpi/ic_launcher.png" />
        <resource-file src="res/android/mipmap-mdpi/ic_launcher_round.png" target="app/src/main/res/mipmap-mdpi/ic_launcher_round.png" />
        <resource-file src="res/android/mipmap-mdpi/ic_launcher_foreground.png" target="app/src/main/res/mipmap-mdpi/ic_launcher_foreground.png" />

        <!-- xhdpi -->
        <resource-file src="res/android/mipmap-xhdpi/ic_launcher.png" target="app/src/main/res/mipmap-xhdpi/ic_launcher.png" />
        <resource-file src="res/android/mipmap-xhdpi/ic_launcher_round.png" target="app/src/main/res/mipmap-xhdpi/ic_launcher_round.png" />
        <resource-file src="res/android/mipmap-xhdpi/ic_launcher_foreground.png" target="app/src/main/res/mipmap-xhdpi/ic_launcher_foreground.png" />
        <!-- xxhdpi -->
        <resource-file src="res/android/mipmap-xxhdpi/ic_launcher.png" target="app/src/main/res/mipmap-xxhdpi/ic_launcher.png" />
        <resource-file src="res/android/mipmap-xxhdpi/ic_launcher_round.png" target="app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png" />
        <resource-file src="res/android/mipmap-xxhdpi/ic_launcher_foreground.png" target="app/src/main/res/mipmap-xxhdpi/ic_launcher_foreground.png" />
        <!-- xxxhdpi -->
        <resource-file src="res/android/mipmap-xxxhdpi/ic_launcher.png" target="app/src/main/res/mipmap-xxxhdpi/ic_launcher.png" />
        <resource-file src="res/android/mipmap-xxxhdpi/ic_launcher_round.png" target="app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png" />
        <resource-file src="res/android/mipmap-xxxhdpi/ic_launcher_foreground.png" target="app/src/main/res/mipmap-xxxhdpi/ic_launcher_foreground.png" />
    </platform>  

关于android - Cordova 自适应图标链接文件资源错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60710627/

相关文章:

javascript - 无法在 Jquerymobile 中获取 slider 值

android - 在 Android 中运行 Vuforia 示例时出错

android - ViewPagerIndicator 导致随机崩溃

java - 如何在 ViewModel 中将 LiveData<List<User>> 转换为 LiveData<List<String>> ?

ios - IONIC BUILD IOS 什么都不做,只是下降到下一行

angular - 谷歌本地 map 不适用于 ionic 3

java - 我是否应该将 Android 中的(在线)数据库查询放入一个单独的线程中,同时 UI 应该显示什么?

C# Linq to XML 读取带有属性的多个标签

c++ - 有没有更好的设计模式/方法可以使用?

java - 添加到 fragment 时按钮不起作用