2018年7月1日 星期日

[React Native]看著文件跌跌撞撞-Getting Started


1.裝好Node.js
2.裝好Android Studio
3.設置環境變數(讓到處都可以用adb這個指令)
加入C:\Users\使用者\AppData\Local\Android\Sdk\platform-tools這個路徑

4.Android Studio模擬器測試
5.至Android Studio的Tools的AVD Manager
6.Create Virtual Device
7.支援度較高的手機型號:Nexus_4_API_27
8.按下綠色三角形啟動模擬器
9.加入全域的React Native工具
npm install -g create-react-native-app

10.進入你的開發資料夾,開始建構專案啦
create-react-native-app 你要的資料夾

cd 你要的資料夾
yarn start

15:44:18: Starting packager...
Packager started!

Your app is now running at URL: exp://192.168.0.20:19000

View your app with live reloading:

  Android device:
    -> Point the Expo app to the QR code above.
       (You'll find the QR scanner on the Projects tab of the app.)
  iOS device:
    -> Press s to email/text the app URL to your phone.
  Emulator:
    -> Press a to start an Android emulator.

Your phone will need to be on the same local network as this computer.
For links to install the Expo app, please visit https://expo.io.

Logs from serving your app will appear here. Press Ctrl+C at any time to stop.

 › Press a to open Android device or emulator.
 › Press s to send the app URL to your phone number or email address
 › Press q to display QR code.
 › Press r to restart packager, or R to restart packager and clear cache.
 › Press d to toggle development mode. (current mode: development)

11.按下a可以讓你看到更新的app狀態


12.若要有打包成app的功能,是另一個指令
react-native init 你的app名稱

13.打包
react-native run-android

14.噴錯誤
Starting JS server...
Building and installing the app on the device (cd android && gradlew.bat installDebug)...

FAILURE: Build failed with an exception.

* What went wrong:
A problem occurred configuring project ':app'.
> The SDK directory 'c:\Users\YOUR_USERNAME\AppData\Local\Android\Sdk' does not exist.

* 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: 28.512 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/getting-started.html

15.在路徑platforms\android底下加一個檔案叫local.properties,並放入以下內容
sdk.dir = C:/Users/使用者/AppData/Local/Android/Sdk //使用者記得要換成自己的

沒有留言:

張貼留言