Automating game processes on Android using bots is a topic that interests both experienced developers and beginners who want to optimize their routine. Bots can perform repetitive actions in games (farm resources, complete levels, collect rewards), but their creation requires an understanding of both the technical nuances Androidand the mechanics of a particular game. In this article, we will analyze the legal and technical aspects of development, select tools, write a simple bot using Python using ADB, and also discuss how to bypass typical automation protection systems.

It is important to understand: the use of bots in online games often violates service rules (for example, Supercell, MiHoYo or Riot Games actively fight against cheaters). We focus on local games without multiplayer or testing your own projectswhere automation does not affect the interests of other players. If you plan to use a bot in a network game, check the developers' policy to avoid blocking your account.

The article is suitable for those who:

  • ๐Ÿ”น Can work with a team line and has basic knowledge Python or Java/Kotlin.
  • ๐Ÿ”น Wants to automate routine actions in offline games (for example, clickers or simulators).
  • ๐Ÿ”น Interested in reverse engineering of mobile applications (without breaking laws).
  • ๐Ÿ”น Ready to test the bot on an emulator or backup device.

1. Legality and risks: what you need to know before you start

Before starting development, it is worth assessing the legal and technical risks. Most online games (Clash of Clans, Genshin Impact, PUBG Mobile) prohibit the use of bots in their User Agreements. Violation may lead to:

  • ๐Ÿšซ Account ban (temporary or permanent).
  • ๐Ÿšซ Block device by IMEI or Android ID.
  • ๐Ÿšซ A claim for damages (in rare cases, if the bot caused damage to the game economy).

However, there are scenarios where bots are acceptable:

  • ๐ŸŽฎ Local games without an online component (for example, Cookie Clicker or Adventure Capitalist).
  • ๐Ÿ› ๏ธ Testing your own games (if you are a developer).
  • ๐Ÿค– Research purposes (training neural networks, analyzing game mechanics).
โš ๏ธ Attention: Even if the game does not detect bots, using automation in multiplayer may be considered cheating. Some studios (for example, Blizzard) sued the creators of cheats.

If you still decide to take a risk, we recommend:

  • ๐Ÿ”„ Use secondary account i backup device.
  • ๐Ÿ›ก๏ธ Disable the bot when updating the game (developers often add new protection systems).
  • ๐Ÿ“ฑ Test the code on emulator (BlueStacks, LDPlayer) before running it on a real one smartphone.
๐Ÿ“Š What game do you want to create a bot for?
Clicker/simulator
MOBA (for example, Mobile Legends)
RPG (for example, Genshin Impact)
Strategy (for example, Clash of Clans)
Other

2. Selecting tools: what is needed for development

Creating a bot for Androidgames requires a combination of software and hardware tools. Below is the minimum set to get started:

Tool Purpose Alternatives
ADB (Android Debug Bridge) Sending commands to the device, simulating clicks, screenshots. Scrcpy (for control from a PC), Termux (for working directly on the phone).
Python 3.10+ Writing bot logic (library pyautogui, opencv, pydirectinput). Java/Kotlin (for native solutions), AutoIt (for Windows automation).
Android emulator Safe testing without risk to the main device. BlueStacks, Genymotion, Android Studio Emulator.
Apktool APK disassembly for game code analysis (optional). JADX, Ghidra.
Fiddler/Charles Interception of game network traffic (for API analysis). Wireshark, Burp Suite.

For beginners, the optimal start is Python + ADB. This duo allows you to quickly create bots for clickers and simple simulators. If the game requires working with memory (for example, changing health or mana values), you will need reverse engineering using GameGuardian or Cheat Engine, but this is already an advanced level.

Example of a minimal installation on Windows:

  1. Download Platform Tools (includes adb.exe).
  2. Install Python from the official website (check the "Add to PATH" box).
  3. Connect the phone to the PC and execute in the command line line:
    adb devices

    If the device is displayed, the connection is established.

โš ๏ธ Attention: On some devices (Xiaomi, Huawei), you need to additionally enable USB debugging (factory settings) in the developer menu.

โ˜‘๏ธ Preparing the working environment

Done: 0 / 5

3. Game analysis: determining interaction points

