我正在使用google-espresso在Kitkat平台上测试系统应用“通讯录”。我的测试项目位于#android-dir#/cts/tests/tests/contactTest。
这是.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)
这是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>
这是命令:
> $ 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
然后我得到这个错误:
INSTRUMENTATION_RESULT: longMsg=java.lang.IllegalAccessError: Class ref in pre-verified class resolved to unexpected implementation
当我使用Eclipse编译并运行它时,一切都很好。并且它只是在这里失败,我在guideline之后尝试了
espresso-dependencies
和espresso-standalone
,但都没有用。这个问题真的把我搞砸了。
我是新来的,任何答复表示赞赏。谢谢。
最佳答案
我在Espresso 2中遇到了这个问题,最终发现依赖性问题出在支持库中。我将以下configurations
添加到build.gradle
的顶层来解决此问题。
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'
}
关于android - 使用Espresso : Class ref in pre-verified class resolved to unexpected implementation运行检测测试,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/20323881/