25

When I try to run ./gradlew build.gradle from terminal, I have been getting following error:

> No signature of method: org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler.compile() is applicable for argument types: (org.gradle.api.internal.project.DefaultProject_Decorated) values: [project ':TestMobile']
Possible solutions: module(java.lang.Object)

I have tried applying java plugin at root build.gradle file and also on sub projects. but still I get same error.

I have the following project structure:

ProjectRepos
->build.gradle
->settings.gradle
->TestMobile (Android plugin)
   ->build.gradle
->ThirdParty/SlidingMenu (Android library)
  ->build.gradle

Where top level build.gradle contains:

// Top-level build file where you can add configuration options common to all sub-   projects/modules.
buildscript {
    repositories {
    mavenCentral()
}
dependencies {
    classpath 'com.android.tools.build:gradle:0.5.+'
    compile project(':TestMobile')
    compile project(':ThirdParty:SlidingMenu')      
}
}

settings.gradle contains following:

include ':ThirdParty:SlidingMenu'
include ':TestMobile'

TestMobile -> build.gradle contains following:

apply plugin: 'android'

dependencies {
    compile fileTree(dir: 'libs', include: '*.jar')
    compile project(':ThirdParty:SlidingMenu')
}

android {
compileSdkVersion 18
buildToolsVersion "18.0.1"

sourceSets {
    main {
        manifest.srcFile 'AndroidManifest.xml'
        java.srcDirs = ['src']
        resources.srcDirs = ['src']
        aidl.srcDirs = ['src']
        renderscript.srcDirs = ['src']
        res.srcDirs = ['res']
        assets.srcDirs = ['assets']
    }

    // Move the tests to tests/java, tests/res, etc...
    instrumentTest.setRoot('tests')

    debug.setRoot('build-types/debug')
    release.setRoot('build-types/release')
 }
}

ThirdParty/SlidingMenu -> build.gradle contains following:

apply plugin: 'android-library'
dependencies {
compile fileTree(dir: 'libs', include: '*.jar')
}

android {
compileSdkVersion 18
buildToolsVersion "18.0.1"

sourceSets {
    main {
        ......
        ......

   }
 }
Jonik
  • 80,077
  • 70
  • 264
  • 372
user2506411
  • 303
  • 1
  • 5
  • 10

2 Answers2

14

You can't have compile dependencies in the buildscript block, only classpath dependencies. Also you can't have project dependencies there. You probably just need to get rid of these two lines.

Peter Niederwieser
  • 121,412
  • 21
  • 324
  • 259
  • If I remove those lines and keep only class path. I get following error : FAILURE: Could not determine which tasks to execute. * What went wrong: Task 'build.gradle' not found in root project 'ProjectRepos'. – user2506411 Oct 09 '13 at 18:55
  • This means that you got past the earlier problem. You need to call `./gradlew build`, not `./gradlew build.gradle`. I recommend to study the first few chapters of the [Gradle User Guide](http://gradle.org/docs/current/userguide/userguide_single.html), which will make you more successful with Gradle. – Peter Niederwieser Oct 09 '13 at 19:21
  • Thanks, this helped me realise I have to add my Guava, Gson, etc dependencies in a top level `dependencies` block. (Then, in Android Studio, run "Tools -> Android -> Sync Project with Gradle files" to make the libs available in the IDE.) – Jonik Dec 07 '13 at 20:29
1

For me, it was a simple syntax error (missing commas) when adding a string resource:

Incorrect:

resValue "string" "app_name" "My App Dev"

Correct:

resValue "string", "app_name", "My App Dev"
Jared Anderton
  • 826
  • 9
  • 12