appium-espresso-driver icon indicating copy to clipboard operation
appium-espresso-driver copied to clipboard

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

Open zpiao1 opened this issue 4 years ago • 11 comments

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

zpiao1 avatar Apr 01 '22 04:04 zpiao1

What about lower NodeJS versions?

KazuCocoa avatar Apr 01 '22 07:04 KazuCocoa

One of my colleague is using the same Node version with me and he has the same issue. Another colleague who uses Node v14.x doesn't have this issue though.

zpiao1 avatar Apr 01 '22 08:04 zpiao1

interesting... anyway, the 2) full path is reasonable way. I've created a pr to make it full path.

KazuCocoa avatar Apr 01 '22 16:04 KazuCocoa

espresso driver 2.2.1 has the 2).

KazuCocoa avatar Apr 03 '22 06:04 KazuCocoa

I'm still encoutering the same error using 2.2.1 on an M1 Mac using the appium boilerplate project.

This is the config I am using: `config.capabilities = [

{
    platformName: 'Android',
    //maxInstances: 1,
    // For W3C the appium capabilities need to have an extension prefix
    // http://appium.io/docs/en/writing-running-appium/caps/
    // This is `appium:` for all Appium Capabilities which can be found here
    'appium:deviceName': 'Pixel_3_10.0',
   // 'appium:platformVersion': '10.0',
    'appium:orientation': 'PORTRAIT',
    'appium:automationName': 'Espresso',
    // The path to the app
    'appium:app': join(process.cwd(), './apps/Android-NativeDemoApp-0.4.0.apk'),
    // @ts-ignore
    'appium:appWaitActivity': 'com.wdiodemoapp.MainActivity',
    'appium:newCommandTimeout': 240,
    'appium:showGradleLog': true,
    'appium:forceEspressoRebuild': true,
    'appium:espressoBuildConfig': "{ \
        \"toolsVersions\": { \
            \"gradle\": \"7.4.2\", \
            \"androidGradlePlugin\":\"7.1.1\", \
            \"sourceCompatibility\": \"VERSION_11\", \
            \"targetCompatibility\": \"VERSION_11\", \
            \"jvmTarget\": \"11\" \
        } \
    }"
},

`

I've tried this with appium and the espresso driver installed globally and locally, and with Node 16 and 17 and get the error but with no additional information as to why. If I browse into the module folder and run npm run build:server the server will build just fine.

JasonSznol avatar Apr 05 '22 12:04 JasonSznol

Could you share the full appium log as GIST?

KazuCocoa avatar Apr 10 '22 06:04 KazuCocoa

Could you share the full appium log as GIST?

https://gist.github.com/JasonSznol/34da273696d1e56c36403485f88db024

JasonSznol avatar Apr 12 '22 00:04 JasonSznol

Do you have the appium server instead of webdriverio's log?

KazuCocoa avatar Apr 12 '22 08:04 KazuCocoa

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

JasonSznol avatar Apr 13 '22 20:04 JasonSznol

@JasonSznol how did you solve it, i am getting this error and not able to resolve it. Tried real devices as well as emulator

[debug] [ADB] Removing forwarded port socket connection: 8300 [debug] [ADB] Running '/Users/abc/Library/Android/sdk/platform-tools/adb -P 5037 -s emulator-5554 forward --remove tcp:8300' [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.errorAndThrow (/opt/homebrew/lib/node_modules/appium/node_modules/appium-support/lib/logging.js:94:35) [debug] [W3C] at ServerBuilder.runBuildProcess (/opt/homebrew/lib/node_modules/appium/node_modules/appium-espresso-driver/lib/server-builder.js:191:11) [debug] [W3C] at ServerBuilder.build (/opt/homebrew/lib/node_modules/appium/node_modules/appium-espresso-driver/lib/server-builder.js:72:5) [debug] [W3C] at EspressoRunner.buildNewModServer (/opt/homebrew/lib/node_modules/appium/node_modules/appium-espresso-driver/lib/espresso-runner.js:188:5) [debug] [W3C] at EspressoRunner.installTestApk (/opt/homebrew/lib/node_modules/appium/node_modules/appium-espresso-driver/lib/espresso-runner.js:146:7) [debug] [W3C] at EspressoDriver.initAUT (/opt/homebrew/lib/node_modules/appium/node_modules/appium-espresso-driver/lib/driver.js:435:7) [debug] [W3C] at EspressoDriver.startEspressoSession (/opt/homebrew/lib/node_modules/appium/node_modules/appium-espresso-driver/lib/driver.js:298:5) [debug] [W3C] at EspressoDriver.createSession (/opt/homebrew/lib/node_modules/appium/node_modules/appium-espresso-driver/lib/driver.js:190:7) [debug] [W3C] at AppiumDriver.createSession (/opt/homebrew/lib/node_modules/appium/lib/appium.js:387:35) [HTTP] <-- POST /wd/hub/session 500 1222 ms - 1709

psangwan8 avatar Apr 25 '22 11:04 psangwan8

@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.

JasonSznol avatar Apr 25 '22 11:04 JasonSznol