原文连接:http://www.studyshare.cn/blog/details/1137/1
最近做一个app,使用React Native实现,如果严格按照RN官方文档去配置环境并初始化一个全新的项目,一路走下来,基本上是没有问题的。RN截止目前最新版本是0.58,如果之前的项目要在xcode和android studio上运行起来,可能会遇到各种各样的问题。
更多深度技术文章,在这里。 java开发工具下载地址及安装教程大全,点这里。
运行一些版本比较老的开源项目几个注意点:
1、android sdk 环境变量要配置好,具体参考RN官方文档,有一个中文文档(https://reactnative.cn/docs/getting-started.html)
2、在xcode上运行运行不成功,可能是没有授权,执行命令:chmod -R 777 node_modules
3、在android上运行不成功,sdk环境变量没问题,则也需要授权:chmod 755 android/gradlew
4、如果是从github上clone下来的项目,检查此文件是否存在(/android/local.properties),将里面的路径改为自己的
注意:2、3、命令执行的路径是工程项目文件夹下(android、ios、App.js、index.js所在的文件夹)
常见错误:
1、Could not install the app on the device, read the error above for details.
Make sure you have an Android emulator running or a device connected and have
set up your Android development environment:
https://facebook.github.io/react-native/docs/getting-started.html
出现此错误按以上几步解决。
2、unable to load script from assets ‘index.android bundle’ ,make sure your bundle is packaged correctly or youu’re runing a packager server
在 android/app/src/main 目录下创建一个 assets空文件夹
(1)mkdir android/app/src/main/assets
在项目根目录运行
(2)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/
重新react-native run-android即可
原创文章,转载请注明出处。