/

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

Groovy
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

DetectionWhat It Detects
DebuggerJava debuggers (Android Studio, JDWP)
Debuggable flagFLAG_DEBUGGABLE set in the APK manifest
Process tracingptrace-based tools (gdb, lldb) attached to the process
FridaFrida agent libraries loaded into process memory
Timing anomalySingle-stepping through a debugger (slows execution)
XposedXposed framework hooks present in the runtime
EmulatorAndroid 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:

Groovy
shield {
    variant('debug') {
        protections {
            antiDebug = false
        }
    }

    variant('release') {
        protections {
            antiDebug = true
        }
    }
}

See Variant Configuration.


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.


Previous
Resource Protection