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)
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.
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!
Related
I am using Picasso library for images in my android library, and if i run app for API 26 it compiles okay it runs and everything is perfect, if i run for API 21 (5.0) i always receive duplicate entry: okio/AsyncTimeout$1.class
I already excluded in my gradle
configurations {
all*.exclude group: 'com.squareup.okhttp3', module: 'okhttp'
}
But no success, if i assemble in terminal i get same error, only libraries i use in my lib project are exoplayer and picasso (others are support libraries) I also tried to remove Picasso then it builds normally. Is it maybe connected that the other libraries of main project are causing it?
Try to add this in project level grandle:
configurations{
all*.exclude module: 'okhttp'
all*.exclude module: 'okio'
}
I had several libraries conflict issues. That i resolved by adding
configurations {
all {
exclude module: 'httpclient'
exclude module: 'commons-logging'
exclude group: 'org.json', module: 'json'
exclude group: 'org.apache.httpcomponents'
exclude module: 'xmlParserAPIs'
exclude module: 'xpp3'
exclude module: 'opengl-api'
}
}
But still following error present. And i am unable to build signed apk.
I have tried project clean/rebuild option.
Error: android defines classes that conflict with classes now provided by Android. Solutions include finding newer versions or alternative libraries that don't have the same problem (for example, for httpclient use HttpUrlConnection or okhttp instead), or repackaging the library using something like jarjar. [DuplicatePlatformClasses]
Thanks in advance for your help.
Problem
How to see which dependency is creating conflicts. It is same like shooting in dark.
Solution
Some AS plugin that will show you which projects dependency hierarchy. You can find where issue presents exactly and solve that.
Gradle View is an Android Studio plugin that you can install and show dependency hierarchy.
Methods Count is another plugin, it also shows dependency tree.
The error may be comes from different module but if issue is httpcomp... or xpp3 then
I just add these lines of code in app Gradle
dependencies {
......
configurations {
all*.exclude group: 'xpp3', module: 'xpp3'
implementation.exclude group: "org.apache.httpcomponents", module: "httpclient"
}
}
done
I have upgraded to the latest API level 24 which is the latest API Level (at time of writhing) anyhow it caused this error message.
Error:Conflict with dependency 'com.android.support:support-v4'. Resolved versions for app (24.2.0) and test app (23.1.1) differ. See http://g.co/androidstudio/app-test-app-conflict for details.
So How can I fix this?
Also this page the 2nd answer down gives a solution to the problem but if you want to include
com.android.support.test.espresso:espresso-contrib:2.2.2
in your then this will lead to 4 more similar error messages.
So How can I get rid of these 4 extra error messages?
Here are my Espresso build.gradle dependencies:
androidTestCompile "com.android.support:support-annotations:$SUPPORT_VERSION"
androidTestCompile "com.android.support.test.espresso:espresso-core:$ESPRESSO_VERSION"
androidTestCompile 'com.android.support.test:runner:0.5'
androidTestCompile "com.android.support.test.espresso:espresso-intents:$ESPRESSO_VERSION"
/**
* AccessibilityChecks
* CountingIdlingResource
* DrawerActions
* DrawerMatchers
* PickerActions (Time and Date picker)
* RecyclerViewActions
*/
androidTestCompile("com.android.support.test.espresso:espresso-contrib:$ESPRESSO_VERSION") {
exclude group: 'com.android.support', module: 'appcompat'
exclude group: 'com.android.support', module: 'support-v4'
exclude group: 'com.android.support', module: 'support-v7'
exclude group: 'com.android.support', module: 'design'
exclude module: 'support-annotations'
exclude module: 'recyclerview-v7'
}
where:
ESPRESSO_VERSION = '2.2.2'
Check my project's build.gradle file if you still stuck: https://github.com/piotrek1543/LocalWeather/blob/master/app/build.gradle
Hope it will help
I found a solution (workaround)
If you click on the picture below you will note look at the picture below you will note that the error message
Error:Conflict with dependency 'com.android.support:support-v4'. Resolved versions for app (24.2.0) and test app (23.1.1) differ. See http://g.co/androidstudio/app-test-app-conflict for details.
will be fixed with the line
configurations.all {resolutionStrategy.force "com.android.support:support-v4:23.1.0"}
Which is located in the dependencies area of the gradle file
Likewise the error message
Error:Conflict with dependency 'com.android.support:appcompat-v7'. Resolved versions for app (24.2.0) and test app (23.1.0) differ. See http://g.co/androidstudio/app-test-app-conflict for details.
can be fixed with the line
configurations.all {resolutionStrategy.force "com.android.support:appcompat-v7:23.1.0"}
And so on and so fourth until all the errors are solved
p.s Don't forget to go here for the main solution (2nd and 3rd answer down
You can force the support library in your test using:
androidTestCompile 'com.android.support:support-v4:24.2.0'
Note: I know there are a thousand questions about this error on SO, and I swear I've read all of them, but none of the solutions have worked. (More detail on my many unsuccessful attempts below.)
When I try to build my cordova app for Android, I get the following error:
:processDebugResources FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':processDebugResources'.
> Error: more than one library with package name 'com.google.android.gms'
You can temporarily disable this error with android.enforceUniquePackageName=false
However, this is temporary and will be enforced in 1.0
My question: How can I fix this and build my app?
Background
From the many SO answers I've read, I know this is almost certainly a problem with plugins adding duplicate Google Play dependencies. My app (and all its plugins) were working great until my most recent plugin addition: the Urban Airship cordova plugin. Here is my current plugin list:
cc.fovea.cordova.purchase 4.0.0 "Purchase"
com.xmartlabs.cordova.market 1.1 "Market"
cordova-google-play-services 25.0.0 "Google Play Services for Android"
cordova-plugin-analytics 1.3.3 "Google Analytics Plugin"
cordova-plugin-console 1.0.2 "Console"
cordova-plugin-device 1.1.0 "Device"
cordova-plugin-dialogs 1.2.0 "Notification"
cordova-plugin-file 3.0.0 "File"
cordova-plugin-inappbrowser 1.1.1 "InAppBrowser"
cordova-plugin-network-information 1.1.0 "Network Information"
cordova-plugin-splashscreen 3.0.0 "Splashscreen"
cordova-plugin-statusbar 2.0.0 "StatusBar"
cordova-plugin-whitelist 1.2.0 "Whitelist"
cordova-plugin-x-socialsharing 5.0.7.1 "SocialSharing"
cordova-plugin-x-toast 2.3.1 "Toast"
urbanairship-cordova 4.0.1 "Urban Airship"
I've read through every plugin's plugin.xml, and the only other one which references Google Play Services is Appfeel's cordova-plugin-analytics.
I'm using cordova 5.4.1 and cordova-android#4.1.1. Here is my config.xml. I'm not using an IDE.
Also, another answer recommended investigating the compile dependencies and looking for duplicates using ./gradlew dependencies. Doing so gave me this output. As you can see, it has many duplicates: lots of com.google.android.gms and lots of com.android.support and lots of CordovaLib.
What I've tried
Removing and re-adding the Android platform. It changed nothing.
Removing and re-adding cordova-google-play-services. I was unable to remove it and got the following error:
Error: The plugin 'cordova-google-play-services' is required by (cordova-plugin-analytics), skipping uninstallation.
(I did not install cordova-google-play-services explicitly – it was installed automatically by cordova-plugin-analytics.)
Earlier in my project I tried to use the more common analytics plugins by danwilson and cmackay, but I ran into similar issues just installing those plugins, which is why I'm now using Appfeel's Google Analytics plugin (which installed without problems and works great).
Adding a build-extras.gradle in /platforms/android with the following code:
configurations {
all*.exclude group: 'com.android.support', module: 'support-v4'
all*.exclude group: 'com.google.android.gms', module: 'play-services-analytics'
}
When I run this, I do avoid the "more than one library" error, but instead I get dozens of package-does-not-exist errors like this one:
:compileDebugJava
/Users/sarah/Development/app/platforms/android/src/com/urbanairship/cordova/CordovaAutopilot.java:31: error: package android.support.v4.app does not exist
import android.support.v4.app.NotificationCompat;
^
I've also tried a variety of other exclusion combinations that were motivated from the ./gradlew dependencies output I mentioned above.
Updating the Android platform, updating cordova
Making sure I have the most current version of gradle
Updating everything I can in the Android SDK Manager. Here's a screenshot of the Extras I have installed. And a screenshot of Tools. And other SDK packages.
Adding a build-extras.gradle that uses dependencies with exclusions instead of configurations. I've tried about twenty different combinations of packages and groups and modules (again motivated by the ./gradlew dependencies output) . Sometimes I try excluding only groups or only modules. Sometimes I try excluding with or without the version numbers. (As you can see, I don't really know what I'm doing re:gradle.) Here's one attempt:
dependencies {
compile('com.urbanairship.android:urbanairship-sdk:6.4.1') {
exclude group: 'com.google.android.gms', module: 'play-services-base'
exclude group: 'com.google.android.gms', module: 'play-services-basement'
exclude group: 'com.android.support', module: 'support-v4'
}
}
Here's another:
dependencies {
compile('com.urbanairship.android:urbanairship-sdk:6.4.1') {
exclude group: 'com.google.android.gms', module: 'play-services-base'
exclude group: 'com.google.android.gms', module: 'play-services-maps'
exclude group: 'com.google.android.gms', module: 'play-services-basement'
exclude group: 'com.android.support', module: 'support-v4'
}
compile('com.google.android.gms:play-services-location:8.1.0') {
exclude group: 'com.google.android.gms', module: 'play-services-base'
exclude group: 'com.google.android.gms', module: 'play-services-maps'
exclude group: 'com.google.android.gms', module: 'play-services-basement'
exclude group: 'com.android.support', module: 'support-v4'
}
compile('com.android.support:cardview-v7:23.1.0') {
exclude group: 'com.android.support', module: 'support-v4'
}
}
In my research I discovered that the Urban Airship plugin has its own build-extras.gradle in /platforms/android/urbainairship-cordova. So I tried adding compile exclusions to that build-extras.gradle instead using a zillion combinations like those I mentioned in #7. Eventually I exclude too much and end up with package-does-not-exist errors like those shown in #3, but backing off results in the same more-than-one-library error.
Commenting out <dependency id="cordova-google-play-services" /> in the analytics plugin's plugin.xml.
My question
Sorry for the long post, but this all seems like relevant troubleshooting info! To restate my question from the beginning: how do I fix this error and build successfully?
I ran into this recently with com.android.support conflicts and (for that)
I would highly recommend https://github.com/dpa99c/cordova-android-support-gradle-release which is a "plugin to align various versions of the Android Support libraries specified by other plugins".
To avoid the problem of removing all versions of the support libs, which can lead plugins having missing dependencies/failing gradle syncs, they use some clever gradle dependency resolution to solve the problem:
configurations.all {
resolutionStrategy.eachDependency { DependencyResolveDetails details ->
if (details.requested.group in ['com.android.support'] && !(details.requested.name in ['multidex', 'multidex-instrumentation'])) { details.useVersion "26.1.0"}
}
}
I reckon you could do the same for your Google Plays Services libs by adding another inner condition:
if (details.requested.group in ['com.google.android.gms'] && !(details.requested.name in ['multidex', 'multidex-instrumentation'])) {
details.useVersion "11.8.0" //Or whichever GMS level you're targeting.
}
Currently I am trying to test the views using RecyclerView. The app works great, but in the test, it doesn't, it couldn't find method of RecyclerView, the followings are the dependencies in the test file
androidTestCompile ('com.android.support.test.espresso:espresso-core:2.0') {
exclude group: 'javax.inject'
exclude group: 'com.google.code.findbugs'
exclude group: 'com.android.support', module: 'support-v4'
}
androidTestCompile('com.android.support.test.espresso:espresso-contrib:2.0') {
exclude group: 'javax.inject'
exclude group: 'com.google.guava'
exclude group: 'com.android.support', module: 'support-annotations'
exclude module: 'recyclerview-v7'
}
And I got errors when I was using RecyclerViewActions.actionOnItemAtPosition and it will call RecyclerView's scrollToPosition() method. But it complains that it couldn't find this method:
java.lang.NoSuchMethodError: android.support.v7.widget.RecyclerView.scrollToPosition
at android.support.test.espresso.contrib.RecyclerViewActions$ScrollToPositionViewAction.perform(RecyclerViewActions.java:397)
at android.support.test.espresso.contrib.RecyclerViewActions$ActionOnItemAtPositionViewAction.perform(RecyclerViewActions.java:277)
at android.support.test.espresso.ViewInteraction$1.run(ViewInteraction.java:144)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:422)
....
I assume the problem is, since it works fine in the app, that in the test, it might use the older version than the app. And for test dependency, the version for recyclerView is 21.0.3 and app version is 22.2.0. However, after I change the app version of RecyclerView to 21.0.3 (same as in test), it still has same error.
Much appreciate any comments
Ok, after two days of searching, finally I found the solution. It has something to do with Proguard. It turns out that the RecyclerView is obfuscated by Android Proguard. Thats the reason why Espresso cannot find this method.
Just simply add
-keep class android.support.v7.widget.RecyclerView { *; }
in proguard-rules.text and then you are all set.