After inspiration from this template, I was able to get roblolectric and espresso tests working with Android and gradle. The key was to store the robolectric in its own module. However, I cannot add a support library to robolectric. How can i do this?
Here's the gradle file of the robolectric module:
apply plugin: 'java'
tasks.withType(Test) {
scanForTestClasses = false
include "**/*Test.class"
}
dependencies {
def androidModule = project(':App')
compile androidModule
testCompile androidModule.android.applicationVariants.toList().first().javaCompile.classpath
testCompile androidModule.android.applicationVariants.toList().first().javaCompile.outputs.files
testCompile files(androidModule.plugins.findPlugin("com.android.application").getBootClasspath())
testCompile 'junit:junit:4.+'
testCompile ('org.robolectric:robolectric:2.3') {
exclude module: 'support-v13'
exclude module: 'support-v4'
}
}
Here is the top level gradle project. As you can see, I bring the correct repo, because the App module does not create any problems.
ext {
versions = [
findbugs: '2.0.3',
checkstyle: '5.7',
pmd: '5.1.1'
]
}
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.12.1+'
classpath group: 'com.autoscout24.gradle', name: 'gradle-monkey-plugin', version: '0.7+'
classpath 'de.felixschulze.gradle:gradle-hockeyapp-plugin:2.1+'
}
}
allprojects {
repositories {
mavenCentral()
}
}
Adding
robolectric, github, , , Android . gradle, , gradle maven (~./gradle vs./m2).
:
Robolectric requires the Google APIs for Android (specifically, the maps JAR) and Android support-v4 library. To download this onto your development machine use the Android SDK tools and then run the following to install them to your local Maven repository:
mvn install:install-file -DgroupId=com.google.android.maps \
-DartifactId=maps \
-Dversion=18_r3 \
-Dpackaging=jar \
-Dfile="$ANDROID_HOME/add-ons/addon-google_apis-google-18/libs/maps.jar"
mvn install:install-file -DgroupId=com.android.support \
-DartifactId=support-v4 \
-Dversion=19.0.1 \
-Dpackaging=jar \
-Dfile="$ANDROID_HOME/extras/android/support/v4/android-support-v4.jar"