我试图在Android上自动化任务,但当我在Android上的Pydroid3上运行我的代码时,它返回了一个错误...
我的设备是华硕Zenfone Selfie 4
我不明白这个错误,因为这个错误是关于一个亚洲开发银行EXE问题。
安卓有ADB EXE吗?
代码:
#MODULES IMPORT
import os
import cv2
import numpy as np
from uiautomator2 import Device
from uiautomator2 import connect
#CLASS AND FUNCTIONS DEFINE
class AndroidAuto:
def _init_ (self, Serial = "Serial"):
self.Serial = Serial
def Android_Screenshot(self, dir = ".screenshots"):
dir = dir
if not os.path.exists(dir):
os.makedirs(dir)
device = Device(self.Serial)
device.screenshot(f"{dir}/.screenshot_opencv.png")
return (f"{dir}/.screenshot_opencv.png")
def Android_Touch(self, x = 0, y = 0):
device = Device(self.Serial)
device.click(x, y)
def Android_Get_Position(self, target = None):
Device.toast("Starting ")
while True:
template = AndroidAuto().Android_Screenshot()
w, h = target.shape[:-1]
res = cv2.matchTemplate(template, target, cv2.TM_CCOEFF_NORMED)
threshold = 0.8
loc = np.where(res >= threshold)
if len(loc[0]) > 0:
x, y = loc[::-1]
return x, y
else:
x, y = None, None
Device.toast("Trying again!")
continue
def Android_Find_Click(self, target = "", x = 0, y = 0):
while True:
match = AndroidAuto().Android_Get_Position(target)
if match != None:
AndroidAuto().Android_Touch(x, y = match)
break
else:
continue
AA = AndroidAuto()
print(AA.Android_Screenshot())
当我玩游戏的时候,它会告诉我错误:
RuntimeError: No adb exe could be found. install adb on your system
1条答案
按热度按时间hujrc8aj1#
网站描述是这么说的:
python-uiautomator 2是一个Python Package 器,它允许:
根据这一点(和我的猜测),uiautomator 2依赖于ADB.exe连接到设备,在$PATH系统变量中搜索它,未能找到它,并向您显示一个错误。
所以我想在Pydroid 3中不可能像在PC上那样使用uiautomator 2。