react-native本地服務(wù)器未連接的問題

最近在折騰react-native,首先當(dāng)然是安裝環(huán)境,在輸入run-native run-android命令后出現(xiàn)大量錯(cuò)誤,最后聽取季哥的建議,通過利用AndroidStudio的方式來運(yùn)行,在導(dǎo)入后運(yùn)行,一開始是出現(xiàn)白色界面,什么都不顯示。

后來經(jīng)過對(duì)SDK版本的修改,相關(guān)gradle版本的更新,出現(xiàn)如圖,顯示本地服務(wù)器沒有連接,打開


打開localhost:8081,,果然本地服務(wù)器沒有連接,如果連接了(會(huì)顯示一大段js代碼)

然后通過

npm start 打開本地服務(wù)器

然后通過Ctrl+ M,Reload,就可以看到運(yùn)行的結(jié)果了(另外要注意index.android.js文件中的類名,文件名要一致,之前就因?yàn)檫@個(gè)沒注意,運(yùn)行錯(cuò)誤)

最終運(yùn)行成功,如圖:


PS C:\Users\wong\MyProject> react-native run-android

JS server already running.

Running C:\Users\wong\AppData\Local\Android\sdk;/platform-tools/adb -s emul

ator-5554 reverse tcp:8081 tcp:8081

Could not run adb reverse: spawnSync C:\Users\wong\AppData\Local\Android\sd

k;/platform-tools/adb ENOENT

Building and installing the app on the device (cd android && gradlew.bat install

Debug)...

FAILURE: Build failed with an exception.

* What went wrong:

A problem occurred configuring project ':app'.

> The SDK directory 'C:\Users\wong\AppData\Local\Android\sdk;' does not exi

st.

* 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: 4.875 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:

https://facebook.github.io/react-native/docs/android-setup.html


最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

推薦閱讀更多精彩內(nèi)容