React native,无法解析静态图像的模块

React native, Unable to resolve module for static image

我正在使用 react-native 0.14.1

react-native run-android

[3:10:56 PM] <START> find dependencies
Unable to resolve module image!ic_action_android_back_white3 from /Users/lion/Desktop/Developer/AwesomeProject/NewTrackActivity.js
Unable to resolve module image!ic_action_android_back_white3 from /Users/lion/Desktop/Developer/AwesomeProject/NewTrackActivity.js

如果我在 Genymotion 中强行打开我的应用程序,它找不到我的图像。

Requiring unknown module image!ic_action_android_back_white3

我尝试将图像移动到 ./android/app/src/main/res/drawable-xxx./assets/drawable-xxx 但都不起作用。

重启你的反应打包器。这对我有用。

您是否尝试过挂载图像,就像新的资产管理器允许您做的那样? documentation.

中对此进行了描述

为图像组件使用以下属性。选择正确的相对路径并且不要忘记扩展名

<Image source={require('./my-icon.png')} />

我认为这是在初始构建后添加资产的问题。

我关闭了模拟器和捆绑器,清除了缓存和 运行 RN - run-ios/run-andriod - 然后就没问题了。

我也想知道 运行 link 是否可行,但没有测试这个。

有时,您的图像可能包含 @2x@3x 用于不同的屏幕 dpi,如 docs 中所述。在这种情况下,路径应指定没有 @2x@3x 后缀的图像名称。例如,如果图像文件名为 img@2x.png:

<Image source={require('./img.png')} />

您可以将图像保存在该文件夹中,而不是保存在资产文件夹中,并将路径指定为:

<Image source={require('../download.png')} />

对我有用

我收到了相同的错误消息 无法解析包含 大写字符 的文件的模块

我的解决方案 - 将文件名重命名为小写

在代码中使用:

<Image source={require('../download.png')} />

版本:
原生反应 - 0.62
世博会 - 38