appium / appium-espresso-driver

Espresso integration for Appium
Apache License 2.0
190 stars 75 forks source link

Espresso server crashes with error #853

Closed jamesvanhorn closed 1 year ago

jamesvanhorn commented 1 year ago

Appium version: 2.0.0-beta.53 Espresso driver version: espresso@2.15.1

Issue: Seems like our app developers added some new dependencies which are breaking things. Espresso server and session starts, but then fails with a cryptic error message I haven't been able to solve. Seems like we need to add some new additionalAppDependency but I can't figure out what.

Capabilities

{
  "appium:udid": "emulator-5554",
  "platformName": "Android",
  "appium:automationName": "Espresso",
  "appium:deviceName": "Pixel",
  "appium:app": "/Users/jamesvanhorn/Desktop/app-flagship-debug.apk",
  "appium:forceEspressoRebuild": true,
  "appium:showGradleLog": true,
  "appium:espressoBuildConfig": "{   \"toolsVersions\": {     \"compileSdk\": \"33\",     \"kotlin\": \"1.6+\"   },   \"additionalAppDependencies\": [     \"androidx.activity:activity-compose:1.6.0\",     \"androidx.appcompat:appcompat:1.5.1\"  ] }"
}

Error snippet:

[debug] [EspressoDriver@cc44 (ff7ee118)] [Instrumentation] Process crashed while executing startEspressoServer(io.appium.espressoserver.EspressoServerRunnerTest):
[debug] [EspressoDriver@cc44 (ff7ee118)] java.lang.UnsatisfiedLinkError: couldn't find DSO to load: libyoga.so
[debug] [EspressoDriver@cc44 (ff7ee118)]    SoSource 0: com.facebook.soloader.DirectorySoSource[root = /data/app/~~hyYcdiVKWaHUGT0eY2E_ag==/com.weather.sdui-OhynZbvsu2MRaQz1nY_g9g==/lib/x86_64 flags = 0]
[debug] [EspressoDriver@cc44 (ff7ee118)]    SoSource 1: com.facebook.soloader.DirectApkSoSource[root = /data/app/~~4nZN1WxizfyWMH5L_6KJPQ==/io.appium.espressoserver.test-q7JhO73seiwQboxRlemqrA==/base.apk!/lib/x86_64]
[debug] [EspressoDriver@cc44 (ff7ee118)]    SoSource 2: com.facebook.soloader.DirectorySoSource[root = /system/lib64 flags = 2]
[debug] [EspressoDriver@cc44 (ff7ee118)]    SoSource 3: com.facebook.soloader.DirectorySoSource[root = /vendor/lib64 flags = 2]
[debug] [EspressoDriver@cc44 (ff7ee118)]    Native lib dir: /data/app/~~hyYcdiVKWaHUGT0eY2E_ag==/<APP PACKAGE>-OhynZbvsu2MRaQz1nY_g9g==/lib/x86_64
[debug] [EspressoDriver@cc44 (ff7ee118)]  result: 0
[debug] [EspressoDriver@cc44 (ff7ee118)]    at com.facebook.soloader.SoLoader.doLoadLibraryBySoName(SoLoader.java:1098)
[debug] [EspressoDriver@cc44 (ff7ee118)]    at com.facebook.soloader.SoLoader.loadLibraryBySoNameImpl(SoLoader.java:914)
[debug] [EspressoDriver@cc44 (ff7ee118)]    at com.facebook.soloader.SoLoader.loadLibraryBySoName(SoLoader.java:826)
[debug] [EspressoDriver@cc44 (ff7ee118)]    at com.facebook.soloader.SoLoader.loadLibrary(SoLoader.java:773)
[debug] [EspressoDriver@cc44 (ff7ee118)]    at com.facebook.soloader.SoLoader.loadLibrary(SoLoader.java:743)
[debug] [EspressoDriver@cc44 (ff7ee118)]    at com.facebook.yoga.YogaNative.<clinit>(YogaNative.java:16)
[debug] [EspressoDriver@cc44 (ff7ee118)]    at com.facebook.yoga.YogaNodeJNIBase.<init>(YogaNodeJNIBase.java:56)
[debug] [EspressoDriver@cc44 (ff7ee118)]    at com.facebook.yoga.YogaNodeJNIFinalizer.<init>(YogaNodeJNIFinalizer.java:12)
[debug] [EspressoDriver@cc44 (ff7ee118)]    at com.facebook.yoga.YogaNodeFactory.create(YogaNodeFactory.java:12)
[debug] [EspressoDriver@cc44 (ff7ee118)]    at br.com.zup.beagle.android.engine.mapper.FlexMapper.makeYogaNode(FlexMapper.kt:42)
[debug] [EspressoDriver@cc44 (ff7ee118)]    at br.com.zup.beagle.android.view.custom.InternalBeagleFlexView.<init>(InternalBeagleFlexView.kt:47)
[debug] [EspressoDriver@cc44 (ff7ee118)]    at br.com.zup.beagle.android.view.custom.InternalBeagleFlexView.<init>(InternalBeagleFlexView.kt:38)
[debug] [EspressoDriver@cc44 (ff7ee118)]    at br.com.zup.beagle.android.view.custom.BeagleView.<init>(BeagleView.kt:41)
[debug] [EspressoDriver@cc44 (ff7ee118)]    at br.com.zup.beagle.android.view.custom.BeagleView.<init>(BeagleView.kt:38)
[debug] [EspressoDriver@cc44 (ff7ee118)]    at br.com.zup.beagle.android.view.ViewFactory.makeBeagleView(ViewFactory.kt:48)
[debug] [EspressoDriver@cc44 (ff7ee118)]    at br.com.zup.beagle.android.utils.ViewGroupExtensionsKt.loadView(ViewGroupExtensions.kt:178)
[debug] [EspressoDriver@cc44 (ff7ee118)]    at br.com.zup.beagle.android.utils.ViewGroupExtensionsKt.loadView$default(ViewGroupExtensions.kt:166)
[debug] [EspressoDriver@cc44 (ff7ee118)]    at br.com.zup.beagle.android.utils.ViewGroupExtensionsKt.loadView(ViewGroupExtensions.kt:145)
[debug] [EspressoDriver@cc44 (ff7ee118)]    at br.com.zup.beagle.android.utils.ViewGroupExtensionsKt.loadView$default(ViewGroupExtensions.kt:139)
[debug] [EspressoDriver@cc44 (ff7ee118)]    at com.ibm.corgikit.view.CorgiActivity.navigateToNextScreen(CorgiActivity.kt:90)
[debug] [EspressoDriver@cc44 (ff7ee118)]    at com.ibm.corgikit.view.CorgiActivity.handleApplicationState(CorgiActivity.kt:80)
[debug] [EspressoDriver@cc44 (ff7ee118)]    at com.ibm.corgikit.view.CorgiActivity.access$handleApplicationState(CorgiActivity.kt:32)
[debug] [EspressoDriver@cc44 (ff7ee118)]    at com.ibm.corgikit.view.CorgiActivity$onCreate$1$1$1.emit(CorgiActivity.kt:66)
[debug] [EspressoDriver@cc44 (ff7ee118)]    at com.ibm.corgikit.view.CorgiActivity$onCreate$1$1$1.emit(CorgiActivity.kt:59)
[debug] [EspressoDriver@cc44 (ff7ee118)]    at kotlinx.coroutines.flow.StateFlowImpl.collect(StateFlow.kt:398)
[debug] [EspressoDriver@cc44 (ff7ee118)]    at com.ibm.corgikit.view.CorgiActivity$onCreate$1$1.invokeSuspend(CorgiActivity.kt:59)
[debug] [EspressoDriver@cc44 (ff7ee118)]    at com.ibm.corgikit.view.CorgiActivity$onCreate$1$1.invoke(Unknown Source:8)
[debug] [EspressoDriver@cc44 (ff7ee118)]    at com.ibm.corgikit.view.CorgiActivity$onCreate$1$1.invoke(Unknown Source:4)
[debug] [EspressoDriver@cc44 (ff7ee118)]    at androidx.lifecycle.RepeatOnLifecycleKt$repeatOnLifecycle$3$1$1$1$1$1$1.invokeSuspend(RepeatOnLifecycle.kt:111)
[debug] [EspressoDriver@cc44 (ff7ee118)]    at androidx.lifecycle.RepeatOnLifecycleKt$repeatOnLifecycle$3$1$1$1$1$1$1.invoke(Unknown Source:8)
[debug] [EspressoDriver@cc44 (ff7ee118)]    at androidx.lifecycle.RepeatOnLifecycleKt$repeatOnLifecycle$3$1$1$1$1$1$1.invoke(Unknown Source:4)
[debug] [EspressoDriver@cc44 (ff7ee118)]    at kotlinx.coroutines.intrinsics.UndispatchedKt.startUndispatchedOrReturn(Undispatched.kt:89)
[debug] [EspressoDriver@cc44 (ff7ee118)]    at kotlinx.coroutines.CoroutineScopeKt.coroutineScope(CoroutineScope.kt:264)
[debug] [EspressoDriver@cc44 (ff7ee118)]    at androidx.lifecycle.RepeatOnLifecycleKt$repeatOnLifecycle$3$1$1$1$1.invokeSuspend(RepeatOnLifecycle.kt:110)
[debug] [EspressoDriver@cc44 (ff7ee118)]    at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
[debug] [EspressoDriver@cc44 (ff7ee118)]    at kotlinx.coroutines.internal.DispatchedContinuationKt.resumeCancellableWith(DispatchedContinuation.kt:367)
[debug] [EspressoDriver@cc44 (ff7ee118)]    at kotlinx.coroutines.intrinsics.CancellableKt.startCoroutineCancellable(Cancellable.kt:30)
[debug] [EspressoDriver@cc44 (ff7ee118)]    at kotlinx.coroutines.intrinsics.CancellableKt.startCoroutineCancellable$default(Cancellable.kt:25)
[debug] [EspressoDriver@cc44 (ff7ee118)]    at kotlinx.coroutines.CoroutineStart.invoke(CoroutineStart.kt:110)
[debug] [EspressoDriver@cc44 (ff7ee118)]    at kotlinx.coroutines.AbstractCoroutine.start(AbstractCoroutine.kt:126)
[debug] [EspressoDriver@cc44 (ff7ee118)]    at kotlinx.coroutines.BuildersKt__Builders_commonKt.launch(Builders.common.kt:56)
[debug] [EspressoDriver@cc44 (ff7ee118)]    at kotlinx.coroutines.BuildersKt.launch(Unknown Source:1)
[debug] [EspressoDriver@cc44 (ff7ee118)]    at kotlinx.coroutines.BuildersKt__Builders_commonKt.launch$default(Builders.common.kt:47)
[debug] [EspressoDriver@cc44 (ff7ee118)]    at kotlinx.coroutines.BuildersKt.launch$default(Unknown Source:1)
[debug] [EspressoDriver@cc44 (ff7ee118)]    at androidx.lifecycle.RepeatOnLifecycleKt$repeatOnLifecycle$3$1$1$1.onStateChanged(RepeatOnLifecycle.kt:106)
[debug] [EspressoDriver@cc44 (ff7ee118)]    at androidx.lifecycle.LifecycleRegistry$ObserverWithState.dispatchEvent(LifecycleRegistry.java:360)
[debug] [EspressoDriver@cc44 (ff7ee118)]    at androidx.lifecycle.LifecycleRegistry.forwardPass(LifecycleRegistry.java:271)
[debug] [EspressoDriver@cc44 (ff7ee118)]    at androidx.lifecycle.LifecycleRegistry.sync(LifecycleRegistry.java:313)
[debug] [EspressoDriver@cc44 (ff7ee118)]    at androidx.lifecycle.LifecycleRegistry.moveToState(LifecycleRegistry.java:151)
[debug] [EspressoDriver@cc44 (ff7ee118)]    at androidx.lifecycle.LifecycleRegistry.handleLifecycleEvent(LifecycleRegistry.java:134)
[debug] [EspressoDriver@cc44 (ff7ee118)]    at androidx.lifecycle.ReportFragment.dispatch(ReportFragment.java:68)
[debug] [EspressoDriver@cc44 (ff7ee118)]    at androidx.lifecycle.ReportFragment$LifecycleCallbacks.onActivityPostStarted(ReportFragment.java:187)
[debug] [EspressoDriver@cc44 (ff7ee118)]    at android.app.Activity.dispatchActivityPostStarted(Activity.java:1418)
[debug] [EspressoDriver@cc44 (ff7ee118)]    at android.app.Activity.performStart(Activity.java:8367)
[debug] [EspressoDriver@cc44 (ff7ee118)]    at android.app.ActivityThread.handleStartActivity(ActivityThread.java:3670)
[debug] [EspressoDriver@cc44 (ff7ee118)]    at android.app.servertransaction.TransactionExecutor.performLifecycleSequence(TransactionExecutor.java:221)
[debug] [EspressoDriver@cc44 (ff7ee118)]    at android.app.servertransaction.TransactionExecutor.cycleToPath(TransactionExecutor.java:201)
[debug] [EspressoDriver@cc44 (ff7ee118)]    at android.app.servertransaction.TransactionExecutor.executeLifecycleState(TransactionExecutor.java:173)
[debug] [EspressoDriver@cc44 (ff7ee118)]    at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:97)
[debug] [EspressoDriver@cc44 (ff7ee118)]    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2307)
[debug] [EspressoDriver@cc44 (ff7ee118)]    at android.os.Handler.dispatchMessage(Handler.java:106)
[debug] [EspressoDriver@cc44 (ff7ee118)]    at android.os.Looper.loopOnce(Looper.java:201)
[debug] [EspressoDriver@cc44 (ff7ee118)]    at android.os.Looper.loop(Looper.java:288)
[debug] [EspressoDriver@cc44 (ff7ee118)]    at android.app.ActivityThread.main(ActivityThread.java:7872)
[debug] [EspressoDriver@cc44 (ff7ee118)]    at java.lang.reflect.Method.invoke(Native Method)
[debug] [EspressoDriver@cc44 (ff7ee118)]    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548)
[debug] [EspressoDriver@cc44 (ff7ee118)]    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:936)
[debug] [EspressoDriver@cc44 (ff7ee118)]    Suppressed: kotlinx.coroutines.DiagnosticCoroutineContextException: [StandaloneCoroutine{Cancelling}@54722a, Dispatchers.Main.immediate]
[EspressoDriver@cc44 (ff7ee118)] socket hang up
[debug] [EspressoDriver@cc44 (ff7ee118)] Deleting espresso session

