Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
399 views
in Technique[技术] by (71.8m points)

android - Getting Error "Gradle DSL method not found: 'compile()'" when Syncing Build.Gradle

Error after resolutionproject is staymax2 build.gradle files that i am working onTo add V4 support libraries to android studio, i followed this document:https://developer.android.com/tools/support-library/setup.html#libs-without-res but I get an error. Here is what i did

  1. SDK manager> Installed Android Support Library and Android Repository.
  2. Go to Build.Gradle and added the line as given in the dcoument. Build.Gradle now looks like this:

// 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:0.13.2'

    // 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:18.0.+"
    }
}

}

Then, I get a popup that suggest that I sync gradle. When i sync Gradle, i get this error:

Error:(20, 0) Gradle DSL method not found: 'compile()' Possible causes:

The project 'staymax' may be using a version of Gradle that does not contain the method. Open Gradle wrapper fileThe build file may be missing a Gradle plugin. Apply Gradle plugin

Am i missing any step? Please suggest.

Build.Gradle(app)

apply plugin: 'com.android.application'

android {
compileSdkVersion 20
buildToolsVersion "20.0.0"

defaultConfig {
    applicationId "com.appt.shreyabisht.staymax"
    minSdkVersion 15
    targetSdkVersion 20
    versionCode 1
    versionName "1.0"
}
buildTypes {
    release {
        runProguard false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
 }
}

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
}
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

In almost all cases, your dependencies should be put into the individual module's build.gradle files rather than at the top most level build.gradle file. In your case, that means the dependency should be added to the app module's build.gradle file:

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile "com.android.support:support-v4:18.0.+"
}

And you should remove the entire allprojects part of the top level build.gradle.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...