/

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:

Groovy
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).


Development (Debug)

During development, you want fast builds and debuggable code. Disable most protections:

Groovy
shield {
    projectToken = System.getenv('SHIELD_PROJECT_TOKEN')

    variant('debug') {
        verbose = true
        protections {
            stringEncryption = false
            constantMutation = false
            debugRemoval = false
            nameObfuscation = false
            controlFlowObfuscation = false
            antiDebug = false
            referenceProxy = false
            resourceProtection = false
            antiTamper = false
        }
    }
}

Or simply set enabled = false on the debug variant if you want to skip Shield entirely during development.

Production (Release)

For release builds, enable all protections that your application supports:

Groovy
shield {
    variant('release') {
        protections {
            stringEncryption = true
            constantMutation = true
            debugRemoval = true
            nameObfuscation = true
            controlFlowObfuscation = true
            antiDebug = true
            referenceProxy = true
            resourceProtection = true
            antiTamper = true
        }
    }
}

Using all { }

The all block applies configuration to every variant. Use it for settings that should be consistent across all builds:

Groovy
shield {
    projectToken = System.getenv('SHIELD_PROJECT_TOKEN')

    all {
        excludePackages('android', 'androidx', 'kotlin', 'kotlinx')
    }

    variant('debug') {
        verbose = true
        protections {
            stringEncryption = false
        }
    }

    variant('release') {
        protections {
            stringEncryption = true
            constantMutation = true
            controlFlowObfuscation = true
            antiDebug = 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:

Groovy
android {
    flavorDimensions 'tier'
    productFlavors {
        free { dimension 'tier' }
        pro { dimension 'tier' }
    }
}

shield {
    variant('freeRelease') {
        protections {
            stringEncryption = true
            antiDebug = true
        }
    }

    variant('proRelease') {
        protections {
            stringEncryption = true
            constantMutation = true
            controlFlowObfuscation = true
            antiDebug = true
            antiTamper = true
        }
    }
}

Previous
Gradle DSL Reference