Integrating AndroidMonitor for In‑App Network Packet Capture on Android
This article introduces AndroidMonitor, a lightweight Android packet‑capture library, explains how to add its monitor and monitor‑plugin dependencies, configure ProGuard, customize entry names, ports and logos, and optionally use AndroidLocalService to expose captured data via a local socket for both mobile and PC UI visualization.
When a tester reports missing data during a game session, developers often waste time checking logs; integrating a packet‑capture tool like AndroidMonitor lets anyone view request data directly on the device, freeing developers to focus on coding.
AndroidMonitor (https://github.com/lygttpod/AndroidMonitor) provides visualized network request data with only two configuration steps, making it accessible to non‑technical team members.
Integration steps:
1. Add the monitor library to the app module:
debugImplementation 'io.github.lygttpod:monitor:0.0.4'2. Add the monitor‑plugin to the project‑level build.gradle :
buildscript {\n dependencies {\n // ...\n classpath 'io.github.lygttpod:monitor-plugin:0.0.1'\n }\n}3. Apply the plugin in the app module:
apply plugin: 'monitor-plugin'The plugin automatically injects an OkHttp interceptor at compile time, so developers do not need to add interceptors manually.
ProGuard configuration (already added):
# monitor\n-keep class com.lygttpod.monitor.** { *; }Personalization options: change the desktop entry name via string.xml , replace the logo with monitor_logo.png , set a unique port (default 8080), and define custom properties in assets/monitor.properties for multiple projects.
AndroidMonitor stores captured data in a Room database; sample DAO interfaces and queries are provided to retrieve, insert, update, and delete MonitorData records.
For richer interaction, AndroidLocalService (https://github.com/lygttpod/android-local-service) can be used to expose a local HTTP service built on NanoHttpd. Example service definition:
@Service(port = 9527)\nabstract class AndroidService {\n @Page("index")\n fun getIndexFileName() = "test_page.html"\n @Get("query")\n fun query(aaa: Boolean, bbb: Double, ccc: Float, ddd: String, eee: Int): List
{\n return listOf("$aaa", "$bbb", "$ccc", "$ddd", "$eee")\n }\n // additional endpoints...\n}After initializing ALSHelper.init(this) and starting the service, the endpoints can be accessed via http:// :9527/index from any browser, allowing both mobile and PC UI to display captured request data.
In summary, AndroidMonitor offers a simple, configurable solution for real‑time network debugging on Android, with optional local socket service support for cross‑device data visualization.
Sohu Tech Products
A knowledge-sharing platform for Sohu's technology products. As a leading Chinese internet brand with media, video, search, and gaming services and over 700 million users, Sohu continuously drives tech innovation and practice. We’ll share practical insights and tech news here.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.