Appium Error: Could not find 'adb.exe' in PATH. (local environment is setup)

Appium Error: Could not find 'adb.exe' in PATH. (local environment is setup)

我正在尝试使用桌面 appium 创建会话,但出现此错误:

An unknown server-side error occurred while processing the command. Original error: Could not find 'adb.exe' in PATH. Please set the ANDROID_HOME or ANDROID_SDK_ROOT environment variables to the correct Android SDK root directory path.

现在我可以在我的终端中毫无问题地使用 adb,因为我已经在我的路径中设置了 adk。我的路径中也有 Java_home。

#all in my path
C:\Users\Sams PC\AppData\Local\Android\Sdk\build-tools
C:\Users\Sams PC\AppData\Local\Android\Sdk\tools
C:\Users\Sams PC\AppData\Local\Android\Sdk\platform-tools
C:\Program Files (x86)\Common Files\Oracle\Java\javapath

所以我不太明白为什么会出现此错误。这些是我想要的功能:

{
  "deviceName": "emulator-5554",
  "platformName": "Android",
  "app ": "C:\Users\Sams PC\Desktop\Android\myapp-0.1-armeabi-v7a-debug.apk"
}

以下是 Appium 日志:

[BaseDriver] Creating session with MJSONWP desired capabilities: {
[BaseDriver]   "app": "C:\Users\Sams PC\Desktop\Android\myapp-0.1-armeabi-v7a-debug.apk",
[BaseDriver]   "deviceName": "emulator-5554",
[BaseDriver]   "platformName": "Android",
[BaseDriver]   "newCommandTimeout": 0,
[BaseDriver]   "connectHardwareKeyboard": true
[BaseDriver] }
[BaseDriver] The following capabilities were provided, but are not recognized by Appium:
[BaseDriver]   connectHardwareKeyboard
[BaseDriver] Session created with session id: e5a41011-c8e6-4d25-b1de-ea89de54a7b1
[BaseDriver] Using local app 'C:\Users\Sams PC\Desktop\Android\myapp-0.1-armeabi-v7a-debug.apk'
[UiAutomator2] Checking whether app is actually present
[ADB] The ANDROID_HOME environment variable is not set to the Android SDK root directory path. ANDROID_HOME is required for compatibility with SDK 23+. Checking along PATH for adb.
[UiAutomator2] Deleting UiAutomator2 session
[BaseDriver] Event 'newSessionStarted' logged at 1595009685037 (14:14:45 GMT-0400 (Eastern Daylight Time))
[MJSONWP] Encountered internal error running command: Error: Could not find 'adb.exe' in PATH. Please set the ANDROID_HOME or ANDROID_SDK_ROOT environment variables to the correct Android SDK root directory path.
[MJSONWP]     at ADB.getBinaryFromPath (C:\Users\Sams PC\AppData\Local\Programs\Appium\resources\app\node_modules\appium\node_modules\appium-adb\lib\tools\system-calls.js:140:11)
[MJSONWP] Destroying socket connection
[HTTP] <-- POST /wd/hub/session 500 443 ms - 288
[HTTP] 
[HTTP] --> DELETE /wd/hub/session
[HTTP] {}
[HTTP] No route found. Setting content type to 'text/plain'
[HTTP] <-- DELETE /wd/hub/session 404 13 ms - 57
[HTTP] 

如您所见,问题显然出在找不到 adb.exe;但是正如您所看到的,我的路径中有平台工具(这就是我可以在终端中使用 adb 的原因,所以 adb.exe 肯定在我的路径中)

问题已解决。虽然我已将 PATH 设置为 Sdk 和平台工具,但您还必须为 ANDROID_HOME 和 JAVA_HOME 创建 系统变量。仅仅为他们设置路径是不够的。因此,尽管能够 运行 adb,该程序仍需要预定义的系统变量。