96

I have a problem with 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

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.

What seems to be the source of this error?

RobertoAV96
  • 5,843
  • 4
  • 16
  • 13

12 Answers12

120

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.

Calvin Li
  • 2,614
  • 3
  • 17
  • 25
  • 10
    In fact, when I had the problem, the Android-18 sdk was installed, but I think Android Studio didn't detect it. I've resolved by uninstalling and reinstalling SDK and Studio. – RobertoAV96 Sep 29 '13 at 11:04
  • 3
    When I received a similar error, just restarting Android Studio was sufficient rather than a complete reinstall. – Code-Apprentice Feb 10 '16 at 20:01
  • 1
    Restarting the mac was the only thing that let IntelliJ see the newly installed SDKs for me. – codeulike Feb 11 '16 at 15:51
50

I solved the problem by changing the compileSdkVersion in the Gradle.build file from 18 to 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.+'
}
iraj jelodari
  • 3,118
  • 3
  • 35
  • 45
RobertoAV96
  • 5,843
  • 4
  • 16
  • 13
  • good job. I think same would have been accomplished if you advanced your minimum target. In fact, it probly wouldnt run on a 2.3.3 – Dave Alperovich Aug 06 '13 at 16:49
  • 3
    This really isn't a solution to the problem especially if you are trying to use features available only in 18+ – Daniel Smith Aug 30 '13 at 16:30
  • How do you make it just use the latest SDK instead? I have a similar issue with this library: https://github.com/devunwired/custom-view-examples , and even though I've made similar steps, I get this error. – android developer Sep 21 '14 at 21:13
10

STEP 1) Start Android SDK Manager

With android command something as below,

$ /usr/local/android-studio/sdk/tools/android

STEP 2) Find API 18

enter image description here

STEP 3) Select Android 4.3 (API 18 ) and install packages.

prayagupa
  • 30,204
  • 14
  • 155
  • 192
5

What worked for me in Android Studio (0.8.1):

  1. Right click on project name and open Module Settings
  2. Verify SDK Locations SDK
  3. Verify Gradle and Plugin Versions (Review the error message hints for the proper version to use) Gradke
  4. On the app Module set the Compile SDK Version to android-L (latest)
  5. Set the Build Tools version to largest available value (in my case 20.0.0) Build

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).

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.

Tommie C.
  • 12,895
  • 5
  • 82
  • 100
3

Thank you RobertoAV96.

You're my hero. But it's not enough. In my case, I changed both compileSdkVersion, and buildToolsVersion. Now it work. Hope this help

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')
       }
   }
Hoa Hoang
  • 1,212
  • 14
  • 20
2

If you had the problem, opened SDK manager, installed the requested updates, returned to Android Studio and had the problem again, IT IS RECOMMENDED TO RESTART ANDROID STUDIO befor trying anything else.

Gradle will run automatically and chances are that your problem will be over. You will very possibly be told install the appropriate SDK TOOLS package, which is found in your SDK MANAGER under the second tab (sdk's are not the same as sdk tools, they are complementary packages).

You don't even need to hunt the tools package, if you click on the link under the error message, Android Studio should call SDK Manager to install the package automatically.

Restart Android Studio again and you should be up and running much faster than if you attempted workarounds.

RULE OF THUMB> restart your application before messing with options and configurations.

tony gil
  • 9,424
  • 6
  • 76
  • 100
1

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.

Toni Menzel
  • 764
  • 3
  • 10
0

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.

Fixed by:

export 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.

cd pathtobundle

wget http://dl.google.com/android/adt/adt-bundle-linux-x86_64-20130729.zip

unzip *.zip

As someone else said, you may need to run the SDK Manager to install the desired packages before running Studio.

Community
  • 1
  • 1
dturvene
  • 2,284
  • 1
  • 20
  • 18
0

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.

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.

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.

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.

0

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.

nmr
  • 16,625
  • 10
  • 53
  • 67
0

You can solve the problem changing the compileSdkVersion in the Grandle.build file from 18 to wtever SDK is installed ..... BUTTTTT

  1. 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+

  2. 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

So, the only solution is to ensure the SDK version installed or not, you are targeting to , If not then install.

Error:Cause: failed to find target with hash string 'android-19' in: C:\Users\setia\AppData\Local\Android\sdk

Gaurav Setia
  • 274
  • 3
  • 7
0

Target with hash string 'android-18' is corresponding to the SDK level 18. You need to install SDK 18 from SDK manager.

Shreyas
  • 1
  • 1