ReactNative Could not install the app on the device

我们从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.

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

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:

export ANDROID_HOME=~/Library/Android/sdk

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:

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不怎么流畅, 使用天天模拟器后感觉不错)

转载于:https://my.oschina.net/u/2542649/blog/840397

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值