/

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:

Kotlin
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.


Development (Debug)

During development, you want fast builds and debuggable code. Disable Shield entirely or use no protections:

Kotlin
shield {
    variant("debug") {
        projectToken = "your-token"
        verbose = true
        protections {
            stringEncryption = false
            debugRemoval = false
        }
    }
}

Production (Release)

For release builds, use a preset for quick configuration:

Kotlin
shield {
    variant("release") {
        projectToken = "your-token"
        preset("aggressive")
    }
}

Or configure protections individually:

Kotlin
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:

Kotlin
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:

Kotlin
android {
    flavorDimensions += "tier"
    productFlavors {
        create("free") { dimension = "tier" }
        create("pro") { dimension = "tier" }
    }
}

shield {
    variant("freeRelease") {
        preset("mobile")
    }

    variant("proRelease") {
        preset("aggressive")
    }
}

Previous
Gradle DSL Reference