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
IMEIorAndroid 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.
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:
- Download Platform Tools (includes
adb.exe). - Install Python from the official website (check the "Add to PATH" box).
- Connect the phone to the PC and execute in the command line line:
adb devicesIf 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
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 cv2import 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 subprocessimport 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:
- Connect the device to the PC.
- Start the game and go to the desired screen.
- 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 swipewith variable parameters).
- ๐ Code obfuscation:
- Compile Python-script in
.exeby using PyInstaller. - Encrypt command strings
ADB.
- Compile Python-script in
- ๐ก๏ธ Change device signature:
- Change
Android ID,IMEI(requires root). - Use VPN to change IP (but this may cause suspicions).
- Change
An example of a โhumanoidโ click with errors:
import randomdef 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
ADBin power saving mode).
To minimize problems:
- Test on an emulator with a fixed resolution (for example,
720ร1280). - Add logging:
with open("bot_log.txt", "a") as f:f.write(f"{time.strftime('%H:%M:%S')} - Click on ({x}, {y})\n") - Handle exceptions:
try:tap_screen(BUTTON_X, BUTTON_Y)
except subprocess.CalledProcessError:
print("ADB error! Check your connection.") - Use relative coordinates:
# Example: button in the center of the screenscreen_width = 1080
screen_height = 2340
center_x = screen_width // 2
center_y = screen_height // 2
If the bot stopped working after updating the game:
- Take a new screenshot and update the coordinates.
- Check if the interface has changed (for example, new animation has been added).
- Update
ADBand 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
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 cv2Loading 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 pytesseractfrom 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:
- The neural network analyzes the screenshot (input: screen pixels).
- Determines the current state of the game (for example, the positions of units).
- Selects the optimal action (for example, attack or movement).
- 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:
<serviceandroid: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:
- Use emulator with root access (for example, Genymotion with Magisk).
- Connect to the device via Wi-Fi (
adb connect IP:PORT). - 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:
- Object recognition via computer vision (YOLO, TensorFlow Object Detection).
- Imitation of swipes with variable speed (in Genshin Impact anti-cheat from