Getting Error “Gradle DSL method not found: 'compile()'” when Syncing Build.Gradle

后端 未结 10 814
后悔当初
后悔当初 2020-11-30 09:42

\"Error\"project

相关标签:
10条回答
  • 2020-11-30 10:24

    Make sure you have a settings.gradle file in your project. Adding that solved the problem of Error:Gradle DSL method not found: 'minSdkVersion()' for me.

    0 讨论(0)
  • 2020-11-30 10:25

    Deleting .gradle in my project folder did the job for me.

    0 讨论(0)
  • 2020-11-30 10:29

    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.

    0 讨论(0)
  • 2020-11-30 10:29

    I have the same issue, and the bug is my build.gradle of application level has dependencies of my submodules. Means

    dependencies {
       compile project(':library')
      compile project(':MPChartLib')
    }
    

    I have just remove the two line inside the dependencies braces and it is able to start syncing.

    0 讨论(0)
  • 2020-11-30 10:31

    I have found that when I add an applicationSuffix or versionNameSuffix through the IDE menu (Build > Edit Build Types), it changes the dependencies section of my app build.gradle from this:

    dependencies {
        compile fileTree(include: ['*.jar'], dir: 'libs')
        testCompile 'junit:junit:4.12'
        testCompile 'org.json:json:20140107'
    
        compile "com.android.support:appcompat-v7:${supportLibVersion}" 
        compile "com.android.support:design:${supportLibVersion}" 
        compile "com.android.support:support-vector-drawable:${supportLibVersion}" // VectorDrawableCompat
        compile "com.android.support:animated-vector-drawable:${supportLibVersion}" // AnimatedVectorDrawableCompat
    }
    

    to this:

    dependencies {
        compile fileTree(include: ['*.jar'], dir: 'libs')
        testCompile 'junit:junit:4.12'
        testCompile 'org.json:json:20140107'
        compile "com.android.support:appcompat-v7:${supportLibVersion}" compile "com.android.support:design:${supportLibVersion}" compile "com.android.support:support-vector-drawable:${supportLibVersion}"
        // VectorDrawableCompat
        compile "com.android.support:animated-vector-drawable:${supportLibVersion}"
        // AnimatedVectorDrawableCompat
    }
    

    I don't know why, but it combines the first three "compile" lines into one line, and moves the two comments (to the next line in each case).

    I solved the problem by editing the app build.gradle and putting each "compile" statement onto its own line.

    0 讨论(0)
  • 2020-11-30 10:32

    You have 2 different build.gradle (sometimes more depending on you)

    Only one of them is your app's gradle, then the other one is project's gradle.

    If you put your dependencies project's gradle you can get error : Gradle DSL method not found: 'compile()'

    Put your dependencies in app's build.gradle then it will work.

    0 讨论(0)
提交回复
热议问题