React Native 搭建Android开发环境踩坑

Posted by fengmiaosen on 2016-11-18

心血来潮想体验下React Native,于是就按照官方教程React Native中文教程搭建完Android开发环境,使用官方脚手架工具新建了一个测试demo。

1
2
3
react-native init AwesomeProject
cd AwesomeProject
react-native run-android

结果运行报错

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:installDebug'.
> com.android.builder.testing.api.DeviceException: No connected devices!
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
BUILD FAILED
Total time: 12.603 secs
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.
Go to https://facebook.github.io/react-native/docs/getting-started.html
and check the Android tab for setup instructions.

以上错误信息中关键部分

1
2
Execution failed for task ':app:installDebug'.
> com.android.builder.testing.api.DeviceException: No connected devices!
  • 大概意思是 没有连接到设备,此时需要我们启动一个安卓虚拟设备(AVD),具体步骤如下:
  1. 启动Android Studio —— Tools —— Android —— AVD Manager

avd

  1. 选中已有的Virtual Device 或者 Create Virtual Device,然后点击右侧Actions下的启动按钮启动虚拟设备。

  2. 如果没有步骤2中默认创建好的Virtual Device,就需要Create Virtual Device
    hardware

  3. 再在官方的测试demo中运行react-native run-android就可以启动调试。

参考资料