openatx / adbutils

pure python adb library for google adb service.
MIT License
781 stars 180 forks source link

Issue with `device.sync.push` Resulting in `AdbError: FAIL` #101

Closed songyuc closed 4 months ago

songyuc commented 8 months ago

Hello, guys,

I've encountered an issue with adbutils while working on a script that involves pushing a file to an Android emulator. The specific method that's causing trouble is device.sync.push. Despite successful execution of the same command via os.system(), the device.sync.push method results in an AdbError: FAIL exception.

Environment:

Issue Description: The script is intended to clone the minitouch repo, build it, and then push the minitouch binary to an emulator. The os.system() method successfully pushes the file using the adb push command. However, when attempting to do the same with adbutils, it results in an error.

Here is the relevant part of the script:

# ... [Previous code for context]

print(minitouch_path / "libs" / abi / "minitouch")
os.system(r"adb push D:\Program\xxx\Python_emutouch\minitouch\libs\x86_64\minitouch /data/local/tmp/")
device.sync.push(minitouch_path / "libs" / abi / "minitouch", "/data/local/tmp/", check=True)

# ... [Rest of the code]

The error encountered is as follows:

adbutils.errors.AdbError: FAIL

Attempts to Resolve:

I'm unsure why device.sync.push is failing while os.system() succeeds. Any insights or suggestions would be greatly appreciated.

Thank you for your time and assistance.

Best regards, Yucheng Song

codeskyblue commented 8 months ago

Change the destination to /data/local/tmp/minitouch

songyuc commented 8 months ago

Hi, @codeskyblue, thanks sincerely for your guide!

Besides, I'd like to suggest an enhancement for the device.sync.push() method to align more closely with the standard adb push command behavior.

In standard ADB, the command adb push source-path destination-path automatically retains the source file name if the destination file name is not specified. For example, adb push xxx\minitouch\libs\x86_64\minitouch /data/local/tmp/ pushes the file to /data/local/tmp/minitouch.

It would be highly beneficial if adbutils could adopt similar functionality, as following example:

# os.system(r"adb push xxx\minitouch\libs\x86_64\minitouch /data/local/tmp/")
device.sync.push(minitouch_path / "libs" / abi / "minitouch", "/data/local/tmp/", check=True)

This change of omitting the target file name would allow users to push files without specifying the file name in the destination path, thus simplifying the command and making the API more intuitive, especially for those accustomed to the standard ADB behavior.

Thank you for considering this suggestion.

Best regards, Yucheng Song

shidalao commented 5 months ago

change your dst directory to a specific file name, such as "/data/local/tmp/" to "/data/local/tmp/123.txt"