Gradle not including dependancies


(Jacob Kiser) #1

I have the following gradle file

buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:0.9.+'
    }
}
apply plugin: 'android'
  sourceSets {
    unitTest {
        java.srcDir file('src/main/java/com/smartsocialmedia/tests')
        resources.srcDir file('src/main/res/com/smartsocialmedia/tests')
    }
}
  configurations {
    unitTestCompile.extendsFrom runtime
    unitTestRuntime.extendsFrom unitTestCompile
}
  repositories {
    mavenCentral()
}
  android {
    compileSdkVersion 19
    buildToolsVersion '19.0.0'
      lintOptions {
        checkReleaseBuilds false
        abortOnError false
    }
      defaultConfig {
        minSdkVersion 14
        targetSdkVersion 19
        versionCode 7
        versionName "1.0.5"
        testPackageName "com.smartsocialmedia.tests"
        testInstrumentationRunner "android.test.InstrumentationTestRunner"
        //testHandlingProfiling true
        testFunctionalTest true
    }
      buildTypes {
        release {
            runProguard false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
        }
    }
}
  dependencies {
    compile 'com.android.support:support-v4:18.0.0'
    compile 'org.apache.httpcomponents:httpmime:4.1.2@jar'
    compile 'com.github.chrisbanes.actionbarpulltorefresh:library:+'
    compile files('libs/universal-image-loader-1.9.1-with-sources.jar')
      repositories {
        mavenCentral()
    }
    unitTestCompile files("$project.buildDir/classes/release")
    unitTestCompile 'junit:junit:4.10'
    unitTestCompile 'org.robolectric:robolectric:2.1.+'
    unitTestCompile 'com.google.android:android:4.0.1.2'
    unitTestCompile 'com.google.android:android-test:4.1.1.4'
    unitTestCompile files('libs/universal-image-loader-1.9.1-with-sources.jar')
    unitTestCompile 'org.apache.httpcomponents:httpmime:4.1.2@jar'
    unitTestCompile 'com.android.support:support-v4:18.0.0'
}
  task unitTest(type:Test, dependsOn: assemble) {
    testClassesDir = project.sourceSets.unitTest.output.classesDir
    classpath = project.sourceSets.unitTest.runtimeClasspath
}
check.dependsOn unitTest

As you can see it contains a unit test called unitTest. I found making this run in android studio easy enough, but getting gradle to run it is a nightmare. When I attempt to run the unit test gradle will error stating that it can’t find the class I am using (which is part of the default build). How do I just make gradle build my project as usual and run the darn test… this seems like an obvious way of doing things, and yet.


(Mark Iantorno) #2

I’m having the exact same problem. Everything is set up correctly…the tests work with the Android Libraries just fine, but if I include the compiled classes from my own project:

unitTestCompile files("$project.buildDir/classes/release") …it doesn’t work…

Always says cannot resolve symbol.


(Peter Niederwieser) #3

I’m not sure if ‘unitTestCompile files("$project.buildDir/classes/release")’ is the right approach (especially without a task dependency), but since the question is related to the ‘android’ plugin, I’d recommend to ask on the Android list.