未找到 SDK 位置 Android Studio + Gradle [英] SDK Location not found Android Studio + Gradle

查看:35
本文介绍了未找到 SDK 位置 Android Studio + Gradle的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经多次看到同样的内容发布,但每当我尝试将我的项目导入我的新工作笔记本电脑时,我总是收到此错误.

I have seen this same thing posted quite a few times, but whenever I try to import my project to my new work laptop I keep getting this error.

我已经从 git 中提取了该项目(顺便说一句,他在我的旧笔记本电脑上运行良好).

I have pulled the project from git (which his btw running fine on my old laptop).

然后我去了 sdk 管理器,下载了所有工具,以及所有可用的 SDK.在欢迎屏幕中,我转到配置 -> 项目默认值 -> 项目结构.Android SDK Tab 表示没有 local.properties 的项目的路径将是/Applications/Android Studio.app/sdk这是对的.在 SDK 下,我可以看到所有可用的 SDK.项目 SDK 设置为 API 18

Then I went to the sdk manager, downloaded all the tools, and all the SDK's available. In the welcome screen, I went to Configure -> project Defaults -> Project structure. Android SDK Tab says the path for projects without local.properties will be /Applications/Android Studio.app/sdk This is correct. Under SDKs I have all the available SDK's visible. Project SDK is set to API 18

然而,我在尝试构建我的项目时仍然遇到此错误.谁能告诉我我还没有看过哪里?

Yet still I get this error when trying to build my project. Can anyone tell me where I havent looked yet?

在尝试构建从 services.gradle.org 下载的版本时,我正在运行 gradle 1.7

I am running gradle 1.7 when trying to build which is downloaded from services.gradle.org

推荐答案

我遇到了非常相似的情况(在另一台机器上有一个项目并将其克隆到我的笔记本电脑并看到同样的问题),我查看了它.

I had very similar situation (had a project on another machine and cloned it to my laptop and saw the same issue) and I looked in it.

错误消息来自 Android gradle 插件的 Sdk.groovy:https://android.googlesource.com/platform/tools/build/+/master/gradle/src/main/groovy/com/android/build/gradle/internal/Sdk.groovy

Error message was coming from Sdk.groovy of Android gradle plugin: https://android.googlesource.com/platform/tools/build/+/master/gradle/src/main/groovy/com/android/build/gradle/internal/Sdk.groovy

看代码,它的findLocation需要设置androidSdkDir变量,只有三种方法:

By looking at code, its findLocation needs to set androidSdkDir variable and there are only three ways to do it:

  • 创建local.properties 文件并有sdk.dirandroid.dir 行.
  • 定义了 ANDROID_HOME 环境变量.
  • System.getProperty("android.home") - 我不确定它是如何工作的,但它看起来像是 Java 的东西.
  • create local.properties file and have either sdk.dir or android.dir line.
  • have ANDROID_HOME environment variable defined.
  • System.getProperty("android.home") - I'm not sure how it works, but it seems like a Java thing.

虽然您的 Android Studio 知道 SDK 在那个位置,但我怀疑 Android Studio 是否正在将该信息传递给 gradle,因此我们看到了该错误.

While your Android Studio knows that the SDK is at that place, I doubt that Android Studio is passing that information to gradle and thus we're seeing that error.

我在项目根目录下创建了 local.properties 文件并添加了以下行并成功编译代码.

I created local.properties file at the project root and put the following line and it compiled the code successfully.

<代码>sdk.dir =/Applications/Android Studio.app/sdk/

这篇关于未找到 SDK 位置 Android Studio + Gradle的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