我们从github下载的ReactNative(以下简称RN)经常会出现这个错误:
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:
https://facebook.github.io/react-native/docs/android-setup.html
导致构建失败BUILD FAILED.
看到上述的命令行提示,发现他的意思是我们的安卓环境可能配置的不对,还让我们去官网看看,那好吧,咱们到官网一看,有个步骤是这样的
Set up paths
The React Native command line interface requires the ANDROID_HOME
environment variable to be set up. You can configure it in a Terminal using the following command:
export ANDROID_HOME=~/Library/Android/sdk
export ANDROID_HOME=~/Library/Android/sdkexport PATH=${PATH}:${ANDROID_HOME}/tools
To avoid doing this every time you open a new Terminal, create (or edit) ~/.bashrc
using your favorite text editor and add the following lines:
The second line will add the android
tool to your path, which will come in handy in the next step.
Please make sure you export the correct path for
ANDROID_HOME
if you did not install the Android SDK using Android Studio. If you install the Android SDK using Homebrew, it will be located at/usr/local/opt/android-sdk
.
这个是环境相关的配置,咱们只需要这样在命令行中输入:export ANDORD_HOME = 我们的android sdk 路径(一个细节后面记得加上 sdk,这个目录才是sdk的位置,否则还是会报错,我就是忘记加这个了)
然后上面设置完成后设置到环境变量PATH中即可
export PATH = ${PATH}:${ANDROID_HOME}/tools
上述配置完成后,react-native run-android 继续运行,这个时候他会构建运行该项目的必需project,我们等待即可,这个时候如果gradle 是1.3.1,命令行中可能会出现以下错误:
com.android.ddmlib.InstallException: Unable to upload some APKs
需要将project的gradle version修改到1.2.3,可能这个版本命令行启动不了
http://blog.csdn.net/shenshibaoma/article/details/52936349 可以看下我这篇博客的介绍,有说到这个错误。