1.初始化,在Android terminal中键入:
npm init
2:安装相关mudule
npm install react react-native
可以看到工程根目录下多了个node_modules目录,同时package.json中添加了配置信息
可以在package.json中的scripts添加启动脚本:
"start": "node node_modules/react-native/local-cli/cli.js start",
3.在根目录的build.gradle下添加maven库的地址
4.在lib_rn/build.gradle下添加依赖库(直接和package.json中react-native版本统一)
api 'com.facebook.react:react-native:0.57.4'
5.创建RN容器
6.添加权限:
7.启动服务:使用npm start 或者 react-native start
npm start
8.服务启动后 ,运行app
mac下command+m 可以使用调试工具(前提进入js页面):
备注:0.57.4版本,如果有相关包不存在,可使用npm安装,比如npm install @babel/core,最终下不了的话,可以降级react-native版本,亲测0.56.0稳定.
相关资料:
react-native中文官网: https://reactnative.cn/
react-native官网:http://facebook.github.io/react-native/docs/getting-started.html
demo地址:https://github.com/RightOfHand/RNDemo.git
android原生与react-native通信可参考:https://blog.csdn.net/qq_23575795/article/details/81298142