Before writing code, you need to understand how the game reacts to user actions. To do this, we analyze:

  • ๐ŸŽฏ Click coordinates (where the buttons are located on the screen).
  • ๐Ÿ–ผ๏ธ Images (which interface elements can be visually recognized).
  • ๐Ÿ“ก Network requests (if the game communicates with the server).
  • ๐Ÿง  Game logic (for example, delays between actions).

The simplest way is get a screenshot of the screen and determine the coordinates of the buttons. This can be done by ADB:

adb exec-out screencap -p > screenshot.png

Open the received one screenshot.png in any graphic editor (for example, Paint or GIMP) and write down the coordinates of the necessary elements. For example, the "Attack" button may be located at the point (500, 1200) for permission 1080ร—2340.

To automate image recognition, use the library OpenCV in Python. Example code for searching for a button by template:

import cv2

import numpy as np

Uploading a screenshot and button template

screenshot = cv2.imread('screenshot.png', cv2.IMREAD_COLOR)

template = cv2.imread('attack_button.png', cv2.IMREAD_COLOR)

Looking for a match

result = cv2.matchTemplate(screenshot, template, cv2.TM_CCOEFF_NORMED)

min_val, max_val, min_loc, max_loc = cv2.minMaxLoc(result)

Coordinates of the center of the button

button_x = max_loc[0] + template.shape[1] // 2

button_y = max_loc[1] + template.shape[0] // 2

print(f"Button found at point: ({button_x}, {button_y})"))

If the game actively uses network interaction (for example, MMORPG), analyze the traffic through Fiddler or Charles Proxy. This will help you understand what data is sent to the server and whether it can be faked. However, this approach requires deep knowledge HTTP/HTTPS and often breaks the rules of the game.

adb shell screenrecord /sdcard/record.mp4 - Screen recording will help analyze dynamic elements.-->

4. We are writing a simple bot in Python + ADB

Consider an example of a bot for a clicker game, where you need to periodically click on the screen at a certain point. We will use:

  • ๐Ÿ Python for logic.
  • ๐Ÿ”Œ ADB to simulate clicks.
  • โฑ๏ธ Delays between actions (so that the bot looks โ€œhuman-likeโ€).

Set the necessary libraries:

pip install opencv-python numpy pyautogui

Example code for a bot that presses a button every 3 seconds:

import subprocess

import time

import random

Button coordinates (replace with your own)

BUTTON_X = 500

BUTTON_Y = 1200

ADB command for tapping on the screen

def tap_screen(x, y):

subprocess.run(f"adb shell input tap {x} {y}", shell=True)

Main loop

while True:

tap_screen(BUTTON_X, BUTTON_Y)

# Random delay from 2.5 to 3.5 seconds

delay = 2.5 + random.random()

time.sleep(delay)

To start the bot:

  1. Connect the device to the PC.
  2. Start the game and go to the desired screen.
  3. Run the script: python bot.py.

To complicate the logic, you can add:

  • ๐Ÿ” Image recognition (if the button changes position).
  • ๐Ÿ“Š Pixel color analysis (for example, checking whether an enemy has appeared on the screen).
  • ๐Ÿ”„ Error handling (if the game crashes or advertising appears).
โš ๏ธ Attention: Some games (for example, Genshin Impact) block ADB-commands during gameplay. In this case, you will need to use emulator with root access or alternative input methods (for example, OctoWiFi for wireless control).
๐Ÿ’ก

To bypass simple anti-bot systems, add random delays and small deviations in the coordinates of clicks (for example, ยฑ10 pixels).

5. Bypassing protection: how to make a bot less noticeable

Modern games use various methods of Detection of bots. Here are the most common and ways to bypass them:

Protection method How it works Bypass methods
Input analysis The game tracks โ€œinhumanโ€ speed clicks or ideal swipe trajectories. Add random delays and errors in coordinates.
ADB check Some games block commands input tap via ADB. Use emulators with root access or alternative input methods (for example, uiautomator).
Traffic analysis The server compares request patterns with typical player behavior. Imitate real delays between actions and do not send requests too often.
Checking the emulator The game determines whether it is running on the emulator (for example, by Build.FINGERPRINT). Use a real device or disguise the emulator as a device (for example, through Magisk).

