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

限于喜欢 提交于 2019-12-03 11:11:07

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

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

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!

Go to you Android SDK dir and install it properly:

tools/android update sdk

or

tools/android update sdk --no-ui

This error I also getting again and again when I import other's project. So I resolve to change some in Gradle file according to my system.

compileSdkVersion 23
buildToolsVersion "23.0.2"

Which I have already installed in my system.

Just check android home environment variable, it should be : path/../path/sdk and not : path/.../path/sdk/tools example: android home path is : /home/username/android/sdk you should put the following lines to .bashrc file in user home directory:

 ANDROID_HOME='/home/username/android/sdk'
 PATH="$HOME:$HOME/bin:$ANDROID_HOME/tools:$PATH"
 export ANDROID_HOME
 export PATH
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!