Variant Configuration
Shield supports per-variant configuration so you can apply different protection levels to debug and release builds. This lets you develop with minimal friction while shipping fully protected releases.
How Variants Work
Android projects have build variants composed of build types (debug, release) and product flavors. Shield lets you configure protections for each variant independently using the variant() method:
shield {
variant("debug") {
// Configuration for debug builds
}
variant("release") {
// Configuration for release builds
}
}shield {
variant("debug") {
// Configuration for debug builds
}
variant("release") {
// Configuration for release builds
}
}The variant name must match an existing Android build variant. Common values are debug and release, but custom build types and product flavor combinations also work (e.g., stagingRelease, freeDebug).
Shield matches configurations to variants in this order: exact match (variant("freeRelease") matches freeRelease), build type match (variant("release") matches freeRelease, paidRelease, etc.), and top-level DSL as wildcard.
Recommended Setup
Development (Debug)
During development, you want fast builds and debuggable code. Disable Shield entirely or use no protections:
shield {
variant("debug") {
projectToken = "your-token"
verbose = true
protections {
stringEncryption = false
debugRemoval = false
}
}
}shield {
variant("debug") {
projectToken = "your-token"
verbose = true
protections {
stringEncryption = false
debugRemoval = false
}
}
}Production (Release)
For release builds, use a preset for quick configuration:
shield {
variant("release") {
projectToken = "your-token"
preset("aggressive")
}
}shield {
variant("release") {
projectToken = "your-token"
preset("aggressive")
}
}Or configure protections individually:
shield {
variant("release") {
projectToken = "your-token"
protections {
stringEncryption = true
constantMutation = true
debugRemoval = true
nameObfuscation = true
controlFlowObfuscation = true
antiDebug = true
antiTamper = true
}
}
}shield {
variant("release") {
projectToken = "your-token"
protections {
stringEncryption = true
constantMutation = true
debugRemoval = true
nameObfuscation = true
controlFlowObfuscation = true
antiDebug = true
antiTamper = true
}
}
}Using all { }
The all block applies configuration to every variant. Use it for settings that should be consistent across all builds:
shield {
all {
projectToken = System.getenv("BYTEHIDE_PROJECT_TOKEN")
}
variant("debug") {
verbose = true
protections {
stringEncryption = false
}
}
variant("release") {
preset("mobile")
protections {
controlFlowObfuscation = true
}
}
}shield {
all {
projectToken = System.getenv("BYTEHIDE_PROJECT_TOKEN")
}
variant("debug") {
verbose = true
protections {
stringEncryption = false
}
}
variant("release") {
preset("mobile")
protections {
controlFlowObfuscation = true
}
}
}Settings in variant() override settings from all() for that specific variant.
Product Flavors
If your project uses product flavors, the variant name is the combination of flavor and build type:
android {
flavorDimensions += "tier"
productFlavors {
create("free") { dimension = "tier" }
create("pro") { dimension = "tier" }
}
}
shield {
variant("freeRelease") {
preset("mobile")
}
variant("proRelease") {
preset("aggressive")
}
}android {
flavorDimensions += "tier"
productFlavors {
create("free") { dimension = "tier" }
create("pro") { dimension = "tier" }
}
}
shield {
variant("freeRelease") {
preset("mobile")
}
variant("proRelease") {
preset("aggressive")
}
}Related
- Gradle DSL Reference — Complete configuration reference
- Protections — What each protection does