For advanced bots you can use: Imitation of human behavior (use with variable parameters). data-i="242">Encrypt command lines

  • ๐ŸŽญ Imitation of human behavior:
    • Random pauses between actions (for example, from 0.5 to 2 seconds).
    • Inaccurate clicks (coordinate deviation by ยฑ5โ€“15 pixels).
    • Swipe at different speeds (use adb shell input swipe with variable parameters).
  • ๐Ÿ” Code obfuscation:
    • Compile Python-script in .exe by using PyInstaller.
    • Encrypt command strings ADB.
  • ๐Ÿ›ก๏ธ Change device signature:
    • Change Android ID, IMEI (requires root).
    • Use VPN to change IP (but this may cause suspicions).

An example of a โ€œhumanoidโ€ click with errors:

import random

def human_like_tap(x, y):

# Adding a random deviation

offset_x = random.randint(-10, 10)

offset_y = random.randint(-10, 10)

real_x = x + offset_x

real_y = y + offset_y

subprocess.run(f"adb shell input tap {real_x} {real_y}", shell=True)

Use

human_like_tap(500, 1200)

For games with server verification (for example, MMORPG) can required Packet interception and modification. This is a complex task that requires knowledge TCP/IP and often breaks the rules. We do not recommend this approach for beginners.

How do games detect bots?

Most anti-cheats (for example, Easy Anti-Cheat or BattlEye) are analyzed:

- Speed and accuracy of clicks (a person cannot click perfectly every 1,000 seconds).

- Movement patterns (swipe at a constant speed).

- System calls (for example, using ADB or Root).

- Network traffic (atypical requests or their frequency).

6. Testing and debugging: how to avoid errors

Even the simplest bot can be unstable due to:

  • ๐Ÿ”„ Changes in the game interface (buttons have moved after the update).
  • ๐Ÿ“ฑ Differences in screen resolution (coordinates do not match on another device).
  • ๐Ÿšซ Command blocking (the game ignores ADB-input).
  • ๐Ÿ”‹ Battery drain (some devices turn off ADB in power saving mode).

To minimize problems:

  1. Test on an emulator with a fixed resolution (for example, 720ร—1280).
  2. Add logging:
    with open("bot_log.txt", "a") as f:
    

    f.write(f"{time.strftime('%H:%M:%S')} - Click on ({x}, {y})\n")

  3. Handle exceptions:
    try:
    

    tap_screen(BUTTON_X, BUTTON_Y)

    except subprocess.CalledProcessError:

    print("ADB error! Check your connection.")

  4. Use relative coordinates:
    # Example: button in the center of the screen
    

    screen_width = 1080

    screen_height = 2340

    center_x = screen_width // 2

    center_y = screen_height // 2

If the bot stopped working after updating the game:

  1. Take a new screenshot and update the coordinates.
  2. Check if the interface has changed (for example, new animation has been added).
  3. Update ADB and device drivers.
โš ๏ธ Attention: On devices Samsung with One UI you may need to disable the function Optimize battery usage for ADBotherwise the connection will be lost.

โ˜‘๏ธ Checklist before launching the bot

Done: 0 / 5

7. Advanced techniques: neural networks and machine learning

For complex games (for example, MOBA or RTS) ordinary scripts are not suitable - required computer vision and machine learning. Let's consider the basic approaches:

1. Object recognition using OpenCV and Template Matching

If the game has a dynamic interface (the buttons change position), you can train the bot to find elements from the image. Example:

import cv2

Loading the "Attack" button template

template = cv2.imread('attack_button.png', 0)

screenshot = cv2.imread('screen.png', 0)

Looking for a match

result = cv2.matchTemplate(screenshot, template, cv2.TM_CCOEFF_NORMED)

threshold = 0.8 # Similarity threshold

loc = np.where(result >= threshold)

If a match is found

if len(loc[0]) > 0:

x, y = loc[1][0], loc[0][0]

tap_screen(x + 10, y + 10) # Click in the center of the button

2. Use Tesseract OCR for text recognition

If the game displays important information in text (for example, the amount of health), you can read it from the screen:

import pytesseract

