Protections Overview
Shield provides 9 protections plus class repackaging that work individually or together to create layered security for your Android application. 7 protections are available via the Gradle DSL; 2 additional protections (Reference Proxy and Resource Protection) are available exclusively through the CLI/JSON config.
Protection Categories
Code Obfuscation
These protections make your code harder to understand when decompiled:
| Protection | CLI/JSON Name | DSL Property | Effect |
|---|---|---|---|
| Name Obfuscation | NameObfuscation | nameObfuscation | Renames classes, methods, and fields to short meaningless identifiers |
| Control Flow Obfuscation | ControlFlowMatrix | controlFlowObfuscation | Restructures method logic with opaque predicates and dead code paths |
| Reference Proxy | ReferenceProxy | CLI/JSON only | Redirects method and field calls through generated proxy methods |
Data Protection
These protections hide sensitive data embedded in bytecode:
| Protection | CLI/JSON Name | DSL Property | Effect |
|---|---|---|---|
| String Encryption | StringEncryption | stringEncryption | Encrypts string literals, decrypted at runtime |
| Constant Mutation | ConstantMutation | constantMutation | Replaces numeric constants with arithmetic expressions |
| Resource Protection | ResourceProtection | CLI/JSON only | Encrypts embedded resources within the JAR/APK |
Runtime Protections
These protections detect and respond to attacks at runtime:
| Protection | CLI/JSON Name | DSL Property | Effect |
|---|---|---|---|
| Anti-Debug | AntiDebug | antiDebug | Detects debuggers, Frida, Xposed, and instrumentation tools |
| Anti-Tamper | AntiTamper | antiTamper | Verifies application integrity, detects package modifications |
| Debug Removal | DebugInfoRemoval | debugRemoval | Strips debug metadata from bytecode |
Repackaging
| Option | CLI/JSON Name | DSL Property | Effect |
|---|---|---|---|
| Repackage Classes | repackageClasses | repackageClasses | Moves all classes into a single flat package, eliminating the original package structure |
| Repackage Target | repackageClassesTargetPackage | repackageClassesTargetPackage | Target package name (default "a") |
Recommended Configurations
Baseline — mobile preset
For most Android applications. Safe and effective:
shield {
preset("mobile")
// Enables: stringEncryption, constantMutation, debugRemoval, antiDebug
}shield {
preset("mobile")
// Enables: stringEncryption, constantMutation, debugRemoval, antiDebug
}Standard — server preset
For backend JVM apps or Android apps that need name obfuscation:
shield {
preset("server")
// Enables: stringEncryption, constantMutation, debugRemoval, nameObfuscation
}shield {
preset("server")
// Enables: stringEncryption, constantMutation, debugRemoval, nameObfuscation
}Maximum — aggressive preset
For financial, healthcare, or other security-critical applications:
shield {
preset("aggressive")
// Enables: ALL protections + repackageClasses
}shield {
preset("aggressive")
// Enables: ALL protections + repackageClasses
}If R8 is enabled (minifyEnabled true), override nameObfuscation = false after the preset and let R8 handle renaming.
Protection Compatibility
All 9 protections can be enabled simultaneously. They are applied in a specific order to avoid conflicts:
- Debug Removal (strips metadata)
- String Encryption (encrypts literals)
- Constant Mutation (transforms constants)
- Reference Proxy (redirects calls through proxies)
- Resource Protection (encrypts embedded resources)
- Name Obfuscation (renames identifiers)
- Control Flow Obfuscation (restructures logic)
- Anti-Debug (injects runtime checks)
- Anti-Tamper (injects integrity verification)
Excluding Elements from Protection
Use annotations to exclude individual classes, methods, or fields from protection:
@Keep // Exclude from ALL protections
@DoNotObfuscate // Exclude from name obfuscation only
@Exclude(protections = {"StringEncryption"}) // Exclude from specific protections@Keep // Exclude from ALL protections
@DoNotObfuscate // Exclude from name obfuscation only
@Exclude(protections = {"StringEncryption"}) // Exclude from specific protectionsProtection names for annotations and per-protection exclusions: StringEncryption, ConstantMutation, DebugInfoRemoval, NameObfuscation, ControlFlowMatrix, AntiDebug, AntiTamper, ReferenceProxy, ResourceProtection.
Use excluded packages to skip entire package trees.
Related
- Annotations — Fine-grained protection control
- Excluded Packages — Skip entire packages
- Best Practices — Recommendations for production deployments