Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

run instrumentation test using Espresso: Class ref in pre-verified class resolved to unexpected implementation

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.

like image 813
joooohnli Avatar asked Dec 02 '13 08:12

joooohnli


3 Answers

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'
}
like image 97
Brian Bowman Avatar answered Nov 06 '22 16:11

Brian Bowman


I tried to exclude Guava and it did not work. It's not a "nice" solution but it works:

adb shell setprop dalvik.vm.dexopt-flags v=n,o=v
adb shell stop installd
adb shell start installd

Execute them on a terminal prior to run the tests.

like image 25
Jesús Castro Avatar answered Nov 06 '22 14:11

Jesús Castro


I got this error because I was working with Guava and Espresso also contains Guava.

If you use Gradle and Android Studio you can exclude packages from the dependency like this:

androidTestCompile('com.jakewharton.espresso:espresso:1.1-r3') {
   exclude group: 'com.google.guava'
}
like image 1
Janusz Avatar answered Nov 06 '22 16:11

Janusz