错误:(22,0)未找到Gradle DSL方法:'compile()'

时间:2015-01-25 11:40:29

标签: android android-studio android-gradle

大家好我有问题Gradle DSL方法未找到:'compile()'。我读过的大多数讨论建议我将编译'com.android.support:support-v4:21.+'添加到个人的模块构建文件中,在我的例子中编译'com.android.support:support-v4:21。 +'已经存在了。如果我删除了我在最顶级构建文件中添加的那个,我会收到此错误(Error:Artifact 'support-v4.jar (com.android.support:support-v4:21.0.3)' not found. Android studio 1.0.2)。

请帮助,这是我的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.0.0'

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

    allprojects {
        repositories {
            jcenter()
        }
    }

dependencies {
    compile 'com.android.support:support-v4:21.+'
}

App文件夹下的Gradle文件:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 21
    buildToolsVersion "21.1.2"

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

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:appcompat-v7:21.0.3'
    compile 'com.android.support:support-v4:21.0.3'
}

谢谢。

1 个答案:

答案 0 :(得分:1)

从顶级build.gradle文件中删除依赖项块

dependencies {
    compile 'com.android.support:support-v4:21.+'
}

同时更新您的sdk文件。