run instrumentation test using Espresso: Class ref in pre-verified class resolved to unexpected implementation
android, android-espresso, instrumentation
Solution
I ran into this issue with Espresso 2 and eventually found the dependency issue was with the support library. I added the following `configurations` to the top level of `build.gradle` to resolve the issue.
configurations {
androidTestCompile.exclude group: 'com.android.support'
androidTestCompile.exclude module: 'support-v4'
}
dependencies {
compile 'com.android.support:support-v4:21.+'
// more dependencies
androidTestCompile 'com.android.support.test.espresso:espresso-core:2.0'
androidTestCompile 'com.android.support.test.espresso:espresso-contrib:2.0'
androidTestCompile 'com.android.support.test:testing-support-lib:0.1'
}
Problem
I am testing the system app Contacts on platform Kitkat using the google-espresso. My test project located in #android-dir#/cts/tests/tests/contactTest. Here is the .mk: ``` LOCAL_PATH:= $(call my-dir) include $(CLEAR_VARS) # don't include this package in any target LOCAL_MODULE_TAGS := optional # and when built explicitly put it in the data partition LOCAL_MODULE_PATH := $(TARGET_OUT_DATA_APPS) LOCAL_JAVA_LIBRARIES := android.test.runner LOCAL_STATIC_JAVA_LIBRARIES += librarycontacts LOCAL_CERTIFICATE := shared LOCAL_SRC_FILES := $(call all-java-files-under, src) LOCAL_PACKAGE_NAME := contactsTest LOCAL_INSTRUMENTATION_FOR := Contacts include $(BUILD_CTS_PACKAGE) ################################################## include $(CLEAR_VARS) LOCAL_PREBUILT_STATIC_JAVA_LIBRARIES += librarycontacts:libs/espresso-1.0-SNAPSHOT-bundled.jar include $(BUILD_MULTI_PREBUILT) ``` Here is the Manifest.xml ``` <?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.android.contacts.test" android:versionCode="1" android:versionName="1.0" > <uses-sdk android:minSdkVersion="7" android:targetSdkVersion="19" /> <instrumentation android:name="com.google.android.apps.common.testing.testrunner.GoogleInstrumentationTestRunner" android:targetPackage="com.android.contacts" /> <application> <uses-library android:name="android.test.runner" /> </application> </manifest> ``` Here is the commands: ``` > $ mmm cts/tests/tests/contactsTest/ > $ adb install -r out/target/product/generic/data/app/contactsTest.apk > $ adb shell am instrument -w -r com.android.contacts.test/com.google.android.apps.common.testing.testrunner.GoogleInstrumentationTestRunner ``` then I got this error: ``` INSTRUMENTATION_RESULT: longMsg=java.lang.IllegalAccessError: Class ref in pre-verified class resolved to unexpected implementation ``` It's all OK when I compiling and running it with eclipse. and it just fails here, I've tried both `espresso-dependencies` and `espresso-standalone` following the guideline, all do not work. This problem really messed me up. I'm new to here,any reply appreciated. thanks.