React-Native android 初体验

Windows
1 安装 npm
https://nodejs.org/en/download/
这里写图片描述
公司电脑 安装的5.6 版本 测试不通过 (可能是网的原因) 不过自己电脑之前安装的 版本3.10.10 (在家测试 可以)

2 在线安装 react-Native
npm install -g react-native-cli

3 安装 android studio
https://blog.csdn.net/a136447572/article/details/74452153

4创建项目 react-native init FirstApp
/** 注 1安装前需要更换国内淘宝镜像
C:\Program Files\nodejs\node_modules\npm\npmrc 文件中 最后添加
registry = https://registry.npm.taobao.org
**/
/** 注 2安装前可选择项目安装的目录
类似 D:react-native init FirstApp
**/

5 安装完之后 可通过 react-native run-android 运行程序

可能出现问题
unable to load script from asset/index.android.bundle问题解决
解决:1.去(你的项目文件夹)\android\app\src\main目录下新建asset文件夹

     2.终端下运行

     react-native bundle –platform android –dev false –entry-file index.android.js –bundle-output android/app/src/main/assets/index.android.bundle –assets-dest android/app/src/main/res

     3.再次执行 react-native run-android
      注:由于0.49版本以后的react-native没有index.android.js和index.ios.js文件,而统一合并成了index.js,所以使用0.49及以后版本的同学请将第2步中的入口文件改为index.js

修改后 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

6 打开android studio 导入项目 并运行 或 react-native run-android 运行程序

猜你喜欢

转载自blog.csdn.net/a136447572/article/details/80275512