13

I'm receiving a runtime error No interface method trackUsage() in UsageTracker.java when the lines run in the Espresso test to scroll to a certain element in the RecyclerView list:

   onView(withId(R.id.recyclerView)).perform(scrollTo(hasDescendant(withText(text))));

I'm using RecyclerViewActions for the scrollTo() method.

Here are my current configurations and gradle dependencies:

  • Android Studio 3.0 Canery 9
  • compileSdkVersion 25
  • buildToolsVersion "26.0.1"
  • junit:junit:4.12
  • com.android.support.test:runner:1.0.0
  • com.android.support.test:rules:1.0.0
  • com.android.support.test.espresso:espresso-contrib:2.2.2
  • com.android.support.test.espresso:espresso-core:2.2.2
  • Android Support Library: 25.3.1

Also, for each of the androidTestCompile's I'm using the following excludes:

  • exclude group: 'com.android.support', module: 'appcompat'
  • exclude group: 'com.android.support', module: 'support-v4'
  • exclude group: 'com.android.support', module: 'support-annotations'
  • exclude module: 'recyclerview-v7'

Full error message: No interface method trackUsage(Ljava/lang/String;)V in class Landroid/support/test/internal/runner/tracker/UsageTracker; or its super classes (declaration of 'android.support.test.internal.runner.tracker.UsageTracker' appears in /data/app/adamhurwitz.github.io.doordashlite.test-2/base.apk)

AdamHurwitz
  • 9,758
  • 10
  • 72
  • 134
  • 1
    Check for the version of UsageTracker. Here you have a similar question https://stackoverflow.com/questions/38951218/java-lang-nosuchmethoderror-no-interface-method-sortljava-util-comparator-ex/38951385#38951385 – Ivan Aug 07 '17 at 08:03
  • 1
    Is UsageTracker declaring the trackUsage in its interface? – Ivan Aug 07 '17 at 08:05
  • Thanks for the response @Ivan The *trackUsage()* method is defined in the UsageTracker interface. – AdamHurwitz Aug 08 '17 at 05:21
  • My current hypothesis is this is an issue with *Android Studio 3.0 Canery 9* – AdamHurwitz Aug 11 '17 at 17:54

2 Answers2

34

I was experiencing the same issue with rules 1.0.0 and runner 1.0.0. Though I was able to solve it by just adding espresso-core 3.0.0. Which avoids the use of outdated versions such as suggested in Erics answer.

com.android.support.test:rules:1.0.0 
com.android.support.test.runner:1.0.0 
com.android.support.test.espresso:espresso-core:3.0.0

EDIT: Meanwhile one should use the AndroidX libraries, the current versions as of 2021 / 12 are:

androidx.test:rules:1.4.0
androidx.test:runner:1.4.0
androidx.test:core:1.4.0
androidx.test.espresso:espresso-core:3.4.0

The up to date versions can in general be found on the Android Developers page.

Michael Troger
  • 3,336
  • 2
  • 25
  • 41
6

I had the same problem. To fix it I changed the following dependencies from:

com.android.support.test:runner:1.0.0
com.android.support.test:rules:1.0.0

to:

com.android.support.test:runner:0.5
com.android.support.test:rules:0.5

UPDATE:

Michael's answer is better, don't use this outdated version anymore!

Eric Diniz
  • 61
  • 4