Java Android studio - 无法找到目标 android-18
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18068920/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Android studio - Failed to find target android-18
提问by RobertoAV96
I have a problem with Android Studio 0.2.3.
我有 Android Studio 0.2.3 的问题。
When I run my project the build stops and appears message that says:
当我运行我的项目时,构建会停止并显示以下消息:
Gradle: Execution failed for task ':AppName:compileDebugAidl'.
> failed to find target android-18
Gradle:任务“:AppName:compileDebugAidl”的执行失败。
> 未能找到目标 android-18
although I have installed the SDK platform of Android 4.3 (API 18) and I tried to reinstall all the SDK. I've also added the ANDROID_HOME
variable in the system variables.
虽然我已经安装了 Android 4.3 (API 18) 的 SDK 平台并且我尝试重新安装所有的 SDK。我还在ANDROID_HOME
系统变量中添加了变量。
What seems to be the source of this error?
这个错误的根源似乎是什么?
采纳答案by Calvin Li
I think you might not have the Android-18 sdk installed. Go to Tools > Android > SDK Manager and check to see if Android 4.3 (API 18) is installed.
我想你可能没有安装 Android-18 sdk。转到“工具”>“Android”>“SDK 管理器”并检查是否安装了 Android 4.3 (API 18)。
回答by RobertoAV96
I solved the problem by changing the compileSdkVersion
in the Gradle.buildfile from 18 to 17.
我通过改变解决了这个问题compileSdkVersion
在Gradle.build文件从18到17。
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.5.+'
}
}
apply plugin: 'android'
repositories {
mavenCentral()
}
android {
compileSdkVersion 17
buildToolsVersion "17.0.0"
defaultConfig {
minSdkVersion 10
targetSdkVersion 18
}
}
dependencies {
compile 'com.android.support:support-v4:13.0.+'
}
回答by dturvene
I had the same problem when trying out Android Studio. I already had projects running on the ADT under SDK 18. No need to hack the manifest files.
我在尝试 Android Studio 时遇到了同样的问题。我已经在 SDK 18 下的 ADT 上运行了项目。无需修改清单文件。
Fixed by:
修正者:
export ANDROID_HOME= pathtobundle/adt-bundle-linux-x86_64-20130729/sdk
导出 ANDROID_HOME= pathtobundle/adt-bundle-linux-x86_64-20130729/sdk
If you don't have the ADT installed, and just want the SDK, it seems like a good solution is to install everything and then point Android Studio to the just the packaged SDK.
如果您没有安装 ADT,而只想要 SDK,那么安装所有内容,然后将 Android Studio 指向刚刚打包的 SDK,这似乎是一个很好的解决方案。
cd pathtobundle
wget http://dl.google.com/android/adt/adt-bundle-linux-x86_64-20130729.zip
unzip *.zip
cd pathtobundle
wget http://dl.google.com/android/adt/adt-bundle-linux-x86_64-20130729.zip
解压 *.zip
As someone else said, you may need to run the SDK Manager to install the desired packages before running Studio.
正如其他人所说,在运行 Studio 之前,您可能需要运行 SDK Manager 来安装所需的包。
回答by Toni Menzel
Check the local.properties file in your Studio Project. Chances are that the property sdk.dir points to the wrong folder if you had set/configured a previous android sdk from pre-studio era. This was the solution in my case.
检查 Studio 项目中的 local.properties 文件。如果您从 pre-studio 时代设置/配置了以前的 android sdk,则属性 sdk.dir 可能指向错误的文件夹。这是我的情况的解决方案。
回答by Hoa Hoang
Thank you RobertoAV96.
谢谢罗伯托AV96。
You're my hero. But it's not enough. In my case, I changed both compileSdkVersion, and buildToolsVersion. Now it work. Hope this help
你是我的英雄。但这还不够。就我而言,我更改了 compileSdkVersion 和 buildToolsVersion。现在它工作了。希望这有帮助
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.6.+'
}
}
apply plugin: 'android'
dependencies {
compile fileTree(dir: 'libs', include: '*.jar')
}
android {
compileSdkVersion 19
buildToolsVersion "19"
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
resources.srcDirs = ['src']
aidl.srcDirs = ['src']
renderscript.srcDirs = ['src']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
}
// Move the tests to tests/java, tests/res, etc...
instrumentTest.setRoot('tests')
// Move the build types to build-types/<type>
// For instance, build-types/debug/java, build-types/debug/AndroidManifest.xml, ..
// This moves them out of them default location under src/<type>/... which would
// conflict with src/ being used by the main source set.
// Adding new build types or product flavors should be accompanied
// by a similar customization.
debug.setRoot('build-types/debug')
release.setRoot('build-types/release')
}
}
回答by Tommie C.
What worked for me in Android Studio (0.8.1):
在 Android Studio (0.8.1) 中对我有用的是什么:
- Right click on project name and open Module Settings
- Verify SDK Locations
- Verify Gradle and Plugin Versions (Review the error message hints
for the proper version to use)
- On the app Module set the Compile SDK Version to android-L (latest)
- Set the Build Tools version to largest available value (in my case
20.0.0)
- 右键单击项目名称并打开模块设置
- 验证 SDK 位置
- 验证 Gradle 和插件版本(查看要使用的正确版本的错误消息提示)
- 在 app 模块上将 Compile SDK Version 设置为 android-L (latest)
- 将构建工具版本设置为最大可用值(在我的情况下为 20.0.0)
These changes via the UI make the equivalent changes represented in other answers but is a better way to proceed because on close, all appropriate files (current and future) will be updated automatically (which is helpful when confronted by the many places where issues can occur).
这些通过 UI 进行的更改会进行其他答案中表示的等效更改,但这是一种更好的处理方式,因为关闭时,所有适当的文件(当前和未来)将自动更新(这在遇到许多可能发生问题的地方时很有帮助) )。
NB: It is very important to review the Event Log and note that Android Studio provides helpful messages on alternative ways to resolve such issues.
注意:查看事件日志非常重要,请注意 Android Studio 提供了有关解决此类问题的替代方法的有用消息。
回答by deltafalcon
I've had a similar problem occurr when I had both Eclipse, Android Studio and the standalone Android SDK installed (the problem lied where the AVD Manager couldn't find target images). I had been using Eclipse for Android development but have moved over to Android Studio, and quickly found that Android Studio couldn't find my previously created AVDs.
当我同时安装 Eclipse、Android Studio 和独立的 Android SDK 时,我遇到了类似的问题(问题在于 AVD 管理器找不到目标图像)。我一直在使用 Eclipse 进行 Android 开发,但后来转移到了 Android Studio,并且很快发现 Android Studio 找不到我之前创建的 AVD。
The problem could potentially lie in that Android Studio is looking at it's own Android SDK (found in C:\Users\username\AppData\Local\Android\android-studio\sdk) and not a previously installed standalone SDK, which I had installed at C:\adt\sdk.
问题可能在于 Android Studio 正在查看它自己的 Android SDK(在 C:\Users\username\AppData\Local\Android\android-studio\sdk 中找到)而不是我之前安装的独立 SDK在 C:\adt\sdk。
Renaming Android Studio's SDK folder, in C:\Users... (only rename it, just in case things break) then creating a symbolic link between the Android Studio SDK location and a standalone Android SDK fixes this issue.
在 C:\Users... 中重命名 Android Studio 的 SDK 文件夹(仅重命名它,以防万一),然后在 Android Studio SDK 位置和独立 Android SDK 之间创建符号链接可解决此问题。
I also used the Link Shell Extension (http://schinagl.priv.at/nt/hardlinkshellext/linkshellextension.html) just to take the tedium out of creating symbolic links.
我还使用了链接外壳扩展 ( http://schinagl.priv.at/nt/hardlinkshellext/linkshellextension.html) 只是为了消除创建符号链接的乏味。
回答by prayagupd
STEP 1) Start Android SDK Manager
步骤 1) 启动 Android SDK 管理器
With android
command something as below,
使用android
如下命令,
$ /usr/local/android-studio/sdk/tools/android
STEP 2) Find API 18
步骤 2) 查找 API 18
STEP 3) Select Android 4.3 (API 18 ) and install packages.
步骤 3) 选择 Android 4.3 (API 18) 并安装软件包。
回答by nmr
This will also happen if you have written compileSdkVersion = 22
e.g. (as used in the "new new" Android build system) instead of compileSdkVersion 22
.
如果您编写了compileSdkVersion = 22
eg(如在“新的”Android 构建系统中使用的那样)而不是compileSdkVersion 22
.
回答by Gaurav Setia
You can solve the problem changing the compileSdkVersion in the Grandle.build file from 18 to wtever SDK is installed ..... BUTTTTT
您可以解决将Grandle.build 文件中的compileSdkVersion 从18 更改为wtever SDK is installed ..... BUTTTTT 的问题
If you are trying to goin back in SDK versions like 18 to 17 ,You can not use the feature available in 18 or 18+
If you are migrating your project (Eclipse to Android Studio ) Then off course you Don't have build.gradle file in your Existed Eclipse project
如果您尝试返回 18 到 17 之类的 SDK 版本,则无法使用 18 或 18+ 中可用的功能
如果您正在迁移您的项目(Eclipse 到 Android Studio),那么当然您的现有 Eclipse 项目中没有 build.gradle 文件
So, the only solution is to ensure the SDK version installed or not, you are targeting to , If not then install.
因此,唯一的解决方案是确保是否安装了 SDK 版本,您的目标是 ,如果没有则安装。
Error:Cause: failed to find target with hash string 'android-19' in: C:\Users\setia\AppData\Local\Android\sdk
错误:原因:无法在以下位置找到带有哈希字符串“android-19”的目标:C:\Users\setia\AppData\Local\Android\sdk