最近在折騰react-native,首先當然是安裝環境,在輸入run-native run-android命令后出現大量錯誤,最后聽取季哥的建議,通過利用AndroidStudio的方式來運行,在導入后運行,一開始是出現白色界面,什么都不顯示。
后來經過對SDK版本的修改,相關gradle版本的更新,出現如圖,顯示本地服務器沒有連接,打開
打開localhost:8081,,果然本地服務器沒有連接,如果連接了(會顯示一大段js代碼)
然后通過
npm start 打開本地服務器
然后通過Ctrl+ M,Reload,就可以看到運行的結果了(另外要注意index.android.js文件中的類名,文件名要一致,之前就因為這個沒注意,運行錯誤)
最終運行成功,如圖:
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
,