from PIL import Image

Crop the area with text

image = Image.open('health_bar.png').crop((100, 50, 200, 70))

text = pytesseract.image_to_string(image)

print(f"Health: {text}")

3. Neural networks for decision making

For games with complex logic (for example, chess or step-by-step strategies), you can train a neural network using screenshots. Libraries:

  • ๐Ÿค– TensorFlow/Keras โ€”for training models.
  • ๐ŸŽฏ PyTorch โ€”for computer vision.
  • ๐Ÿง  Stable Baselines3 โ€” for reinforcement learning (Reinforcement Learning).

Example of bot architecture for turn-based game:

  1. The neural network analyzes the screenshot (input: screen pixels).
  2. Determines the current state of the game (for example, the positions of units).
  3. Selects the optimal action (for example, attack or movement).
  4. Sends a command via ADB.

Training a neural network requires a large amount of data (thousands of screenshots with markup) and powerful hardware (video card NVIDIA with support CUDA). For beginners, itโ€™s easier to start with ready-made models (for example, YOLO for object detection).

๐Ÿ’ก

To speed up image recognition, reduce the resolution of screenshots to 320ร—640 and convert to black and white format (cv2.COLOR_BGR2GRAY).

8. Alternative approaches: without ADB and Python

If ADB is blocked by the game or you are looking for a more reliable solution, consider alternatives:

1. Automation via AutoInput (for rooted devices)

Application AutoInput (plugin for Tasker) allows you to create bots directly on your phone without a PC. Pros:

  • โœ… Works without ADB.
  • โœ… Supports conditional operators. (for example, โ€œif an enemy appears, attackโ€).
  • โœ… You can export/import tasks.

Cons:

  • โŒ Required root for some functions.
  • โŒ Limited logic compared to Python.

2. Using GameGuardian or Cheat Engine

These tools allow you to:

  • ๐Ÿ” Change values in the game memory (for example, the number of coins).
  • ๐ŸŽฎ Automate actions through Lua scripts.

Example script for GameGuardian:

-- Autoclicker for a button with coordinates (300, 500)

while true do

touchDown(0, 300, 500)

touchUp(0, 300, 500)

sleep(1000) -- Pause 1 second

end

3. Development of a native bot on Java/Kotlin

If you are familiar with Android Studio, you can create an application that:

  • ๐Ÿ“ฑ Simulates clicks through AccessibilityService.
  • ๐Ÿ” Analyzes the interface of other applications (requires permission android.permission.BIND_ACCESSIBILITY_SERVICE).

An example of a manifest for AccessibilityService:

<service

android:name=".MyAccessibilityService"

android:permission="android.permission.BIND_ACCESSIBILITY_SERVICE">

<intent-filter>

<action android:name="android.accessibilityservice.AccessibilityService" />

</intent-filter>

<meta-data

android:name="android.accessibilityservice"

android:resource="@xml/accessibility_service_config" />

</service>

The advantage of a native bot is that it looks like a regular application and is more difficult to detect by anti-cheats. However, development requires knowledge Android SDK and an application signature.

๐Ÿ’ก

For maximum secrecy, combine several methods: for example, use AccessibilityService for clicks and OpenCV for image recognition.

FAQ: Frequently asked questions about bots for Android games

โ“ Can the bot be used in Clash of Clans or Brawl Stars?

No. Supercell actively blocks accounts for using automation. Even if the bot works for several days, sooner or later it will be detected. For testing, you can create a secondary account, but the risk of a ban remains.

โ“ How to bypass blocking ADB in games?

Options:

  1. Use emulator with root access (for example, Genymotion with Magisk).
  2. Connect to the device via Wi-Fi (adb connect IP:PORT).
  3. Use alternative input methods (for example, OctoWiFi or Scrcpy).

If the game is blocking input tap, try sending events via uiautomator:

adb shell uiautomator dump /sdcard/window.xml

adb pull /sdcard/window.xml

โ“ How to make a bot for a game with 3D graphics (for example, Genshin Impact)?

3D games require:

  1. Object recognition via computer vision (YOLO, TensorFlow Object Detection).
  2. Imitation of swipes with variable speed (in Genshin Impact anti-cheat from