安装git for windows
在这里下载安装,安装过程中注意选择"Run Git from Windows Command Prompt"。
安装Python
从官网下载并安装python 2.7.x(3.x版本不行)
安装node.js
从官网下载node.js的官方5.x版本或更高版本。
建议设置npm镜像以加速后面的过程(或使用科学上网工具)。
npm configsetregistry https://registry.npm.taobao.org --global
npm configsetdisturl https://npm.taobao.org/dist --global
安装react-native命令行工具
npm install -g react-native-cli
创建项目
进入你的工作目录,运行
react-native init AwesomeProject(自己创建的文件名)
在react-native配置中有一段代码AppRegistry.registerComponent('AwesomeProject', () => AwesomeProject);
需要注意的一点就是代码中单引号内的内容是我们init项目的时候的项目名称,() =>后边的是我们自己定义的组件名称,别弄混了!
npm start
react-native start
react-native run-android
adb reverse tcp:8081 tcp:8081命令
AndroidStudio 运行报错
一、java.lang.RuntimeException: Unable to load script from assets 'index.android.bundle'. Make sure your bundle is packaged correctly or you're running a packager server.
1- Create a new folder => android/app/src/main/assets
2- Run this command =>
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
This command will create 2 files : index.android.bundle & index.android.bundle.meta
3- run command => react-native run-android
网友评论