quasar + cordova项目更换icon

我之前写了如何使用 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

  cordova platform add android  之后文件目录如下:

  

 此时运行到手机  quasar dev -m android 

 按照Cordova 应用的图标 | Quasar 中文文档 | Quasar 框架中文网 (quasar-cn.cn)中文件目录所示:

在 /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.

 

 

posted @ 2024-06-24 14:43  sunshine233  阅读(6)  评论(0编辑  收藏  举报