I\'m trying to add Espresso 2 to my project (which also has lots of other dependencies), but I\'m hitting this error when trying to run tests:
UNEXPECTED TOP
I got this error trying to set up Espresso as well. Try using
espresso-contrib:2.1
, not 2.0
Try excluding the following from espresso (one at a time):
androidTestCompile('com.android.support.test.espresso:espresso-core:2.1') {
exclude group: 'javax.inject'
exclude group: 'com.google.code.findbugs'
exclude group: 'com.android.support', module: 'support-annotations'
}
Probably need to do the same with runner
I recently ran into this error after we enabled incremental gradle builds.
dexOptions {
javaMaxHeapSize "2g"
incremental true
}
This was resolved by disabling predexing libraries.
dexOptions {
javaMaxHeapSize "2g"
incremental true
preDexLibraries = false
}
According to this bug report, you can also use resolutionStrategy
:
allprojects {
repositories {
mavenCentral()
maven {
url 'http://download.crashlytics.com/maven'
}
}
configurations.all {
resolutionStrategy.force 'com.android.support:support-annotations:22.2.0'
}
}
This is the solution that worked for me and allowed me to use the most recent version of appcompat-v7 and appcompat-v4.
One other useful tip is how to force dependency resolution to a specific version.
Here is one way:
configurations.all {
resolutionStrategy.force 'com.android.support:support-annotations:22.0.0'
}
...and here is another:
configurations.all {
resolutionStrategy.eachDependency { DependencyResolveDetails details ->
if (details.requested.group == 'com.android.support') {
details.useVersion '22.0.0'
}
}
}
Using either of these with com.android.support.test.espresso:espresso-core:2.1
should work.
See the Forcing consistent version for a group of libraries
section in the Gradle documentation for more information.
My solution:
compile 'com.android.support:appcompat-v7:22.1.0'
androidTestCompile 'com.android.support.test.espresso:espresso-core:2.1'
androidTestCompile 'com.android.support:support-annotations:22.1.0'
androidTestCompile 'com.android.support.test:runner:0.2'
+
android {
packagingOptions {
exclude 'LICENSE.txt'
}
}