Any ideas on how to track down the needed dependency?

jamesvanhorn commented 1 year ago

So I was able to "solve" this in a hacky way and I'm on the hunt now for the right way.

My fix:

  1. Copy libyoga.so from my app under test repo
  2. Create a jniLibs folder at ~/.appium/node_modules/appium-espresso-driver/espresso-server/app/src/androidTest/
  3. Paste libyoga.so there so it's picked up and packaged into the eventual espresso test server apk

Is there a way to specify this dependency using an Appium capability? I'll admit I don't know a ton about the android build process so I could be way off base, but this fix did work in successfully starting a session though and unblocking me for locally. The fix isn't portable at all though other environments.

KazuCocoa commented 1 year ago

Is there a way to specify this dependency using an Appium capability?

No, maybe it has no way. How the test target app's dependencies refer to it? I wonder if it is not adding dependencies in https://github.com/appium/appium-espresso-driver/blob/master/espresso-server/app/build.gradle.kts#L91-L146 For example, it needs additional references in https://github.com/appium/appium-espresso-driver/blob/master/espresso-server/build.gradle.kts

jamesvanhorn commented 1 year ago

in case anyone else stumbles across this, the answer ended up being to declare the library which uses lib yoga.so (br.com.zup.beagle:beagle-yoga-layout:1.19.0) under additionalAndroidTestDependencies but NOT under additionalAppDependencies

This packaged the libyoga.so file into the espresso test server apk and then things worked fine.