Can't make Appium work with Compose 1.2.0 - java.lang.AbstractMethodError: abstract method "kotlin.coroutines.CoroutineContext$Key androidx.compose.ui.platform.InfiniteAnimationPolicy.getKey()"
I'm using latest beta versions of appium (Appium v2.0.0-beta.42) and espresso driver, but I can't make it work with compose app. I've tried even on empty compose Hello world project generated by Android studio (using compose version 1.2.0), but the appium still throws this error:
[debug] [EspressoDriver@d452 (d7e46f24)] [Instrumentation] io.appium.espressoserver.EspressoServerRunnerTest: [debug] [EspressoDriver@d452 (d7e46f24)] [Instrumentation] Error in startEspressoServer(io.appium.espressoserver.EspressoServerRunnerTest): [debug] [EspressoDriver@d452 (d7e46f24)] java.lang.AbstractMethodError: abstract method "kotlin.coroutines.CoroutineContext$Key androidx.compose.ui.platform.InfiniteAnimationPolicy.getKey()" [debug] [EspressoDriver@d452 (d7e46f24)] at kotlin.coroutines.CoroutineContext$plus$1.invoke(CoroutineContext.kt:33) [debug] [EspressoDriver@d452 (d7e46f24)] at kotlin.coroutines.CoroutineContext$plus$1.invoke(CoroutineContext.kt:32) [debug] [EspressoDriver@d452 (d7e46f24)] at kotlin.coroutines.CoroutineContext$Element$DefaultImpls.fold(CoroutineContext.kt:70) [debug] [EspressoDriver@d452 (d7e46f24)] at androidx.compose.ui.platform.InfiniteAnimationPolicy$DefaultImpls.fold(InfiniteAnimationPolicy.kt:36) [debug] [EspressoDriver@d452 (d7e46f24)] at androidx.compose.ui.test.AndroidComposeUiTestEnvironment$infiniteAnimationPolicy$1.fold(ComposeUiTest.android.kt:239) [debug] [EspressoDriver@d452 (d7e46f24)] at kotlin.coroutines.CoroutineContext$DefaultImpls.plus(CoroutineContext.kt:32) [debug] [EspressoDriver@d452 (d7e46f24)] at kotlin.coroutines.CombinedContext.plus(CoroutineContextImpl.kt:111) [debug] [EspressoDriver@d452 (d7e46f24)] at androidx.compose.ui.test.AndroidComposeUiTestEnvironment.<init>(ComposeUiTest.android.kt:248) [debug] [EspressoDriver@d452 (d7e46f24)] at androidx.compose.ui.test.junit4.AndroidComposeTestRule$special$$inlined$AndroidComposeUiTestEnvironment$1.<init>(ComposeUiTest.android.kt:203) [debug] [EspressoDriver@d452 (d7e46f24)] at androidx.compose.ui.test.junit4.AndroidComposeTestRule.<init>(AndroidComposeTestRule.android.kt:212) [debug] [EspressoDriver@d452 (d7e46f24)] at io.appium.espressoserver.EspressoServerRunnerTest.<init>(EspressoServerRunnerTest.kt:45)
Did anyone make appium espresso work with Compose?
What version of library versions did you provide? https://github.com/appium/appium-espresso-driver#espresso-build-config
The espresso driver's dependencies are https://github.com/appium/appium-espresso-driver/blob/master/espresso-server/app/build.gradle.kts , so I guess you may need to add/update dependencies to fit for your test app configuration
Library versions I provided so they would match versions in tested application
{
""gradle"": ""7.4.2"",
""androidGradlePlugin"": ""7.2.1"",
""compileSdk"": 32,
""buildTools"": ""30.0.3"",
""minSdk"": 23,
""targetSdk"": 31,
""kotlin"": ""1.7.0"",
""composeVersion"": ""1.2.0""
}
Thanks, what kind of dependencies in your app under test uses? I wonder if some of them are missing/incompatible with https://github.com/appium/appium-espresso-driver/blob/60fd5887ee12326f2386bea42b034d3ff60cf35d/espresso-server/app/build.gradle.kts#L130-L134 etc. Then, could you try to modify the build.gradle.kts directly?
Hey @KazuCocoa, while trying to run Appium Espresso Driver Sessions on one of the sample jetpack compose sample apps (specifically Owl App). Found the exact same error loglines:
2022-09-07 05:30:49:122 - [debug] [EspressoDriver@804f (35dc2741)] [Instrumentation] Error in startEspressoServer(io.appium.espressoserver.EspressoServerRunnerTest):
2022-09-07 05:30:49:122 - [debug] [EspressoDriver@804f (35dc2741)] java.lang.AbstractMethodError: abstract method "kotlin.coroutines.CoroutineContext$Key androidx.compose.ui.platform.InfiniteAnimationPolicy.getKey()"
A Generic Question: How do we know what dependencies are missing/incompatible, in case of such errors?
Appium Logs gist
Appium Version: 1.22.0
Appium Espresso Driver Version: 2.5.0
EspressoBuildConfig:
{
"additionalAppDependencies": [
"org.jetbrains.kotlinx:kotlinx-coroutines-android:1.6.1",
"org.jetbrains.kotlinx:kotlinx-coroutines-core:1.6.1",
],
"toolsVersions": {
"composeVersion": "1.2.0",
"compileSdk": "32",
}
}
https://github.com/appium/appium-espresso-driver/blob/master/espresso-server/app/build.gradle.kts is what appium espresso server resolves dependencies by default, so what dependencies are missing/incompatible is generally you may need to compare the dependencies between your production code and the espresso server.
Probably https://github.com/android/compose-samples/blob/70d05efe9c5de6d3788ac3c6023caa20761d410a/Owl/gradle/libs.versions.toml is the dependency. I haven't deeply compared, but maybe you can try to set the same version of dependencies, missing ones as espresso config
@radimjanda754 Have you resolved this issue ? Can you post your solution ?
@KazuCocoa I have uploaded the sample to test Appium Espresso with the blank Android project. I have cloned both Android and the Espresso server projects, also create the script to run. Can you help me to find out what I was wrong ?
https://github.com/toantk238/Test-Appium-Espresso-Driver
Let me take a look by finding a chance
@rock-tran unfortunately we still didn't manage to fix this issue. We are just trying different versions of appium driver (beta, rc) and some it works on some simple apps, but so far it never worked on the app we want to test.
Thanks for posting sample project, it would be really nice if @KazuCocoa came up with something
Tried a bit last night. Still getting a weird error, so need to take a look further though. It seems like the compose also has complicated dependencies... (based on https://github.com/toantk238/Test-Appium-Espresso-Driver)
1) startEspressoServer(io.appium.espressoserver.EspressoServerRunnerTest)
java.lang.IllegalStateException: The application under test must require android.permission.INTERNET permission in its manifest
at io.appium.espressoserver.lib.http.Server.start(Server.kt:93)
at io.appium.espressoserver.EspressoServerRunnerTest.startEspressoServer(EspressoServerRunnerTest.kt:67)
... 53 trimmed
Caused by: java.net.BindException: bind failed: EADDRINUSE (Address already in use)
at libcore.io.IoBridge.bind(IoBridge.java:108)
at java.net.PlainSocketImpl.socketBind(PlainSocketImpl.java:162)
at java.net.AbstractPlainSocketImpl.bind(AbstractPlainSocketImpl.java:427)
at java.net.ServerSocket.bind(ServerSocket.java:377)
at java.net.ServerSocket.bind(ServerSocket.java:331)
at fi.iki.elonen.NanoHTTPD$ServerRunnable.run(NanoHTTPD.java:1761)
at java.lang.Thread.run(Thread.java:923)
Caused by: android.system.ErrnoException: bind failed: EADDRINUSE (Address already in use)
at libcore.io.Linux.bind(Native Method)
at libcore.io.ForwardingOs.bind(ForwardingOs.java:74)
at libcore.io.ForwardingOs.bind(ForwardingOs.java:74)
at libcore.io.IoBridge.bind(IoBridge.java:104)
... 6 more
FAILURES!!!
Tests run: 1, Failures: 1
(headspin) kazu$ git diff
diff --git a/android_app/app/src/main/AndroidManifest.xml b/android_app/app/src/main/AndroidManifest.xml
index 8d1f774..aa5abe7 100644
--- a/android_app/app/src/main/AndroidManifest.xml
+++ b/android_app/app/src/main/AndroidManifest.xml
@@ -2,6 +2,9 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">
+ <uses-permission android:name="android.permission.INTERNET" />
+ <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
+
<application
android:allowBackup="true"
android:dataExtractionRules="@xml/data_extraction_rules"
diff --git a/android_test/app/build.gradle.kts b/android_test/app/build.gradle.kts
index 9b757ec..c445c57 100644
--- a/android_test/app/build.gradle.kts
+++ b/android_test/app/build.gradle.kts
@@ -4,7 +4,7 @@ plugins {
}
android {
- compileSdk = getIntProperty("appiumCompileSdk", 32)
+ compileSdk = getIntProperty("appiumCompileSdk", 33)
buildToolsVersion = getStringProperty("appiumBuildTools", "32.0.0")
defaultConfig {
// <instrumentation android:targetPackage=""/>
@@ -48,6 +48,14 @@ android {
keyPassword = "android"
}
}
compileOptions {
sourceCompatibility = JavaVersion.VERSION_11
@@ -110,15 +118,8 @@ dependencies {
androidTestImplementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8:${kotlinVersion}")
androidTestImplementation("org.jetbrains.kotlin:kotlin-reflect:${kotlinVersion}")
androidTestImplementation("androidx.compose.ui:ui-test:${composeVersion}")
- androidTestImplementation("androidx.compose.ui:ui-test-junit4:${composeVersion}") {
- isTransitive = false
- }
-
- // additionalAndroidTestDependencies placeholder (don't change or delete this line)
- androidTestImplementation("org.jetbrains.kotlinx:kotlinx-coroutines-test:1.6.4")
- androidTestImplementation("androidx.compose.ui:ui-test-manifest:1.2.1")
- androidTestImplementation("androidx.test.ext:junit:1.1.3")
- androidTestImplementation("com.google.truth:truth:1.1.3")
+ androidTestImplementation("androidx.compose.ui:ui-test-junit4:${composeVersion}")
+ androidTestImplementation("androidx.compose.ui:ui-test-manifest:${composeVersion}")
}
configurations.all {
@@ -141,7 +142,7 @@ object Version {
const val gson = "2.9.0"
const val uia = "2.2.0"
const val nanohttpd = "2.3.1"
- const val annotation = "1.3.0"
+ const val annotation = "1.2.0"
const val mockito = "4.0.0"
const val robolectric = "4.5.1"
const val junit = "4.13.2"
diff --git a/test.sh b/test.sh
index 60daf8c..6149578 100755
I fixed this by forcing androidx.compose.ui to 1.2.1, looks like there was a dependency conflict between testing and runtime deps
Hi there! I'm facing same issue i'm using: Espresso Server v2.12.0 (same story with 2.13.0) Appium v1.22.3
"fix" from chrisjenx doesn't help(
any ideas?)
For me setting androidx.compose.ui to 1.2.1 and setting minSdk to 24 (or newer) helps with the compose issue. I have set these versions in APK and toolsVersions too.
However the Appium still doesn't work, as I'm already facing another weird issue while trying to run the tests:
java.lang.AbstractMethodError: abstract method "androidx.lifecycle.ViewModel androidx.lifecycle.ViewModelProvider$Factory.create(java.lang.Class)"
at androidx.lifecycle.ViewModelProvider.get(ViewModelProvider.java:187)
at androidx.lifecycle.SavedStateHandleSupport.getSavedStateHandlesVM(SavedStateHandleSupport.kt:109)
at androidx.lifecycle.SavedStateHandlesProvider$viewModel$2.invoke(SavedStateHandleSupport.kt:134)
at androidx.lifecycle.SavedStateHandlesProvider$viewModel$2.invoke(SavedStateHandleSupport.kt:133)
at kotlin.SynchronizedLazyImpl.getValue(LazyJVM.kt:74)
at androidx.lifecycle.SavedStateHandlesProvider.getViewModel(SavedStateHandleSupport.kt:133)
at androidx.lifecycle.SavedStateHandlesProvider.performRestore(SavedStateHandleSupport.kt:168)
at androidx.lifecycle.SavedStateHandleAttacher.onStateChanged(SavedStateHandleSupport.kt:199)
at androidx.lifecycle.LifecycleRegistry$ObserverWithState.dispatchEvent(LifecycleRegistry.java:354)
at androidx.lifecycle.LifecycleRegistry.forwardPass(LifecycleRegistry.java:265)
at androidx.lifecycle.LifecycleRegistry.sync(LifecycleRegistry.java:307)
at androidx.lifecycle.LifecycleRegistry.moveToState(LifecycleRegistry.java:148)
at androidx.lifecycle.LifecycleRegistry.handleLifecycleEvent(LifecycleRegistry.java:134)
Tried a bit last night. Still getting a weird error, so need to take a look further though. It seems like the compose also has complicated dependencies... (based on https://github.com/toantk238/Test-Appium-Espresso-Driver)
1) startEspressoServer(io.appium.espressoserver.EspressoServerRunnerTest) java.lang.IllegalStateException: The application under test must require android.permission.INTERNET permission in its manifest at io.appium.espressoserver.lib.http.Server.start(Server.kt:93) at io.appium.espressoserver.EspressoServerRunnerTest.startEspressoServer(EspressoServerRunnerTest.kt:67) ... 53 trimmed Caused by: java.net.BindException: bind failed: EADDRINUSE (Address already in use) at libcore.io.IoBridge.bind(IoBridge.java:108) at java.net.PlainSocketImpl.socketBind(PlainSocketImpl.java:162) at java.net.AbstractPlainSocketImpl.bind(AbstractPlainSocketImpl.java:427) at java.net.ServerSocket.bind(ServerSocket.java:377) at java.net.ServerSocket.bind(ServerSocket.java:331) at fi.iki.elonen.NanoHTTPD$ServerRunnable.run(NanoHTTPD.java:1761) at java.lang.Thread.run(Thread.java:923) Caused by: android.system.ErrnoException: bind failed: EADDRINUSE (Address already in use) at libcore.io.Linux.bind(Native Method) at libcore.io.ForwardingOs.bind(ForwardingOs.java:74) at libcore.io.ForwardingOs.bind(ForwardingOs.java:74) at libcore.io.IoBridge.bind(IoBridge.java:104) ... 6 more FAILURES!!! Tests run: 1, Failures: 1 (headspin) kazu$ git diff diff --git a/android_app/app/src/main/AndroidManifest.xml b/android_app/app/src/main/AndroidManifest.xml index 8d1f774..aa5abe7 100644 --- a/android_app/app/src/main/AndroidManifest.xml +++ b/android_app/app/src/main/AndroidManifest.xml @@ -2,6 +2,9 @@ <manifest xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools"> + <uses-permission android:name="android.permission.INTERNET" /> + <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" /> + <application android:allowBackup="true" android:dataExtractionRules="@xml/data_extraction_rules" diff --git a/android_test/app/build.gradle.kts b/android_test/app/build.gradle.kts index 9b757ec..c445c57 100644 --- a/android_test/app/build.gradle.kts +++ b/android_test/app/build.gradle.kts @@ -4,7 +4,7 @@ plugins { } android { - compileSdk = getIntProperty("appiumCompileSdk", 32) + compileSdk = getIntProperty("appiumCompileSdk", 33) buildToolsVersion = getStringProperty("appiumBuildTools", "32.0.0") defaultConfig { // <instrumentation android:targetPackage=""/> @@ -48,6 +48,14 @@ android { keyPassword = "android" } } compileOptions { sourceCompatibility = JavaVersion.VERSION_11 @@ -110,15 +118,8 @@ dependencies { androidTestImplementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8:${kotlinVersion}") androidTestImplementation("org.jetbrains.kotlin:kotlin-reflect:${kotlinVersion}") androidTestImplementation("androidx.compose.ui:ui-test:${composeVersion}") - androidTestImplementation("androidx.compose.ui:ui-test-junit4:${composeVersion}") { - isTransitive = false - } - - // additionalAndroidTestDependencies placeholder (don't change or delete this line) - androidTestImplementation("org.jetbrains.kotlinx:kotlinx-coroutines-test:1.6.4") - androidTestImplementation("androidx.compose.ui:ui-test-manifest:1.2.1") - androidTestImplementation("androidx.test.ext:junit:1.1.3") - androidTestImplementation("com.google.truth:truth:1.1.3") + androidTestImplementation("androidx.compose.ui:ui-test-junit4:${composeVersion}") + androidTestImplementation("androidx.compose.ui:ui-test-manifest:${composeVersion}") } configurations.all { @@ -141,7 +142,7 @@ object Version { const val gson = "2.9.0" const val uia = "2.2.0" const val nanohttpd = "2.3.1" - const val annotation = "1.3.0" + const val annotation = "1.2.0" const val mockito = "4.0.0" const val robolectric = "4.5.1" const val junit = "4.13.2" diff --git a/test.sh b/test.sh index 60daf8c..6149578 100755
@KazuCocoa I have updated dependencies based on your patch. Now, it hangs like this

No exception or error. Is it success or fail ?
The build itself seems ok, the above behavior is expected
@KazuCocoa I have tested appium with the test project above and it works. The env is here
{
"name": "yourapp",
"version": "0.0.1",
"dependencies": {
"appium": "2.0.0-beta.46",
"appium-doctor": "1.16.2",
"appium-espresso-driver": "2.13.5",
"appium-uiautomator2-driver": "2.10.2"
}
}
However, it still doesn't work with my project, the more complex one. I will create another issue. I think you can close this. Anyway, Thank you so much !!!
@KazuCocoa Do you have any plan to apply the patch into the repo soon ?
@KazuCocoa Has the same issue with those logs:
startEspressoServer(io.appium.espressoserver.EspressoServerRunnerTest)
[debug] [EspressoDriver@4175 (003c5052)] java.lang.AbstractMethodError: abstract method "kotlin.coroutines.CoroutineContext$Key androidx.compose.ui.platform.InfiniteAnimationPolicy.getKey()"
[debug] [EspressoDriver@4175 (003c5052)] at kotlin.coroutines.CoroutineContext$plus$1.invoke(CoroutineContext.kt:33)
[debug] [EspressoDriver@4175 (003c5052)] at kotlin.coroutines.CoroutineContext$plus$1.invoke(CoroutineContext.kt:32)
[debug] [EspressoDriver@4175 (003c5052)] at kotlin.coroutines.CoroutineContext$Element$DefaultImpls.fold(CoroutineContext.kt:70)
[debug] [EspressoDriver@4175 (003c5052)] at androidx.compose.ui.platform.InfiniteAnimationPolicy$DefaultImpls.fold(InfiniteAnimationPolicy.kt:36)
[debug] [EspressoDriver@4175 (003c5052)] at androidx.compose.ui.test.AndroidComposeUiTestEnvironment$infiniteAnimationPolicy$1.fold(ComposeUiTest.android.kt:239)
[debug] [EspressoDriver@4175 (003c5052)] at kotlin.coroutines.CoroutineContext$DefaultImpls.plus(CoroutineContext.kt:32)
[debug] [EspressoDriver@4175 (003c5052)] at kotlin.coroutines.CombinedContext.plus(CoroutineContextImpl.kt:111)
[debug] [EspressoDriver@4175 (003c5052)] at androidx.compose.ui.test.AndroidComposeUiTestEnvironment.
I wondered if https://github.com/appium/appium-espresso-driver/pull/875 fixes this error in some cases.
At least regular our espresso tests with https://github.com/appium/appium-espresso-driver/tree/master/test/assets (except for old compose test app) fixed the Error in startEspressoServer(io.appium.espressoserver.EspressoServerRunnerTest): message with compse 1.4.3 dependency.
appium espresso driver 2.22.0 has the fix I found. Newer compose may work in some environments