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不怎麼流暢, 使用每天模擬器後感受不錯)

相關文章
相關標籤/搜索