Anti-Debug
Protection ID: antiDebug
Anti-Debug injects runtime checks that detect when your application is being analyzed with debugging tools, instrumentation frameworks, or emulators. When a debugger or tool is detected, the application throws a SecurityException.
Configuration
shield {
protections {
antiDebug = true
}
}shield {
protections {
antiDebug = true
}
}How It Works
Anti-debug protection prevents dynamic analysis of your application at runtime. When enabled, Shield injects detection checks at strategic points in your application code. These checks run continuously and cover multiple attack vectors, from standard Java debuggers to advanced instrumentation frameworks like Frida and Xposed.
If any check detects an analysis tool, the application throws a SecurityException, preventing the attacker from continuing their analysis.
What Gets Detected
| Detection | What It Detects |
|---|---|
| Debugger | Java debuggers (Android Studio, JDWP) |
| Debuggable flag | FLAG_DEBUGGABLE set in the APK manifest |
| Process tracing | ptrace-based tools (gdb, lldb) attached to the process |
| Frida | Frida agent libraries loaded into process memory |
| Timing anomaly | Single-stepping through a debugger (slows execution) |
| Xposed | Xposed framework hooks present in the runtime |
| Emulator | Android emulator environment properties |
Behavior in Development
During development, anti-debug will trigger if you run the app in debug mode from Android Studio. For this reason, it is recommended to only enable anti-debug in release variants:
shield {
variant('debug') {
protections {
antiDebug = false
}
}
variant('release') {
protections {
antiDebug = true
}
}
}shield {
variant('debug') {
protections {
antiDebug = false
}
}
variant('release') {
protections {
antiDebug = true
}
}
}When to Use
Anti-debug protection is recommended for production builds of applications that handle payments or financial transactions, implement license validation or DRM, contain proprietary algorithms or business logic, process sensitive user data, or need to prevent tampering via runtime instrumentation.
Do not enable anti-debug in development or QA builds, as it will prevent normal debugging workflows.
Related
- Anti-Tamper - Detect package modifications
- Variant Configuration - Enable per build type
- Protections Overview - All available protections