Skip to content Skip to sidebar Skip to footer

Getting Error "gradle Dsl Method Not Found: 'compile()'" When Syncing Build.gradle

To 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

Solution 1:

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.

Solution 2:

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.

Solution 3:

This worked for me:

  1. Exit Android Studio.
  2. Remove <home folder>/.gradle folder.
  3. Relaunch Android studio and let it load all gradle modules again.

P.S.: Mine was a fresh project so I removed the project as well and created a new one, so there were no old gradle references from the project

Solution 4:

In my case, there are 2 build.gradle file in my project (it auto create by android studio when create new project)

Just move the compile line to another one is solve my problem

Solution 5:

Hi everyone for me it was a "couple days consuming job" to make my app run in Android Studio . Finally I found that very simple way of it .

  1. Create libs folder under src/main/java/ it is App/java/libs in left pane .
  2. Copy and paste all your external jars into here.
  3. Goto left pane and right click on your App then click Open Module Settings
  4. Then Project Structure window will appear .
  5. Then move to Dependencies tab .
  6. Final Step : Add all your jars located in App/java/libs (You will find them in src/main/java/libs) one by one .

That is all Enjoy it.

Post a Comment for "Getting Error "gradle Dsl Method Not Found: 'compile()'" When Syncing Build.gradle"