Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error: failed to find target with hash string 'android-21'

I want to change my compileSdkVersion from 23 to 21.So I have made following changes in the build.gradle but I am getting following error.How can I resolve this?

failed to find target with hash string 'android-21'

 apply plugin: 'com.android.application'

    android {
        compileSdkVersion 21
        buildToolsVersion "21.1.2"

        defaultConfig {
            applicationId "com.example.shalabh.fly"
            minSdkVersion 14
            targetSdkVersion 21
            versionCode 1
            versionName "1.0"
        }
        buildTypes {
            release {
                minifyEnabled false
                proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            }
        }
    }

    dependencies {
        compile fileTree(include: ['*.jar'], dir: 'libs')
        compile 'com.android.support:appcompat-v7:23.0.1'
        compile files('libs/httpclient-4.1-beta1.jar')
    }
like image 668
user317461 Avatar asked Oct 25 '15 14:10

user317461


4 Answers

Go to you Android SDK dir and install it properly:

tools/android update sdk

or

tools/android update sdk --no-ui
like image 82
KrisWebDev Avatar answered Sep 28 '22 11:09

KrisWebDev


You are using

 compile 'com.android.support:appcompat-v7:23.0.1'

So you have to compile with API 23.
Change your compileSdkVersion in your build.gradle file

 compileSdkVersion 23
like image 3
Gabriele Mariotti Avatar answered Oct 17 '22 11:10

Gabriele Mariotti


Below is for Android studio 1. Go to app -> build.gradle -> change "compileSdkVersion 'installed sdk version'"

  1. Go to Tools -> Android -> sync project with gradle files

That's it, problem solved:-)

like image 3
Selva Avatar answered Oct 17 '22 11:10

Selva


Note: I think this might be a bug in Android Studio.


  1. Go to Project Structure
  2. Select App Module
  3. Under the first tab "Properties" change the Compile SDK Version to API XX from Google API xx (e.g. API 23 instead of Google API 23)
  4. Press OK
  5. Wait for the completion of on going process, in my case I did not get an error at this point.
  6. Now revert Compiled Sdk Version back to Google API xx.

If this not work, then:

  1. With Google API (Google API xx instead of API xx), lower the build tool version (e.g. Google API 23 and build tool version 23.0.1)
  2. Press Ok and wait for completion of on going process
  3. Revert back your build tool version to what it was before you changed
  4. Press Ok and Wait for the completion of process.
  5. Done!
like image 2
Sagar Patel Avatar answered Oct 17 '22 11:10

Sagar Patel