Mac android react native environment construction

1,jdk

2, android studio integrated development environment

3. Configure adb environment variables

 cd user home directory cd ~

Then if the .bash_profile file does not exist in the directory, create the file

$touch .bash_profile

open the folder

$open .bash_profile

 

JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_92.jdk/Contents/Home

export PATH=$JAVA_HOME/bin:$PATH

ANDROID_HOME=Library/Android/sdk

 

export PATH=$ANDROID_HOME/tools:$ANDROID_HOME/platform-tools:$PATH

 

save and exit, then execute

$source .bash_profile

test

$adb version

4. Install nodejs, https://nodejs.org/en/ installation package automatically installs nodejs and npm

  Detect node --version npm --version View version number

 

5, install react native

sudo npm install -g react-native-cli

-g means install globally

$open /usr/local/lib/node_modules    to see all packages installed globally by npm

6, Initialize the sample project

$react-native init AwesomeProject takes a while

 

7. Start the react-native service and run the test project

cd AwesomeProject

$react-native run-android

第一次运行可能会安装gradle,速度有点慢,要耐心,等等等。。。 PS:测试推荐使用真机,安卓虚拟机启动速度不想吐槽。。。 真机调试时,如果一打开一片红,“Unable to download JS bundle”,请摇晃手机,在弹出的选单里选择Dev Settings,选Debug server host for device,然后输入电脑的IP地址,此时手机要与电脑(编译环境)在同一Wifi环境下 

8,编辑代码

 打开index.android.js并修改部分代码,保存 摇动手机,点Reload JS,可以看到界面变化了(增加静态资源时,需要重新编译)

 

 

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326802600&siteId=291194637