Android studio - Failed to find target android-18

前端 未结 12 617
陌清茗
陌清茗 2020-11-29 00:22

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

相关标签:
12条回答
  • 2020-11-29 01:16

    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.

    0 讨论(0)
  • 2020-11-29 01:16

    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')
           }
       }
    
    0 讨论(0)
  • 2020-11-29 01:16

    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.

    0 讨论(0)
  • 2020-11-29 01:18

    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

    0 讨论(0)
  • 2020-11-29 01:20

    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.

    0 讨论(0)
  • 2020-11-29 01:20

    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.

    0 讨论(0)
提交回复
热议问题