question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Error: Unable to build Espresso server - spawn ./gradlew ENOENT

See original GitHub issue

Hi when I try to run the espresso server I got the ENOENT error.

Logs

[Espresso] Unable to build Espresso server - spawn ./gradlew ENOENT
[Espresso] Gradle error message:
[Espresso] 
[debug] [Espresso] Deleting espresso session
[debug] [W3C] Encountered internal error running command: A new session could not be created. Details: Unable to build Espresso server - spawn ./gradlew ENOENT
[debug] [W3C] Gradle error message:
[debug] [W3C] . Check https://github.com/appium/appium-espresso-driver#troubleshooting regarding advanced session startup troubleshooting.
[debug] [W3C] Error: Unable to build Espresso server - spawn ./gradlew ENOENT
[debug] [W3C] Gradle error message:
[debug] [W3C] . Check https://github.com/appium/appium-espresso-driver#troubleshooting regarding advanced session startup troubleshooting.
[debug] [W3C]     at Object.wrappedLogger.errorAndThrow (/Users/zhaojy/ui-test/node_modules/@appium/support/lib/logging.js:94:35)
[debug] [W3C]     at ServerBuilder.runBuildProcess (/Users/zhaojy/ui-test/node_modules/appium-espresso-driver/lib/server-builder.js:195:4)
[debug] [W3C]     at ServerBuilder.build (/Users/zhaojy/ui-test/node_modules/appium-espresso-driver/lib/server-builder.js:73:5)
[debug] [W3C]     at EspressoRunner.buildNewModServer (/Users/zhaojy/ui-test/node_modules/appium-espresso-driver/lib/espresso-runner.js:188:5)
[debug] [W3C]     at EspressoRunner.installTestApk (/Users/zhaojy/ui-test/node_modules/appium-espresso-driver/lib/espresso-runner.js:146:7)
[debug] [W3C]     at EspressoDriver.initAUT (/Users/zhaojy/ui-test/node_modules/appium-espresso-driver/lib/driver.js:552:7)
[debug] [W3C]     at EspressoDriver.startEspressoSession (/Users/zhaojy/ui-test/node_modules/appium-espresso-driver/lib/driver.js:422:5)
[debug] [W3C]     at EspressoDriver.createSession (/Users/zhaojy/ui-test/node_modules/appium-espresso-driver/lib/driver.js:225:7)
[debug] [W3C]     at AppiumDriver.createSession (/Users/zhaojy/ui-test/node_modules/appium/lib/appium.js:387:35)
[HTTP] <-- POST /wd/hub/session 500 4537 ms - 1977
[HTTP] 
[Gradle] [STDOUT] > Task :app:preBuild UP-TO-DATE
[Gradle] [STDOUT] > Task :app:preDebugBuild UP-TO-DATE
[Gradle] [STDOUT] > Task :app:compileDebugAidl NO-SOURCE
[Gradle] [STDOUT] > Task :app:compileDebugRenderscript NO-SOURCE
[Gradle] [STDOUT] > Task :app:generateDebugBuildConfig FROM-CACHE
[Gradle] [STDOUT] > Task :app:checkDebugAarMetadata FROM-CACHE
[Gradle] [STDOUT] > Task :app:generateDebugResValues FROM-CACHE
[Gradle] [STDOUT] > Task :app:generateDebugResources UP-TO-DATE
[Gradle] [STDOUT] > Task :app:mergeDebugResources FROM-CACHE
[Gradle] [STDOUT] > Task :app:createDebugCompatibleScreenManifests FROM-CACHE
[Gradle] [STDOUT] > Task :app:extractDeepLinksDebug FROM-CACHE
[Gradle] [STDOUT] > Task :app:processDebugMainManifest FROM-CACHE
[Gradle] [STDOUT] > Task :app:processDebugManifest FROM-CACHE
[Gradle] [STDOUT] > Task :app:processDebugManifestForPackage FROM-CACHE
[Gradle] [STDOUT] > Task :app:processDebugResources FROM-CACHE
[Gradle] [STDOUT] > Task :app:compileDebugKotlin FROM-CACHE
[Gradle] [STDOUT] > Task :app:javaPreCompileDebug FROM-CACHE
[Gradle] [STDOUT] > Task :app:compileDebugJavaWithJavac FROM-CACHE
[Gradle] [STDOUT] > Task :app:bundleDebugClasses FROM-CACHE
[Gradle] [STDOUT] > Task :app:preDebugAndroidTestBuild SKIPPED
[Gradle] [STDOUT] > Task :app:compileDebugAndroidTestAidl NO-SOURCE
[Gradle] [STDOUT] > Task :app:processDebugAndroidTestManifest
[Gradle] [STDOUT] > Task :app:generateDebugAndroidTestBuildConfig FROM-CACHE
[Gradle] [STDOUT] > Task :app:checkDebugAndroidTestAarMetadata FROM-CACHE
[Gradle] [STDOUT] > Task :app:compileDebugAndroidTestRenderscript NO-SOURCE
[Gradle] [STDOUT] > Task :app:generateDebugAndroidTestResValues FROM-CACHE
[Gradle] [STDOUT] > Task :app:generateDebugAndroidTestResources UP-TO-DATE
[Gradle] [STDOUT] > Task :app:mergeDebugAndroidTestResources FROM-CACHE
[Gradle] [STDOUT] > Task :app:processDebugAndroidTestResources FROM-CACHE
[Gradle] [STDOUT] > Task :app:compileDebugAndroidTestKotlin FROM-CACHE
[Gradle] [STDOUT] > Task :app:javaPreCompileDebugAndroidTest FROM-CACHE
[Gradle] [STDOUT] > Task :app:compileDebugAndroidTestJavaWithJavac FROM-CACHE
[Gradle] [STDOUT] > Task :app:mergeDebugAndroidTestShaders FROM-CACHE
[Gradle] [STDOUT] > Task :app:compileDebugAndroidTestShaders NO-SOURCE
[Gradle] [STDOUT] > Task :app:generateDebugAndroidTestAssets UP-TO-DATE
[Gradle] [STDOUT] > Task :app:mergeDebugAndroidTestAssets FROM-CACHE
[Gradle] [STDOUT] > Task :app:compressDebugAndroidTestAssets FROM-CACHE
[Gradle] [STDOUT] > Task :app:processDebugAndroidTestJavaRes NO-SOURCE
[Gradle] [STDOUT] > Task :app:mergeDebugAndroidTestJniLibFolders FROM-CACHE
[Gradle] [STDOUT] > Task :app:mergeDebugAndroidTestNativeLibs NO-SOURCE
[Gradle] [STDOUT] > Task :app:checkDebugAndroidTestDuplicateClasses FROM-CACHE
[Gradle] [STDOUT] > Task :app:desugarDebugAndroidTestFileDependencies FROM-CACHE

