quasar + cordova项目更换icon
约 810 字大约 3 分钟
2025-06-25
我之前写了如何使用 quasar 项目+cordova 打包成 apk,这种情况下运行到手机的 apk 可以使用,但 apk 安装的图标是 cordova 的 logo
- quasar 文档中有更换 cordova 应用图标的教程:Cordova 应用的图标 | Quasar 中文文档 | Quasar 框架中文网 (quasar-cn.cn)
- cordova 更换 icon 教程:Customize App Icons - Apache Cordova
不过我安装Icon Genie CLI时报错了,想了想我还是选择了直接更换 cordova 项目中的图标。
把更换图标放到最后一步!!也就是所有功能都改完了、也调试好了,只剩下图标的时候再更换!
因为要修改 src-cordova
中的文件,如果重新修改了代码,使用 quasar build -m android
的时候要重新生成 src-cordova
中的内容,会报错 :
> Task :app:mergeReleaseResources FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:mergeReleaseResources'.
> A failure occurred while executing com.android.build.gradle.internal.res.Aapt2CompileRunnable
> Android resource compilation failed
ERROR: E:\code_study\lunarMare\src-cordova\platforms\android\app\src\main\res\mipmap-ldpi\ic_launcher.png: AAPT: error: file failed to compile.
* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.
> Get more help at https://help.gradle.org.
BUILD FAILED in 2s
36 actionable tasks: 6 executed, 30 up-to-date
Command failed with exit code 1: E:\code_study\lunarMare\src-cordova\platforms\android\tools\gradlew.bat :app:bundleRelease
App • Command "cordova" failed with exit code: 1
App • ⚠️ FAIL Cordova CLI has failed
更换 icon
cordova platform add android
之后文件目录如下:
此时运行到手机 quasar dev -m android
按照Cordova 应用的图标)中文件目录所示:
在 /src-cordova
下新建 res
文件夹,和 config.xml
同级,res
中再新建 android
,android
中放图片
在 config.xml
中 <widget>
内部指定平台和 icon
图片
<platform name="android">
<icon density="ldpi" src="res/android/favicon-128x128.png" />
</platform>
然后先 quasar build -m android
一下,然后进入 src-cordova
运行到手机:cordova run android
,应用图标就换了
再换一张图片看看:
<platform name="android">
<icon density="ldpi" src="res/android/momo.png" />
</platform>
常见问题
如果修改了代码,需要重启 quasar build -m android
,但此时 src-cordova
中的 res
不是 quasar
自动生成的,所以 quasar build
会报错:
> Task :app:mergeReleaseResources FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:mergeReleaseResources'.
> A failure occurred while executing com.android.build.gradle.internal.res.Aapt2CompileRunnable
> Android resource compilation failed
ERROR: E:\code_study\lunarMare\src-cordova\platforms\android\app\src\main\res\mipmap-ldpi\ic_launcher.png: AAPT: error: file failed to compile.
* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.
> Get more help at https://help.gradle.org.
BUILD FAILED in 2s
48 actionable tasks: 3 executed, 45 up-to-date
Command failed with exit code 1: E:\code_study\lunarMare\src-cordova\platforms\android\tools\gradlew.bat :app:bundleRelease
App • Command "cordova" failed with exit code: 1
App • ⚠️ FAIL Cordova CLI has failed
此时可以删除 src-cordova
文件,重新 quasar dev -m android
所以建议所有的功能都改完了以后,最后一步再换图标!
如果提示下图错误,是因为 run 之前没有 quasar build -m android
.