我正在使用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
,都没有用。
这个问题真让我搞砸了。 我是新来的,任何回复都表示赞赏。感谢。
答案 0 :(得分:6)
我使用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'
}
答案 1 :(得分:3)
我试图排除番石榴,它没有用。它不是一个很好的&#34;解决方案,但它的工作原理:
adb shell setprop dalvik.vm.dexopt-flags v=n,o=v
adb shell stop installd
adb shell start installd
在运行测试之前在终端上执行它们。
答案 2 :(得分:1)
我收到此错误是因为我正在使用番石榴,Espresso也含有番石榴。
如果您使用Gradle和Android Studio,则可以从依赖项中排除包,如下所示:
androidTestCompile('com.jakewharton.espresso:espresso:1.1-r3') {
exclude group: 'com.google.guava'
}
答案 3 :(得分:0)
这是一个恼人的错误,但相对容易修复。你得到它的原因是因为你在同一个过程中有同一个类的多个版本,通常我测试项目这是因为你的测试应用程序中有一个库存在你的真实应用程序中,或者你正在应用程序中编译测试apk和测试运行时它会爆炸。
要解决此问题,您只需将测试应用中的所有内容和您的应用更改为提供的依赖项。