It looks like it failed when spawning the subprocess to run ./gradlew but the command was executed successfully.

Environment

System: macOS Monterey Version 12.3.1 Node: v17.8.0 Appium: v1.22.3 Appium-Epsresso-Driver: v2.2.0

Workarounds found

  1. Adding shell: true in the options passed to create the SubProcess instance in server-builder.js, runBuildProcess function:
const gradlebuild = new SubProcess(cmd, args, {
  // added
  shell: true,
  cwd: this.serverPath,
  stdio: ['ignore', 'pipe', 'pipe'],
  windowsVerbatimArguments: true
});

With this it seems the error is gone. 2. Changing the command to `${this.serverPath}/gradlew` instead of ./gradlew only

I wonder if it’s just my environment issue. I also tried to run a separate file using Node’s child_process’s spawn function and it also fails with ENOENT:

import { SubProcess } from 'teen_process'
import { spawn } from 'child_process'

// const cmd = '/var/folders/ym/czsz9g516kj4hnxkz3n7405jtjlz7x/T/espresso-server-emulator-5554/gradlew'
const cmd = './gradlew'
const args = [
  '-PappiumAndroidGradlePlugin=7.1.2',
  '-PappiumCompileSdk=31',
  '-PappiumBuildTools=31.0.0',
  '-PappiumTargetSdk=31',
  '-PappiumKotlin=1.6.10',
  '-PappiumComposeVersion=1.1.1',
  '-PappiumTargetPackage=<targetPackage>',
  'app:assembleAndroidTest']
const cwd = '/var/folders/ym/czsz9g516kj4hnxkz3n7405jtjlz7x/T/espresso-server-emulator-5554'

// const gradlew = spawn(cmd, args, { cwd })
const gradlew = spawn(cmd, args,
  {
    cwd,
    // shell: true,
  })
gradlew.on('error', (err) => {
  console.error(err.message)
  console.error(err)
})
gradlew.stdout.on('data', (data) => {
  console.log(data.toString())
})
gradlew.stderr.on('data', (data) => {
  console.error(data.toString())
})
gradlew.on('close', (code) => {
  console.log(`child process exited with code ${code}`)
})

Again, uncommenting // shell: true will also fix the issue

Issue Analytics

  • State:open
  • Created a year ago
  • Comments:11 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
JasonSznolcommented, Apr 13, 2022

I was able to resolve the issue, turns out NPM was resolving a very old version of the driver. Sorry about that!

0reactions
JasonSznolcommented, Apr 25, 2022

@psangwan8 In my case when I ran npm install it would resolve version 1.45 of the espresso driver instead of the 2.2.1 defined in the package.json file. To fix this I edited the package-lock.json file to remove the resolved dependency of the old espresso driver, removed the node_modules directory and ran npm ci to reinstall all the dependent packages; npm ci will respect what is in the package-lock.json file whereas npm install would not.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Ask Question - Stack Overflow
Getting error `spawn ./gradlew ENOENT` when I run `tns build android` ... I'm trying to build a hello world application to test it....
Read more >
Error: Unable to build Espresso server - Support
Gradle error message: How to fix this issue now? Espresso driver fails to start activity (android compose app).
Read more >
Setting up Appium with Android Studio - QA Automated
Set appium server address and port number in URL string. // It will launch calculator app in ... Error: spawn ENOENT"},"sessionId":null}
Read more >
appium-espresso-driver - npm
Gradle must be installed in order to build Espresso server. Both the server package and the application under test must be signed with...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found