无法构建工具版android

时间:2015-07-17 22:27:13

标签: android-studio gradle android-gradle build.gradle

我试图在新安装的Android工作室(今天)打开我的旧项目,它给了我这个错误:

failed to find build tools revision 23.0.0 rc2
install build tools 23.0.0 rc2 and sync project

我在互联网上找了它,我试着在gradle文件中添加它:

android {
compileSdkVersion 22
buildToolsVersion "22.0.0"
}

它给了我另一个错误:

gradle DSL method not found: 'android()'
possible causes:
the project may be using a version of gradle that does not contain the method.
gradle settings.
the build file may be missing a gradle plugin.
apply gradle plugin.

这是我的gradle文件:

// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
    jcenter()
}
dependencies {
    classpath 'com.android.tools.build:gradle:1.2.3'
  }
}

allprojects {
repositories {
    jcenter()
  }
}
android {
compileSdkVersion 22
buildToolsVersion "22.0.0"
}

6 个答案:

答案 0 :(得分:3)

右键点击您的项目>打开模块设置>属性选项卡,然后更改:

Compile Sdk Verion to API 23: Android 6.0
Build Tools Version 23.0.0

enter image description here

答案 1 :(得分:2)

我检查了Android Studio中安装的构建工具版本,我有Android SDK Build-Tools rc3,而不是rc2。 我在build.gradle(模块应用程序)中将其更改为 android {     compileSdkVersion 22     buildToolsVersion" 23.0.0 rc3"} 之后它才有效。 检查您是否有同样的问题。

答案 2 :(得分:1)

在您的顶级build.gradle,您必须删除android

android {
   compileSdkVersion 22
   buildToolsVersion "22.0.0"
}

只需使用:

    // Top-level build file where you can add configuration options common to all sub-projects/modules.

    buildscript {
       repositories {
          jcenter()
       }
       dependencies {
          classpath 'com.android.tools.build:gradle:1.2.3'
       }
    }

    allprojects {
       repositories {
         jcenter()
       }
    }

您必须在android中使用app/build.gradle块,您应在其中定义以下内容:

apply plugin: 'com.android.application'

android {
    compileSdkVersion XX
    buildToolsVersion "XX.X.X"

    defaultConfig {
       minSdkVersion XX
       targetSdkVersion XX
       versionCode 1
       versionName "1.0"
    } 
    buildTypes {
      release {
         //......
      }
    }
}
dependencies {
  //......
}

答案 3 :(得分:0)

theres 2 gradle files

您必须修改的是此目录下的那个 APPLICATION NAME / APP / BUILD.GRADLE

apply plugin: 'com.android.application'

android {
    compileSdkVersion 22
    buildToolsVersion "PUT THE CODE YOU WANT HERE EX "23.0.0 r3""

    defaultConfig {
        applicationId "org.app.appname"
        minSdkVersion 10
        targetSdkVersion 22
        versionCode 9
        versionName "1.10.3"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile 'com.google.android.gms:play-services:7.5.0'
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:appcompat-v7:22.2.1'
    compile 'com.android.support:support-v4:22.2.1'
    compile files('libs/volley.jar')
}

不是看起来像这样的那个

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:1.3.0'

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        jcenter()
    }
}

答案 4 :(得分:0)

在我的情况下,我尝试了一切,最后我不得不做一个简单的改变

apply plugin: 'com.android.application'

android {
    compileSdkVersion 22
    buildToolsVersion "23.0.0 rc2"
}

到这个

apply plugin: 'com.android.application'

android {
    compileSdkVersion 22
    buildToolsVersion "23.0.0" //DELETE rc2 AND SYNC PROJECT 
}

答案 5 :(得分:0)

这取决于您安装的Android SDK Build-tools的哪个版本,您可以通过SDK Manager查看,在我的情况下我没有安装23.0.0 rc2但是23.0.1,所以你需要修改您的app/build.gradle

对我而言当时是:

android {
    compileSdkVersion 22
    buildToolsVersion "23.0.1"
}