1. 程式人生 > >React Native 真機執行調錯(Android 篇)

React Native 真機執行調錯(Android 篇)

跟著官方教程擼完一個電影列表的demo,就想配置到真機上看看效果,這裡列一些遇到的坑。

bug: SDK location not found.

具體的錯誤資訊:

Building and installing the app on the device (cd android && ./gradlew installDebug)...
Starting a Gradle Daemon (subsequent builds will be faster)

FAILURE: Build failed with an exception.

* What went wrong:
A problem occurred configuring project ':app'
. > SDK location not found. Define location with sdk.dir in the local.properties file or with an ANDROID_HOME environment variable.

解決方案

出錯的原因是沒有指定 SDK location

步驟:

  1. 切到你的 React Native 專案目錄下的 android/ 資料夾;
  2. 建立一個叫 local.properties 的檔案,新檔案裡敲上下面這行:
sdk.dir = /Users/USERNAME/Library/Android/sdk

USERNAME

是你的 OSX 使用者名稱!

bug: com.android.builder.testing.api.DeviceException

具體錯誤資訊:

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:installDebug'.
> com.android.builder.testing.api.DeviceException: com.android.ddmlib.InstallException

這個是手機在安裝app時,需要手動點選控制app的安裝,或者是沒有解除手機對安裝app來源的限制。