2


I want to run adb commands from python and I've found google's own library for that but it doesn't work.
https://github.com/google/python-adb

This Is the Code I've used: (It's from the example)

import os.path as op

from adb import adb_commands
from adb import sign_m2crypto

signer = sign_m2crypto.M2CryptoSigner(
    op.expanduser('~/.android/adbkey'))

device = adb_commands.AdbCommands.ConnectDevice(rsa_keys=[signer])

This is the error I get:

Traceback (most recent call last):
  File "/home/elichai2/PycharmProjects/Test/python_adb.py", line 9, in <module>
    device = adb_commands.AdbCommands.ConnectDevice(rsa_keys=[signer])
  File "/usr/local/lib/python2.7/dist-packages/adb/adb_commands.py", line 76, in ConnectDevice
    return cls.Connect(handle, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/adb/adb_commands.py", line 99, in Connect
    device_state = cls.protocol_handler.Connect(usb, banner=banner, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/adb/adb_protocol.py", line 277, in Connect
    cmd, arg0, arg1, banner = cls.Read(usb, ['CNXN', 'AUTH'])
  File "/usr/local/lib/python2.7/dist-packages/adb/adb_protocol.py", line 235, in Read
    actual_checksum = cls.CalculateChecksum(data)
  File "/usr/local/lib/python2.7/dist-packages/adb/adb_protocol.py", line 187, in CalculateChecksum
    return sum(map(ord, data)) & 0xFFFFFFFF
TypeError: ord() expected string of length 1, but int found

Any ideas?

1

3 Answers 3

4

You can try AndroidViewClient/culebra's adbclient.py which is an ADB client implemented in python.

This is a simple example of how to use AdbClient alone without AndroidViewClient.

Sign up to request clarification or add additional context in comments.

3 Comments

I'll need to use their whole project because they got lots of inside dependencies (and they depend on more files inside the project)
s/their/your/ - Diego is the author of AVC
Thanks Diego for this convenient Class. It still works nowadays in 2024
1

Have you tried to install these dependencies? from here [GIthub]: https://github.com/google/python-adb

1 Comment

It is recommended to include the list in the answer rather than referring with a link
1

A more recently maintained option might be https://github.com/JeffLIrion/adb_shell. The Google python-adb package website refers to this one as a better alternative.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.