3

I am using google's volley lib in a project. I added it as a module, but during compilation it gives following error.

Error

Here is the directory structure :

dir_structure

I tried adding

// testing
testCompile 'org.robolectric:robolectric:2.4'
testCompile 'junit:junit:4.+'

to the app's build.gradle, but that didn't help.

So the obvious question is how to make it work?

UPDATE:

Volley's build.gradle

buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:1.1.0+'

        // testing
        testCompile 'org.robolectric:robolectric:2.4'
        testCompile 'junit:junit:4.+'
    }
}

apply plugin: 'com.android.library'

android {
    compileSdkVersion 19
    buildToolsVersion = '21.1.0'
}

apply from: 'rules.gradle'

App's build.gradle

apply plugin: 'com.android.application'

android {
    compileSdkVersion 22
    buildToolsVersion "19.1.0"

    defaultConfig {
        applicationId "com.example.vjdhama.project"
        minSdkVersion 15
        targetSdkVersion 22
        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:22.0.0'

    compile project(":volley")
}

ERROR :

/home/vjdhama/Documents/Coding/Android/project/volley/build.gradle
Error:Error:line (18)Gradle DSL method not found: 'testCompile()'
Possible causes:<ul><li>The project 'project' may be using a version of Gradle that does not contain the method.
<a href="openGradleSettings">Gradle settings</a></li><li>The build file may be missing a Gradle plugin.
<a href="apply.gradle.plugin">Apply Gradle plugin</a></li>
vjdhama
  • 4,878
  • 5
  • 33
  • 47
  • The dependency is required for Volley, not for app module. Can you share volley build gradle or location where you get volley – Eugen Martynov Apr 03 '15 at 18:16
  • I updated the question. I also tries using `androidtestcompile` as suggested in [here](http://stackoverflow.com/questions/25252637/gradle-build-script-error-occurs-when-i-attempt-to-use-testcompile-in-dependan) but it also didn't work. – vjdhama Apr 04 '15 at 10:03
  • You added dependencies to wrong place. Correct file but should be dependencies for library and not for build script – Eugen Martynov Apr 04 '15 at 10:31
  • dependencies { androidTestCompile 'org.robolectric:robolectric:2.4' androidTestCompile 'junit:junit:4.+' } I added this at the end of volley's `build.gradle`. It's again showing the first error of `junit` and `roboelectric`. – vjdhama Apr 04 '15 at 10:57

1 Answers1

0

+1 same issue. I can seem to still use the library within my greater android project, but the tests don't run. It seems the latest version of Volley has broken dependencies in the build.gradle. Not an answer since it doesn't seem to work, but maybe you'll have more luck than I.

by adding

dependencies {
    testCompile 'org.robolectric:robolectric:2.3'
    testCompile 'junit:junit:4.11'
    testCompile 'org.mockito:mockito-core:1.9.5'
}

to the bottom of volley's build.gradle file, I can get the run to fail all the tests instead of failing the build. It's something I suppose.

Full build.gradle from volley:

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:1.2.3'
    }
}

apply plugin: 'com.android.library'

android {
    compileSdkVersion 22
    buildToolsVersion = '22.0.1'
}

apply from: 'rules.gradle'

dependencies {
    testCompile 'org.robolectric:robolectric:2.3'
    testCompile 'junit:junit:4.11'
    testCompile 'org.mockito:mockito-core:1.9.5'
}
Brian
  • 857
  • 2
  • 12
  • 25