I am trying to setup a project using frameworks listed above. I'm using this demonstration project deckard-gradle and i cannot sync gradle. It says that org.robolectric.gradle:gradle-android-test-plugin:0.9.4-SNAPSHOT was not found. How do i fix this? Has anyone made this work? here is the build.gradle file
buildscript {
repositories {
mavenLocal()
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.9.2'
classpath 'org.robolectric.gradle:gradle-android-test-plugin:0.9.4-SNAPSHOT'
}
}
allprojects {
repositories {
mavenCentral()
}
}
apply plugin: 'android'
apply plugin: 'android-test'
android {
packagingOptions {
exclude 'LICENSE.txt'
exclude 'META-INF/LICENSE'
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/NOTICE'
}
compileSdkVersion 19
buildToolsVersion "19.0.3"
defaultConfig {
minSdkVersion 18
targetSdkVersion 18
versionCode 2
versionName "1.0.0-SNAPSHOT"
testInstrumentationRunner "com.google.android.apps.common.testing.testrunner.GoogleInstrumentationTestRunner"
}
buildTypes {
release {
runProguard false
}
}
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
res.srcDirs = ['res']
}
androidTest {
setRoot('src/test')
}
}
}
androidTest {
include '**/*Test.class'
exclude '**/espresso/**/*.class'
}
dependencies {
repositories {
mavenCentral()
maven {
url 'https://oss.sonatype.org/content/repositories/snapshots/'
}
}
// Espresso
androidTestCompile files('lib/espresso-1.1.jar', 'lib/testrunner-1.1.jar', 'lib/testrunner-runtime-1.1.jar')
androidTestCompile 'com.google.guava:guava:14.0.1',
'com.squareup.dagger:dagger:1.1.0',
'org.hamcrest:hamcrest-integration:1.1',
'org.hamcrest:hamcrest-core:1.1',
'org.hamcrest:hamcrest-library:1.1'
androidTestCompile('junit:junit:4.11') {
exclude module: 'hamcrest-core'
}
androidTestCompile('org.robolectric:robolectric:2.3-SNAPSHOT') {
exclude module: 'classworlds'
exclude module: 'maven-artifact'
exclude module: 'maven-artifact-manager'
exclude module: 'maven-error-diagnostics'
exclude module: 'maven-model'
exclude module: 'maven-plugin-registry'
exclude module: 'maven-profile'
exclude module: 'maven-project'
exclude module: 'maven-settings'
exclude module: 'nekohtml'
exclude module: 'plexus-container-default'
exclude module: 'plexus-interpolation'
exclude module: 'plexus-utils'
exclude module: 'wagon-file'
exclude module: 'wagon-http-lightweight'
exclude module: 'wagon-http-shared'
exclude module: 'wagon-provider-api'
}
androidTestCompile 'com.squareup:fest-android:1.0.+'
}
apply plugin: 'idea'
idea {
module {
testOutputDir = file('build/test-classes/debug')
}
}
They currently do not publish snapshot versions of gradle-android-test-plugin. See: https://github.com/robolectric/gradle-android-test-plugin/issues/8
Related
I already saw the answer: Could not find property 'outputFile' on com.android.build.gradle.internal.api.ApplicationVariantImpl
and tried to apply it, but with no success.
I'm migrating from gradle 'com.android.tools.build:gradle:0.12.2' to 'com.android.tools.build:gradle:1.0.0', and not I'm getting the error
Error:Could not find property 'processManifest' on com.android.build.gradle.internal.api.ApplicationVariantImpl_Decorated#158aaf6.
I've already renamed runProguard to minifyEnabled
buildscript {
repositories {
mavenLocal()
mavenCentral()
}
dependencies {
// Spoon plugin of version 0.10.0 supports Android plugin 0.10.+
classpath 'com.android.tools.build:gradle:0.12.2'
classpath 'org.robolectric:robolectric-gradle-plugin:0.11.+'
classpath 'com.stanfy.spoon:spoon-gradle-plugin:0.10.0'
}
}
configurations {
all*.exclude group: 'com.android.support', module: 'support-v4'
}
allprojects {
repositories {
mavenCentral()
maven {
url "https://repository-achartengine.forge.cloudbees.com/snapshot/"
}
}
}
apply plugin: 'android'
apply plugin: 'robolectric'
android {
packagingOptions {
exclude 'META-INF/NOTICE'
exclude 'META-INF/LICENSE'
exclude 'META-INF/LICENSE.txt'
exclude 'LICENSE.txt'
}
compileSdkVersion 19
buildToolsVersion "19.1.0"
defaultConfig {
minSdkVersion 10
targetSdkVersion 19
versionCode 3
versionName "1.02"
testInstrumentationRunner "com.google.android.apps.common.testing.testrunner.GoogleInstrumentationTestRunner"
}
buildTypes {
release {
runProguard false
}
}
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
res.srcDirs = ['res']
}
androidTest {
setRoot('src/test')
}
instrumentTest {
setRoot('src/test')
}
}
lintOptions {
abortOnError false
}
dexOptions {
jumboMode true
}
dependencies {
androidTestCompile 'com.jayway.android.robotium:robotium-solo:5.0.1'
}
}
robolectric {
include '**/*Test.class'
exclude '**/espresso/**/*.class'
}
dependencies {
compile 'com.astuetz:pagerslidingtabstrip:1.0.1'
compile 'com.android.support:appcompat-v7:19.0.0'
compile 'com.android.support:support-v4:19.0.0'
compile 'com.android.support:gridlayout-v7:19.0.0'
compile 'org.achartengine:achartengine:1.2.0'
repositories {
mavenCentral()
maven {
url 'https://oss.sonatype.org/content/repositories/snapshots/'
}
}
// Espresso
androidTestCompile files('lib/espresso-1.1.jar', 'lib/testrunner-1.1.jar', 'lib/testrunner-runtime-1.1.jar')
androidTestCompile 'com.google.guava:guava:14.0.1',
'com.squareup.dagger:dagger:1.1.0',
'org.hamcrest:hamcrest-integration:1.1',
'org.hamcrest:hamcrest-core:1.1',
'org.hamcrest:hamcrest-library:1.1'
androidTestCompile('junit:junit:4.11') {
exclude module: 'hamcrest-core'
}
androidTestCompile('org.robolectric:robolectric:2.4') {
exclude module: 'classworlds'
exclude module: 'maven-artifact'
exclude module: 'maven-artifact-manager'
exclude module: 'maven-error-diagnostics'
exclude module: 'maven-model'
exclude module: 'maven-plugin-registry'
exclude module: 'maven-profile'
exclude module: 'maven-project'
exclude module: 'maven-settings'
exclude module: 'nekohtml'
exclude module: 'plexus-container-default'
exclude module: 'plexus-interpolation'
exclude module: 'plexus-utils'
exclude module: 'wagon-file'
exclude module: 'wagon-http-lightweight'
exclude module: 'wagon-http-shared'
exclude module: 'wagon-provider-api'
exclude group: 'com.android.support', module: 'support-v4'
}
androidTestCompile 'com.squareup:fest-android:1.0.7'
androidTestCompile 'com.squareup.spoon:spoon-client:1.1.0'
}
apply plugin: 'spoon'
// This section is optional
spoon {
// for debug output
debug = true
// To run a single test class
// className = 'com.proverbed.budget.espresso.activity.AllTestsSuite'
// To run a single method in TestCase
// methodName = 'testAddIncome'
}
apply plugin: 'idea'
idea {
module {
testOutputDir = file('build/test-classes/debug')
}
}
You are using old robolectric plugin
https://github.com/robolectric/robolectric-gradle-plugin/issues/120
I have successfully installed Robolectric, but my tests are not running at all. There are no errors, but also no results. What did I miss?
After running ./gradlew test there are no test reports, but test-classes are generated properly
My build.gradle:
buildscript {
repositories {
mavenCentral()
maven { url 'https://maven.fabric.io/repo' }
}
dependencies {
...
classpath 'io.fabric.tools:gradle:1.+'
classpath 'org.robolectric:robolectric-gradle-plugin:0.11.+'
}
}
allprojects {
repositories {
mavenCentral()
}
}
apply plugin: 'android-sdk-manager'
apply plugin: 'com.android.application'
apply plugin: 'io.fabric'
apply plugin: 'idea'
apply plugin: 'hugo'
apply plugin: 'android'
apply plugin: 'robolectric'
idea {
module {
downloadJavadoc = true
downloadSources = true
testOutputDir = file('build/test-classes/debug')
}
}
repositories {
mavenCentral()
maven { url 'https://repo.commonsware.com.s3.amazonaws.com' }
flatDir name: 'localRepository', dirs: 'libs-aar'
maven { url 'https://maven.fabric.io/repo' }
}
dependencies {
repositories {
mavenCentral()
}
...
// Espresso
androidTestCompile files('lib/espresso-1.1.jar', 'lib/testrunner-1.1.jar', 'lib/testrunner-runtime-1.1.jar')
androidTestCompile 'com.google.guava:guava:14.0.1'
androidTestCompile 'com.squareup.dagger:dagger:1.1.0'
androidTestCompile 'org.hamcrest:hamcrest-integration:1.1'
androidTestCompile 'org.hamcrest:hamcrest-core:1.1'
androidTestCompile 'org.hamcrest:hamcrest-library:1.1'
androidTestCompile('junit:junit:4.11') {
exclude module: 'hamcrest-core'
}
androidTestCompile('org.robolectric:robolectric:2.3') {
exclude module: 'classworlds'
exclude module: 'commons-logging'
exclude module: 'httpclient'
exclude module: 'maven-artifact'
exclude module: 'maven-artifact-manager'
exclude module: 'maven-error-diagnostics'
exclude module: 'maven-model'
exclude module: 'maven-project'
exclude module: 'maven-settings'
exclude module: 'plexus-container-default'
exclude module: 'plexus-interpolation'
exclude module: 'plexus-utils'
exclude module: 'wagon-file'
exclude module: 'wagon-http-lightweight'
exclude module: 'wagon-provider-api'
}
androidTestCompile 'com.squareup:fest-android:1.0.+'
}
android {
compileSdkVersion 19
buildToolsVersion '19.1.0'
useOldManifestMerger true
defaultConfig {
minSdkVersion 11
targetSdkVersion 19
buildConfigField "String", "GIT_SHA", "\"${gitSha()}\""
testInstrumentationRunner "com.google.android.apps.common.testing.testrunner.GoogleInstrumentationTestRunner"
// buildConfigField "String", "BUILD_TIME", buildTime()
}
...
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src/com', 'src/se', 'src/viewpagerindicator' , 'src-gen']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
}
...
androidTest {
setRoot('src/androidTest')
}
}
packagingOptions {
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/NOTICE.txt'
exclude 'LICENSE.txt'
exclude 'META-INF/LICENSE'
exclude 'META-INF/NOTICE'
}
}
...
robolectric {
include '**/*Tests.class'
exclude '**/espresso/**/*.class'
}
And my test:
#RunWith(RobolectricTestRunner.class)
public class StartTest {
#Test
public void testSomething() throws Exception {
//Activity activity = Robolectric.buildActivity(DeckardActivity.class).create().get();
assertTrue(true);
}
}
I think the problem is with your file mask. You are including Tests.class, but your class is called StartTest (notice the missing s) so it won't be included.
I have a very hard time solving this problem in Android studio.
I have made an app, and trying to test it with this Robolectric test tool, but it seems like robolectric cant find android jar files although android jar is running perfectly when i run the app by it self. My friend has a clone of the test and the app at his computer, and here i runs perfectly. What i wrong ?
Please help me out here.
This is the failure:
java.lang.NoClassDefFoundError: android/R
at org.robolectric.bytecode.Setup.(Setup.java:39)
at org.robolectric.RobolectricTestRunner.createSetup(RobolectricTestRunner.java:137)
at org.robolectric.RobolectricTestRunner.createSdkEnvironment(RobolectricTestRunner.java:114)
at org.robolectric.RobolectricTestRunner$3.create(RobolectricTestRunner.java:307)
at org.robolectric.EnvHolder.getSdkEnvironment(EnvHolder.java:21)
at org.robolectric.RobolectricTestRunner.getEnvironment(RobolectricTestRunner.java:305)
at org.robolectric.RobolectricTestRunner.access$300(RobolectricTestRunner.java:61)
And this is the app gradle file:
apply plugin: 'com.android.application'
apply plugin: 'robolectric'
apply plugin: 'idea'
android {
compileSdkVersion 18
buildToolsVersion '19.1.0'
defaultConfig {
applicationId "com.kea.project.wheeloffortune"
minSdkVersion 16
targetSdkVersion 18
testInstrumentationRunner "com.google.android.apps.common.testing.testrunner.GoogleInstrumentationTestRunner"
}
buildTypes {
release {
runProguard false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
sourceSets {
androidTest {
setRoot('src/test')
}
}
}
buildscript {
repositories {
jcenter()
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.12.2'
classpath 'org.robolectric:robolectric-gradle-plugin:0.12.+'
}
}
dependencies {
compile 'com.android.support:support-v4:19.1.0'
compile files('libs/commons-lang3-3.3.2.jar')
compile files('libs/picasso-2.2.0.jar')
compile files('libs/volley.jar')
compile files('libs/espresso-1.1.jar')
compile files('libs/testrunner-1.1.jar')
compile files('libs/testrunner-runtime-1.1.jar')
androidTestCompile files('lib/espresso-1.1.jar')
androidTestCompile files('lib/testrunner-1.1.jar')
androidTestCompile files('lib/testrunner-runtime-1.1.jar')
androidTestCompile 'com.google.guava:guava:14.0.1'
androidTestCompile 'com.squareup.dagger:dagger:1.1.0'
androidTestCompile 'org.hamcrest:hamcrest-integration:1.1'
androidTestCompile 'org.hamcrest:hamcrest-core:1.1'
androidTestCompile 'org.hamcrest:hamcrest-library:1.1'
androidTestCompile('junit:junit:4.11') {
exclude module: 'hamcrest-core'
}
androidTestCompile('org.robolectric:robolectric:2.3') {
exclude module: 'classworlds'
exclude module: 'commons-logging'
exclude module: 'httpclient'
exclude module: 'maven-artifact'
exclude module: 'maven-artifact-manager'
exclude module: 'maven-error-diagnostics'
exclude module: 'maven-model'
exclude module: 'maven-project'
exclude module: 'maven-settings'
exclude module: 'plexus-container-default'
exclude module: 'plexus-interpolation'
exclude module: 'plexus-utils'
exclude module: 'wagon-file'
exclude module: 'wagon-http-lightweight'
exclude module: 'wagon-provider-api'
}
androidTestCompile 'com.squareup:fest-android:1.0.+'
}
idea {
module {
testOutputDir = file('build/test-classes/debug')
}
}
task addTest {
def src = ['src/test/java']
def file = file("app.iml")
doLast {
try {
def parsedXml = (new XmlParser()).parse(file)
def node = parsedXml.component[1].content[0]
src.each {
def path = 'file://$MODULE_DIR$/' + "${it}"
def set = node.find { it.#url == path }
if (set == null) {
new Node(node, 'sourceFolder', ['url': 'file://$MODULE_DIR$/' + "${it}", 'isTestSource': "true"])
def writer = new StringWriter()
new XmlNodePrinter(new PrintWriter(writer)).print(parsedXml)
file.text = writer.toString()
}
}
} catch (FileNotFoundException e) {
// nop, iml not found
}
}
}
gradle.projectsEvaluated {
preBuild.dependsOn(addTest)
}
robolectric {
include '**/*Test.class'
exclude '**/espresso/**/*.class'
}
I use android-annotations in my projects and I start learning unit tests. I'm trying to execute tests with robolectric but with no success (Android Studio 8.6 and Gradle).
With some tutorials I configure my build.gradle and if I execute a simple test, without access any activity, the test generate OK results. But, when I try to execute tests accessing a activity, occurs errors.
Error
LoginActivityTest > testActivityAA2 FAILED
java.lang.RuntimeException at LoginActivityTest.java:33
Caused by: java.lang.reflect.InvocationTargetException at LoginActivityTest.java:33
Caused by: java.lang.IllegalStateException at LoginActivityTest.java:33
My Tests
#Config(manifest = "./src/main/AndroidManifest.xml", emulateSdk = 18)
#RunWith(RobolectricTestRunner.class)
public class LoginActivityTest extends InstrumentationTestCase {
//This is OK
#Test
public void testNumbers() throws Exception{
final int expected = 5;
final int reality = 5;
assertEquals(expected, reality);
}
// this occurs error
#Test
public void testActivityAA2() throws Exception {
LoginActivity_ loginnActivity = new LoginActivity_();
loginnActivity.onCreate(null);
assertNotNull(loginnActivity);
}
}
My build.gradle file
apply plugin: 'com.android.application'
apply plugin: 'android-apt'
def AAVersion = '3.0.1'
apply plugin: 'robolectric'
buildscript {
repositories {
mavenCentral()
}
dependencies {
// replace with the current version of the Android plugin
classpath 'com.android.tools.build:gradle:0.12+'
// the latest version of the android-apt plugin
classpath 'com.neenbedankt.gradle.plugins:android-apt:1.3'
classpath 'org.robolectric:robolectric-gradle-plugin:0.11.+'
}
}
repositories {
mavenCentral()
mavenLocal()
}
dependencies {
apt "org.androidannotations:androidannotations:$AAVersion"
compile "org.androidannotations:androidannotations-api:$AAVersion"
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:support-v4:20.0.0'
compile 'com.android.support:appcompat-v7:20.0.0'
compile 'com.android.support:gridlayout-v7:20.0.0'
compile 'com.google.code.gson:gson:2.2.4'
compile 'com.readystatesoftware.systembartint:systembartint:1.0.3'
compile 'org.springframework.android:spring-android-rest-template:1.0.1.RELEASE'
// Espresso
androidTestCompile files('lib/espresso-1.1.jar', 'lib/testrunner-1.1.jar', 'lib/testrunner-runtime-1.1.jar')
androidTestCompile 'com.google.guava:guava:14.0.1'
androidTestCompile 'com.squareup.dagger:dagger:1.1.0'
androidTestCompile 'org.hamcrest:hamcrest-integration:1.1'
androidTestCompile 'org.hamcrest:hamcrest-core:1.1'
androidTestCompile 'org.hamcrest:hamcrest-library:1.1'
androidTestCompile('junit:junit:4.11') {
exclude module: 'hamcrest-core'
}
androidTestCompile('org.robolectric:robolectric:2.3') {
exclude module: 'classworlds'
exclude module: 'commons-logging'
exclude module: 'httpclient'
exclude module: 'maven-artifact'
exclude module: 'maven-artifact-manager'
exclude module: 'maven-error-diagnostics'
exclude module: 'maven-model'
exclude module: 'maven-project'
exclude module: 'maven-settings'
exclude module: 'plexus-container-default'
exclude module: 'plexus-interpolation'
exclude module: 'plexus-utils'
exclude module: 'wagon-file'
exclude module: 'wagon-http-lightweight'
exclude module: 'wagon-provider-api'
}
androidTestCompile 'com.squareup:fest-android:1.0.+'
}
apply plugin: 'idea'
idea {
module {
testOutputDir = file('build/test-classes/debug')
}
}
apt {
arguments {
androidManifestFile variant.processResources.manifestFile
resourcePackageName 'com.example.project'
// If you're using Android NBS flavors you should use the following line instead of hard-coded packageName
// resourcePackageName android.defaultConfig.packageName
// You can set optional annotation processing options here, like these commented options:
// logLevel 'INFO'
// logFile '/var/log/aa.log'
}
}
robolectric {
include '**/*Test.class'
exclude '**/espresso/**/*.class'
}
android {
compileSdkVersion 19
buildToolsVersion "20.0.0"
packagingOptions {
exclude 'META-INF/DEPENDENCIES.txt'
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/NOTICE.txt'
exclude 'META-INF/NOTICE'
exclude 'META-INF/LICENSE'
exclude 'META-INF/DEPENDENCIES'
exclude 'META-INF/notice.txt'
exclude 'META-INF/license.txt'
exclude 'META-INF/dependencies.txt'
exclude 'META-INF/LGPL2.1'
}
defaultConfig {
applicationId "br.com.nexxcity.nexxcitypos"
minSdkVersion 7
targetSdkVersion 19
versionCode 1
versionName "1.0"
testInstrumentationRunner "com.google.android.apps.common.testing.testrunner.GoogleInstrumentationTestRunner"
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_7
targetCompatibility JavaVersion.VERSION_1_7
}
buildTypes {
release {
runProguard true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
sourceSets {
androidTest {
setRoot('src/androidTest')
}
}
}
Can you help me guys ?
Thx for patience
You shouldn't initialise the Activity like that for Robolectric tests.
Use Robolectric.buildActivity() (documentation: http://robolectric.org/activity-lifecycle/)
For example:
Robolectric.buildActivity(LoginActivity.class).create().get()
Depending on what you need to test, you can chain additional methods as well like visible(), start() etc.
I am trying to introduce Robolectric to an already existing android project. The project already runs a slew of espresso tests. As soon as I try to introduce robolectric, the tests fail with
java.lang.NoClassDefFoundError
Anyone have any thoughts? I'm using the gradle file below and used the Decard project as an example on brining in Robolectric.
apply plugin: 'android'
apply plugin: 'robolectric'
apply from : "$rootDir/gradle/signing.gradle"
apply from : "$rootDir/gradle/build_extras.gradle"
apply from : "$rootDir/gradle/environments.gradle"
loadConfiguration()
apply from : "$rootDir/gradle/checkstyle.gradle"
apply from : "$rootDir/gradle/pmd.gradle"
apply from : "$rootDir/gradle/findbugs.gradle"
apply from : "$rootDir/gradle/espresso.gradle"
android {
compileSdkVersion 19
buildToolsVersion '19.1'
useOldManifestMerger true
defaultConfig {
applicationId ‘com.example.app'
minSdkVersion 14
targetSdkVersion 19
versionCode getVersionCode()
testInstrumentationRunner 'com.google.android.apps.common.testing.testrunner.GoogleInstrumentationTestRunner'
}
packagingOptions {
exclude 'LICENSE.txt'
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/LICENSE'
exclude 'META-INF/DEPENDENCIES'
exclude 'META-INF/NOTICE'
exclude 'META-INF/NOTICE.txt'
}
lintOptions {
abortOnError true
}
jacoco {
version = '0.6.2.201302030002'
}
sourceSets {
androidTest {
setRoot('src/test')
}
debug.setRoot('build-types/debug')
}
buildTypes {
debug {
applicationIdSuffix '.debug'
debuggable true
testCoverageEnabled false
}
}
applicationVariants.all { variant ->
removeSetAnimationScaleFromManifest(variant)
task("generate${variant.name}Javadoc", type: Javadoc) {
description "Generates Javadoc for $variant.name."
group "Code Quality"
def Properties localProperties = loadPropertiesFile('../local.properties')
source = variant.javaCompile.source
classpath = files(variant.javaCompile.classpath.files) +
files(localProperties['sdk.dir'] + "/platforms/android-4.4.2/android.jar")
}
copyAndRenameZipAlignedPackage(variant)
}
}
apply plugin: 'monkey'
monkey {
teamCityLog = false
eventCount = 5000
seed = 42
failOnFailure = false
install = false
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile project(':SlidingMenuLibrary')
compile 'com.android.support:support-v4:19.1.+'
compile 'com.google.android.gms:play-services:5.0.77'
compile 'org.apache.james:apache-mime4j:0.6'
compile 'org.apache.httpcomponents:httpmime:4.2.3'
compile 'org.jsoup:jsoup:1.6.3'
compile 'com.nineoldandroids:library:2.4.0'
compile 'com.googlecode.ez-vcard:ez-vcard:0.9.3'
compile 'com.googlecode.libphonenumber:libphonenumber:5.9'
// Espresso
provided 'com.jakewharton.espresso:espresso:1.1-r3'
androidTestCompile ('com.jakewharton.espresso:espresso:1.1-r3') {
}
androidTestCompile 'com.google.guava:guava:14.0.1'
androidTestCompile 'com.squareup.dagger:dagger:1.1.0'
androidTestCompile 'org.hamcrest:hamcrest-integration:1.1'
//androidTestCompile 'org.hamcrest:hamcrest-core:1.1'
androidTestCompile 'org.hamcrest:hamcrest-library:1.1'
androidTestCompile('junit:junit:4.11') {
exclude module: 'hamcrest-core'
}
androidTestCompile('org.robolectric:robolectric:2.3') {
exclude module: 'classworlds'
exclude module: 'commons-logging'
exclude module: 'httpclient'
exclude module: 'maven-artifact'
exclude module: 'maven-artifact-manager'
exclude module: 'maven-error-diagnostics'
exclude module: 'maven-model'
exclude module: 'maven-project'
exclude module: 'maven-settings'
exclude module: 'plexus-container-default'
exclude module: 'plexus-interpolation'
exclude module: 'plexus-utils'
exclude module: 'wagon-file'
exclude module: 'wagon-http-lightweight'
exclude module: 'wagon-provider-api'
}
androidTestCompile 'com.squareup:fest-android:1.0.+'
}
apply plugin: 'idea'
idea {
module {
testOutputDir = file('build/test-classes/debug')
}
}
ErrorLog:
java.lang.NoClassDefFoundError: com/example/android/ui/GettingStarted
...
Caused by: java.lang.IllegalAccessError: Class ref in pre-verified class resolved to unexpected implementation
at dalvik.system.DexFile.defineClassNative(Native Method)
at dalvik.system.DexFile.defineClass(DexFile.java:222)
at dalvik.system.DexFile.loadClassBinaryName(DexFile.java:215)
at dalvik.system.DexPathList.findClass(DexPathList.java:322)
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:65)
at java.lang.ClassLoader.loadClass(ClassLoader.java:497)
at java.lang.ClassLoader.loadClass(ClassLoader.java:457)
This happens when you have a class compiled into your test APK AND you app APK.
Run ./gradlew :app:dependencies and look for duplicates.
You may need to use "provided" instead of "compile" somewhere.
This has been discussed in lots of places:
http://www.sinking.in/blog/android-dependency-double-trouble/
java.lang.IllegalAccessError: Class ref in pre-verified class resolved to unexpected implementation getting while running test project?
https://www.google.com/#q=java.lang.IllegalAccessError%3A+Class+ref+in+pre-verified+class+resolved+to+unexpected+implementation