1

So I made a bot for a singleplayer android game, using python and adb. The biggest problem is that between each tap there is like a 1 second delay.

I connect to the device like this -

from ppadb.client import Client

def Get_device_adb():
    adb = Client(host="127.0.0.1", port=5037)

    devices = adb.devices()
    if len(devices) == 0:
        print("No device attached")
        quit()

    return devices[0]

device = Get_device_adb()

and use shell input tap to send my taps -

taps = [(225, 750), (350, 800), ...]
for tap in taps:
    device.shell(f"input tap {tap[0]} {tap[1]}")

For the game I need the taps to happen as fast as possible one after another, and currently they have a 1 second delay between them.

By the way, I really want this script to run in python and not in jython

So is there a way to make adb tap faster?

Ran42
  • 60
  • 1
  • 9

1 Answers1

1

You can try AndroidViewClient/cuelbra using CluebraTester2-public backend and you can get a much higher rate.

Here is an example script

#! /usr/bin/env python3
# -*- coding: utf-8 -*-

import time
from com.dtmilano.android.viewclient import ViewClient

device, serialno = ViewClient.connectToDeviceOrExit()

kwargs2 = {'useuiautomatorhelper': True}
vc = ViewClient(device, serialno, **kwargs2)

taps = [(225, 750), (350, 800), (100, 100), (300, 300), (150, 150), (100, 200)]
for tap in taps:
    print(f'{time.time()}: touching @{tap}')
    vc.touch(tap[0], tap[1])

using an emulator I could obtain

1635459899.020685: touching @(225, 750)
1635459899.202344: touching @(350, 800)
1635459899.522454: touching @(100, 100)
1635459899.703721: touching @(300, 300)
1635459899.8933198: touching @(150, 150)
1635459903.257416: touching @(100, 200)

which gives approx. 1 touch every 200 ms.

edit

There's a new answer at https://stackoverflow.com/a/72268342/236465 that reduces the time per click to around 100ms

Diego Torres Milano
  • 65,697
  • 9
  • 111
  • 134
  • Thanks, I pip installed the ViewClient but I am having a hard time installing the CulebraTester2 back end server, I already installed the app.zip and instrumentation.zip on my computer but I dont understand what to do next, can you help me please? (and my phone is also connected with adb by usb) – Ran42 Oct 29 '21 at 07:44
  • 1
    You donwloaded and installed the 2 apks (app & instrumentation) on your device. Then you can run `bash <(curl -sL https://git.io/JT5nc) start-server` to start the server. Once the server is running you can execute the above script. Feel free to follow up with another question (use tag https://stackoverflow.com/questions/tagged/androidviewclient). – Diego Torres Milano Oct 29 '21 at 16:50
  • Thank you, but I am using windows is there a way to do it in windows 10? – Ran42 Oct 29 '21 at 19:45
  • 1
    Yes, `gitbash` should work. Otherwise, you can just reproduce the simple command s to `forward_port && run_instrumentation` that are inside https://github.com/dtmilano/CulebraTester2-public/blob/master/culebratester2 script. – Diego Torres Milano Oct 29 '21 at 20:40
  • So on the gitbash I wrote - adb install app-debug.apk. adb install app-debug-and-roidTest.apk. bash <(curl -sL https://git.io/JT5nc) start-server. Im getting this error - "app and instrumentation apks should be installed". I also tried to rename app-debug.apk -> app.apk and app-debug-and-roidTest.apk -> instrumentation.apk. But I still get the sam error – Ran42 Oct 29 '21 at 22:14
  • 1
    Once you have installed and APK (the local name doesn't matter) and having the device connected via ADB, what's the output of `adb shell pm list packages | grep -c com.dtmilano.android.culebratester2` ? That's how the script is checking they are both installed. – Diego Torres Milano Oct 30 '21 at 01:59
  • The output is 1, I also scrolled down after writing "adb shell pm list packges" and I can see package:com.dtmilano.android.culebratester2 is in the list. – Ran42 Oct 30 '21 at 08:48
  • "bash <(curl -sL https://git.io/JT5nc) start-server" still returns "ERROR: app and instrumentation apks should be installed." – Ran42 Oct 30 '21 at 08:49
  • 1
    But the output should be **2**, as two APKs should be installed (app & instrumentation). You are missing 1. Check the status when you install them to verify there is no error. – Diego Torres Milano Oct 31 '21 at 02:57
  • 1
    A new version of `culabratester2` script has been uploaded. Try run it again. The output should be more helpful. – Diego Torres Milano Oct 31 '21 at 04:44
  • I reinstalled the apks, now it says 2 in the adb list, and with the new culabratester2 script it runs without errors! The python script taps are as fast as I need them, Thank you very much :D – Ran42 Oct 31 '21 at 10:04
  • Glad to hear that. – Diego Torres Milano Nov 01 '21 at 01:40
  • Hi using vc.touch is fine with your method. However, using vc.swipe() give me error: RuntimeError: this method should not be used – Ken Apr 06 '22 at 02:45