window安装react-native

我这里把遇到的坑列出来

安装基础环境后,运行react-native init firstProject创建新的工程
cd firstProject/
react-native start
到这里都没问题,之后坑就来了

坑一:浏览器测试
错误:Cannot find entry file index.android.js in any of the roots

原因:新版本entry-file的index.android.js已经改为index.js,网上大部分安装教程都是使用http://localhost:8081/index.android.bundle?platform=android去测试
解决办法:
测试的时候使用 http://localhost:8081/index.bundle?platform=android


坑二:真机测试(需在同一个局域网内)
错误:enable to load script from assets 'index.android.bundle'
原因:android/app/src/main下确实assets文件夹及子文件
解决办法:在项目根路径运行命令 react-native bundle --platform android --dev false --entry-file index.js --bundle-output android/app/src/main/assets/index.android.bundle --assets-dest android/app/src/main/res/
(每次修改代码后,需要再运行一次该命令)
posted @ 2018-01-11 17:22  yklszm  阅读(210)  评论(0)    收藏  举报