I am using Junit4 and Espresso for my tests. I am facing a weird issue with espresso tests - when I call onView sometimes everything is executed like it is supposed to, but sometimes my test freezes and after 60 seconds I get something like this "android.support.test.espresso.AppNotIdleException: Looped for 63 iterations over 60 SECONDS. The following Idle Conditions failed ASYNC_TASKS_HAVE_IDLED"
For example :
onView(withId(R.id.zone_button_continue)).perform(click());
onView(withId(R.id.loginButton)).check(matches(isDisplayed()));
onView(withId(R.id.number)).check(matches(isDisplayed()));
onView(withId(R.id.password)).check(matches(isDisplayed()));
onView(withId(R.id.number)).perform(typeText(phoneNumber));
onView(withId(R.id.password)).perform(typeText(password));
onView(withId(R.id.loginButton)).perform(click());
everything gets executed correctly, except the last line - for some reason it can't find that loginButton, but it is there 100% percent. I can do
activity.runOnUiThread(new Runnable() {
#Override
public void run() {
activity.findViewById(R.id.loginButton).performClick();
}
});
and that works. I have similar problems throughout most of my activities - sometimes onView is working sometimes not.
What could cause such an inconsistency? I have been fighting with this issue for a while, and it makes my testing very frustrating and difficult. My conclusions this far is that something is wrong with my gradle dependencies or there is some kind of bug in my application that prevents espresso to work properly. But it is strange that in the example above everything with onView is working except last line and everything is happening in one activity and that makes me doubt that the bug is within my application.
Here are my gradle dependencies:
compile files('src/main/libs/guice-3.0-no_aop.jar')
compile files('src/main/libs/javax.inject-1.jar')
compile files('src/main/libs/roboguice-2.0.jar')
compile files('src/main/libs/junit-4.11.jar')
compile files('src/main/libs/hamcrest-core-1.3.jar')
compile files('src/main/libs/GeoLib.jar')
compile files('src/main/libs/GeoPolygons.jar')
compile files('src/main/libs/universal-image-loader-1.9.4.jar')
compile files('src/main/libs/javax.annotation-3.2-b06-sources.jar')
compile ('uk.co.chrisjenx:calligraphy:2.1.0'){
exclude group:'com.android.support'
}
compile 'com.squareup:otto:1.3.5'
compile ('com.google.android.gms:play-services:6.5.87'){
exclude group:'com.android.support'
}
compile 'com.android.support:support-annotations:22.2.1'
compile ('com.android.support:appcompat-v7:22.2.0'){
exclude group:'com.android.support'
}
compile ('com.android.support:support-v4:22.2.0'){
exclude group:'com.android.support', module:'support-annotations'
}
compile ('com.android.support:palette-v7:22.2.0'){
exclude group:'com.android.support'
}
compile 'com.google.code.findbugs:jsr305:2.0.1'
compile 'com.nineoldandroids:library:2.4.0'
compile 'pl.charmas.android:android-reactive-location:0.4#aar'
compile 'io.reactivex:rxjava:1.0.3'
compile files('src/main/libs/FlurryAnalytics-6.1.0.jar')
compile 'com.github.castorflex.smoothprogressbar:library:1.1.0'
// androidTestCompile 'com.android.support.test:testing-support-lib:0.1'
androidTestCompile('com.android.support.test:runner:0.4.1') {
exclude group: 'com.android.support', module: 'support-annotations'
}
// Set this dependency to use JUnit 4 rules
androidTestCompile('com.android.support.test:rules:0.4.1') {
exclude group: 'com.android.support', module: 'support-annotations'
}
// Set this dependency to build and run Espresso tests
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.1') {
exclude group: 'com.android.support', module: 'support-annotations'
}
androidTestCompile('com.android.support.test.espresso:espresso-intents:2.2.1') {
exclude group: 'com.android.support', module: 'support-annotations'
}
androidTestCompile('com.android.support.test.espresso:espresso-web:2.2.1') {
// PackagingOptions modified to make this work
exclude group: 'com.android.support', module: 'support-annotations'
}
testCompile 'junit:junit:4.11'
testCompile ('org.mockito:mockito-core:1.9.5'){
exclude group: 'org.hamcrest'
}
compile 'org.mod4j.org.apache.commons:lang:2.1.0'
Please help me with this problem, I am completely out of ideas and stuck with it.
The easiest way to see why you get an AppNotIdleExceptionwith the message "The following Idle Conditions failed ASYNC_TASKS_HAVE_IDLED", is to:
Run the tests in debug mode in Android Studio
Wait until the tests hang
Before the (default) 60 seconds have passed, pause the tests
Look in the "Threads" list and see your threads named "AsyncTask #1" and so on. Expand the one being in state RUNNING. There you see what part of the code is keeping the app busy
This was the result for my case, so I had to disable the Facebook SDK for my tests to make them stable again:
Had the same problem, also a bug with facebook libraries.
Switched to a different emulated device and everything works normally!
Related
I completely new to Android Development and can't seem to resolve this error:
"Error: Program type already present: android.support.v4.media.MediaBrowserCompat$CustomActionCallback"
This is my dependencies:
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'androidx.appcompat:appcompat:1.0.0-alpha1'
implementation 'androidx.constraintlayout:constraintlayout:1.1.2'
implementation 'androidx.lifecycle:lifecycle-extensions:2.0.0-alpha1'
implementation 'androidx.legacy:legacy-support-v4:1.0.0-alpha1'
implementation "android.arch.navigation:navigation-fragment:1.0.0-alpha01"
implementation "android.arch.navigation:navigation-ui:1.0.0-alpha01"
androidTestImplementation 'androidx.test:runner:1.1.0-alpha3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.0-alpha3'
testImplementation 'junit:junit:4.12'
}
I've googled some and ended up on the developer page about "Resolve duplicate class errors", but I'm still not able to fix this. Help would be very much appriciated!
Option 1
Following worked for me
Add the following in your gradle.properties file
android.useAndroidX = true
android.enableJetifier = false
Option 2 (if above does't work)
Android studio -> Navigate -> Class
Check include non-project classes
Copy full class path android.support.v4.accessibilityservice.AccessibilityServiceInfoCompat
See where it is used. You may need to remove, one of them.
Option 3
you might be including package which is including modules as well so exclude the support-v4 module with following method
implementation ('org.eclipse.paho:org.eclipse.paho.android.service:1.0.2') {
exclude group: 'com.android.support', module:'support-v4'
}
You can analyze the conflicting modules using ./gradlew :YOURPROJECT:dependencies from a command line in your project repository.
Check especially your third party libraries for occurences of "com.android.support-":
Then exclude the conflicting modules from these dependencies like:
implementation ("com.jakewharton:butterknife:8.8.1") {
exclude group: 'com.android.support', module: 'support-v4'
exclude group: 'com.android.support', module: 'support-annotation'
exclude group: 'com.android.support', module: 'support-compat'
}
Im using flutter, and Im adding some native libraries in android, I tried the solutions posted here, but the trick for me was android.enableJetifier = true instead false
So, adding the following code to the gradle.properties, my apps are running:
android.useAndroidX = true
android.enableJetifier = true
if you still getting error after
# gradle.properties
android.useAndroidX = true
android.enableJetifier = false
then you probably forgot about main activity that calling android.support.v7.app.AppCompatActivity
change it to androidx.appcompat.app.AppCompatActivity
adding following plugins
cordova plugin add cordova-plugin-androidx
cordova plugin add cordova-plugin-androidx-adapter
solved the problem for me
At least for me the issue was with the implementation 'androidx.legacy:legacy-support-v4:1.0.0-alpha1' dependency. I went into the menu in Android Studio to create a Blank Fragment in Kotlin just to see what that would look like and the dependency above was added.
Once i removed that dependency the error went away.
Some of your existing dependencies are using older versions of support library, try this
implementation 'androidx.legacy:legacy-support-v4:1.0.0-alpha1' {
exclude group: 'com.android.support'
exclude module: 'support-v4'
}
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'
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.
Here is part of my build.gradle that has conflict:
...
dependencies {
classpath 'com.android.tools.build:gradle:1.1.1'
}
...
testCompile( 'com.squareup.assertj:assertj-android:1.0.0' )
...
The issue that I see in log:
WARNING: Conflict with dependency 'com.android.support:support-annotations'. Resolved versions for app (21.0.3) and test app (20.0.0) differ.
Apparently it removes conflicting dependency from the classpath. I'm not sure if it is gradle or android gradle plugin.
I've tried next:
testCompile( 'com.squareup.assertj:assertj-android:1.0.0' ) {
exclude group: 'com.android.support', module: 'support-annotations'
}
But I still have compilation errors so dependency is excluded.
I've tried next:
configurations.all {
resolutionStrategy {
// fail eagerly on version conflict (includes transitive dependencies)
// e.g. multiple different versions of the same dependency (group and name are equal)
failOnVersionConflict()
// force certain versions of dependencies (including transitive)
// *append new forced modules:
force 'com.android.support:support-annotations:21.0.3'
// *replace existing forced modules with new ones:
forcedModules = ['com.android.support:support-annotations:21.0.3']
}
}
But looks like it doesn't work since it is not failing on the first conflict and I still have compilation errors.
What will be your suggestions?
UPDATE What do I mean by removing dependency - I see a lot of compile errors that assertj not found
I ran into the same issue. This fixed it for me:
testCompile('com.squareup.assertj:assertj-android:1.0.0'){
exclude group: 'com.android.support', module:'support-annotations'
}
The accepted answer didn't work for me. However, adding the following did work for me:
androidTestCompile 'com.android.support:support-annotations:23.0.1'
and:
testCompile 'com.android.support:support-annotations:23.0.1'
Based on https://stackoverflow.com/a/29947562/2832027
You need to change:
testCompile( 'com.squareup.assertj:assertj-android:1.0.0' ) {
exclude group: 'com.android.support', module: 'support-annotations'
}
to:
compile('com.squareup.assertj:assertj-android:1.0.0') {
exclude group: 'com.android.support', module: 'support-annotations'
}
Also ensure that your test folder is called test and not androidTest