简体   繁体   English

无法在 react native 中访问资产子文件夹中的资产文件

[英]cant access my asset file in asset sub folder in react native

i can access my icon if the folder in the root folder project,如果根文件夹项目中的文件夹,我可以访问我的图标

example:例子:

AwesomeProject v
  __test__ >
  android >
  icon >
  ios >

and i want to restructur my folder so i create new folder called src then i create sub folder called assets then put my icon there我想重组我的文件夹,所以我创建了一个名为src的新文件夹,然后我创建了一个名为assets的子文件夹,然后把我的图标放在那里

example:例子:

AwesomeProject v
  __test__ >
  android >
  ios >
  src v
    assets v
      icon >

this is my code in App.js file这是我在 App.js 文件中的代码

<Image style={{ width: 26, height: 26 }} source={require('./src/assets/icon/home-active.png')} />

error message: none of these file exist错误信息:这些文件都不存在

*note: i have double checked to make sure im not typo *注意:我已经仔细检查以确保我没有错字

you have to link your files so that they are added to the respective ios / android folders您必须链接您的文件,以便将它们添加到相应的 ios / android 文件夹中

structure:结构体:

AwesomeProject v
  __test__ >
  android >
  icon >
  ios >

Crete react-native.config.js file on root of your project项目根目录上的克里特react-native.config.js文件

  module.exports = {
    project: {
      ios: {},
      android: {},
    },
    assets: [
      './assets/icons/'
    ]
  }

now you will have to link the files现在您必须链接文件

yarn react-native link

or或者

npx react-native link

now you can check if the icons have been added to the folders of your ios / android application现在您可以检查图标是否已添加到您的 ios / android 应用程序的文件夹中

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM