react native android 踩坑記

運行環境

操作系統:macOS Sierra 10.12.1
jdk版本:1.8.0_101

項目運行報錯(react-native run-android)

根據網上教程,安裝了安卓運行環境,初始化項目執行react-native run-android

本以為一切會順利,結果報如下錯誤

Failed to notify ProjectEvaluationListener.afterEvaluate(), but primary configuration failure takes precedence.
java.lang.RuntimeException: SDK location not found. Define location with sdk.dir in the local.properties file or with an ANDROID_HOME environment variable.
.
.
.
.
.
* What went wrong:
A problem occurred evaluating project ':app'.
> SDK location not found. Define location with sdk.dir in the local.properties file or with an ANDROID_HOME environment variable.

* 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: 18.729 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
anderror1.jpeg
anderror2.jpeg

??但是經過仔細對照?官網和網上資料,發現我的環境并沒有問題,后來在 stackoverflow 上找到了 答案

具體做法是:在項目中 andorid?文件夾下新建一個名為local.properties 的文件
內容寫:

sdk.dir=?你的sdk的路徑

保存后重新運行項目就ok了。

最后編輯于
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。

推薦閱讀更多精彩內容