如何在Android中调试“构建失败,出现异常/找不到SDK位置”?

时间:2018-12-06 05:16:14

标签: android visual-studio android-studio react-native

我是React-Native的新手。我在某些论坛上尝试了几种解决方案,但没有帮助。出现错误。

   Microsoft Windows [Version 10.0.17134.407]
(c) 2018 Microsoft Corporation. All rights reserved.

C:\xampp\htdocs\Hands-on React-Native\TripPlane>react-native run-android
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'.
> 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. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 19s
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

1 个答案:

答案 0 :(得分:0)

您需要正确设置ReactNative。

我认为已经安装了android studio,并且已经连接了模拟器或android设备

执行以下步骤!

1] official site

安装JDK

2] official site

安装NodeJ

3] 安装Python 2表单official site

4] 安装ReactNative CLI,打开CMD [右键单击并以管理员身份运行]

  • 键入C:\WINDOWS\system32>node -v //以获取节点版本

  • 键入C:\WINDOWS\system32>npm install -g react-native-cli //以安装RN CLI

5] 创建RN项目的工作区 -D:\ReactNative>react-native init projectname //它将在提到的路径内生成项目。

6] 设置环境变量

  • 在用户变量(如果不存在)JAVA_HOME下设置新变量,其值为 C:\Program Files\Java\jdk-10.0.2(您的JDK路径)

  • 在用户变量(如果不存在)Path下设置新变量,其值为 C:\Users\Admin\AppData\Local\Android\sdk\platform-tools //您的SDK平台工具路径

7] 使用CMD中的以下命令运行项目 D:\ReactNative>react-native run android