简体   繁体   English

错误:无法使用哈希字符串'android-21'找到目标

[英]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? 我想将我的compileSdkVersion从23更改为21.因此我在build.gradle中进行了以下更改,但是我收到了以下错误。如何解决此问题?

failed to find target with hash string 'android-21' 无法使用哈希字符串'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')
    }

You are using 您正在使用

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

So you have to compile with API 23. 所以你必须使用API​​ 23进行编译。
Change your compileSdkVersion in your build.gradle file 更改compileSdkVersion在你build.gradle文件

 compileSdkVersion 23

Below is for Android studio 1. Go to app -> build.gradle -> change "compileSdkVersion 'installed sdk version'" 以下是针对Android studio 1.转到app - > build.gradle - >更改“compileSdkVersion'已安装的sdk版本'”

  1. Go to Tools -> Android -> sync project with gradle files 转到工具 - > Android - >使用gradle文件同步项目

That's it, problem solved:-) 就是这样,问题解决了:-)

Note: I think this might be a bug in Android Studio. 注意:我认为这可能是Android Studio中的错误。


  1. Go to Project Structure 转到项目结构
  2. Select App Module 选择App Module
  3. Under the first tab "Properties" change the Compile SDK Version to API XX from Google API xx (eg API 23 instead of Google API 23) 在第一个“属性”选项卡下,将Compile SDK版本从Google API xx更改为API XX(例如,API 23而不是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. 现在将Compiled Sdk Version还原为Google API xx。

If this not work, then: 如果这不起作用,那么:

  1. With Google API (Google API xx instead of API xx), lower the build tool version (eg Google API 23 and build tool version 23.0.1) 使用Google API(Google API xx而不是API xx),降低构建工具版本(例如Google API 23和构建工具版本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: 转到Android SDK目录并正确安装:

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. 所以我决定根据我的系统在Gradle文件中更改一些。

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主页环境变量,它应该是:path /../ path / sdk而不是:path /.../ path / sdk / tools例子:android主路径是:/ home / username / android / sdk你应该将以下行放在用户主目录中的.bashrc文件中:

 ANDROID_HOME='/home/username/android/sdk'
 PATH="$HOME:$HOME/bin:$ANDROID_HOME/tools:$PATH"
 export ANDROID_HOME
 export PATH

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM