首页 > 解决方案 > where to put my icon picture for expo to use instead of default one?

问题描述

according to expo documentation:

The most straightforward way to provide an icon for your app is to provide the icon key in app.json

so I added my own icon to the assets folder where expo's default icons are, and modified app.json to point to my icon:

  "expo": {
     ...
     "icon": "./assets/myIcon.png"
  }

but when launching I get this error from expo:

Field: icon - cannot access file at './assets/myIcon.png

what am I missing? where should I put my Icon picture?

Solved by running expo start -c to clear cache. *Note: it took me a few minutes to sync with my expo client app!

标签: react-nativeiconsexpo

解决方案


根据我与问题海报(@Blue Turtle)的对话,我从中得到了一些收获。

图像尺寸

确保您用于图标的图像必须是完美的正方形,这一点很重要。如果不是 Expo 会给出类似下面的错误

Error: Problems validating asset fields in app.json. See https://docs.expo.io/
 • Field: icon - image should be square, but the file at './assets/icon.png' has dimensions 1242x2436.

文档建议您使用大小为1024x1024 https://docs.expo.io/versions/latest/workflow/configuration/#icon的图像

用于应用图标的图像的本地路径或远程 URL。我们建议您使用 1024x1024 png 文件。该图标将出现在主屏幕和 Expo 应用程序中。

清除缓存

此外,在更新资产等时,建议关闭并重新启动捆绑程序,使用以下命令重新启动expo start -c。以这种方式启动捆绑器将确保您的缓存被清除,并且您对包、资产等所做的任何更改都将被进行,并且您希望遇到的错误更少。


推荐阅读