ReactNative Could not install the app on the device

咱们从github下载的ReactNative(如下简称RN)常常会出现这个错误:html

 

Could not install the app on the device, read the error above for details.node

Make sure you have an Android emulator running or a device connected and havereact

set up your Android development environment:android

https://facebook.github.io/React-native/docs/android-setup.htmlgit

致使构建失败BUILD FAILED.github

看到上述的命令行提示,发现他的意思是咱们的安卓环境可能配置的不对,还让咱们去官网看看,那好吧,我们到官网一看,有个步骤是这样的,json

3. 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:react-native

export ANDROID_HOME=~/Library/Android/sdkbash

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:app

export ANDROID_HOME=~/Library/Android/sdkexport PATH=${PATH}:${ANDROID_HOME}/tools

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 能够看下我这篇博客的介绍,有说到这个错误。

 

 

搭建React Native开发环境遇到的几个问题

根据http://blog.csdn.net/itpinpai/article/details/50809068这篇文章初步搭建React Native 开发环境, 遇到几个问题

  • 首先端口可能被占用了, 访问8081时提示没法访问

解决方法: 在运行react-native start时添加参数--port 8899, 或者在package.json中修改"scripts"中参数, 添加端口号, 或者修改项目下的node_modules\react-native\local-cli\server\server.js下的方法_server的default 端口值

  • adb devices找不到链接设备

解决方法: 使用Genymotion时, 首先sdk中的 platform-tools 须要加入环境变量, 而后在Genymotion中,点击Setting,选择ADB选项卡,点击Use custom Android SDK tools,浏览本地SDK的位置,点击OK,就能够了,启动虚拟机后, 在cmd中输入adb devices能够查看.

  • 红屏问题"Could not get BatchedBridge, make sure your bundle is packaged correctly"

解决方法: 主要就只遇到这一个问题, 更改ip和port没有解决了, 后来在package.json中的"scripts"中添加"bundle-android":"react-native bundle --platform android --dev false --entry-file index.android.js --bundle-output android/app/src/main/assets/index.android.bundle --sourcemap-output android/app/src/main/assets/index.android.map --assets-dest android/app/src/main/res/",若是没有assets目录,手动添加下,不过运行时没有效果, 在cmd中手动执行下, assets目录中会多出几个文件, 便可解决这个问题

  • 如何使用每天模拟器调试Android程序

解决方法: 在cmd中打命令:adb connect 127.0.0.1:6555 其中6555是每天模拟器的端口. (感受Genymotion不怎么流畅, 使用每天模拟器后感受不错)