Gradle Setup
This guide covers the complete Gradle setup for Shield, including repository configuration, plugin application, and runtime dependency installation.
Requirements
| Requirement | Minimum | Recommended |
|---|---|---|
| Android Gradle Plugin | 7.0 | 8.0+ |
| Java | 11 | 17 |
| Kotlin (if used) | 1.8 | 1.9+ |
| Gradle | 7.4 | 8.0+ |
| minSdk | 21 | — |
Step 1: Configure Repositories
Shield is published on Maven Central. Add the standard repositories to your settings.gradle if you don't have them already:
Groovy DSL
// settings.gradle
pluginManagement {
repositories {
google()
mavenCentral()
gradlePluginPortal()
}
}
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
google()
mavenCentral()
}
}// settings.gradle
pluginManagement {
repositories {
google()
mavenCentral()
gradlePluginPortal()
}
}
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
google()
mavenCentral()
}
}Kotlin DSL
// settings.gradle.kts
pluginManagement {
repositories {
google()
mavenCentral()
gradlePluginPortal()
}
}
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
google()
mavenCentral()
}
}// settings.gradle.kts
pluginManagement {
repositories {
google()
mavenCentral()
gradlePluginPortal()
}
}
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
google()
mavenCentral()
}
}Step 2: Apply the Plugin
Add the Shield plugin to your app module's build.gradle:
Groovy DSL
// app/build.gradle
plugins {
id 'com.android.application'
id 'org.jetbrains.kotlin.android'
id 'com.bytehide.shield' version '1.0.0'
}// app/build.gradle
plugins {
id 'com.android.application'
id 'org.jetbrains.kotlin.android'
id 'com.bytehide.shield' version '1.0.0'
}Kotlin DSL
// app/build.gradle.kts
plugins {
id("com.android.application")
id("org.jetbrains.kotlin.android")
id("com.bytehide.shield") version "1.0.0"
}// app/build.gradle.kts
plugins {
id("com.android.application")
id("org.jetbrains.kotlin.android")
id("com.bytehide.shield") version "1.0.0"
}Shield also supports com.android.library modules. Apply the plugin to any module that contains code you want to protect.
Step 3: Add the Runtime Dependency
Shield requires a lightweight runtime library for decrypting strings at runtime:
Groovy DSL
dependencies {
implementation 'com.bytehide:shield-java-runtime:1.0.0'
}dependencies {
implementation 'com.bytehide:shield-java-runtime:1.0.0'
}Kotlin DSL
dependencies {
implementation("com.bytehide:shield-java-runtime:1.0.0")
}dependencies {
implementation("com.bytehide:shield-java-runtime:1.0.0")
}The runtime library is small (under 20KB) and contains only the StringDecryptor class and anti-debug detectors. It has no transitive dependencies.
Step 4: Configure Shield
Add the shield block with your project token and desired protections:
Groovy DSL
shield {
projectToken = System.getenv('SHIELD_PROJECT_TOKEN')
protections {
stringEncryption = true
constantMutation = true
debugRemoval = true
nameObfuscation = true
controlFlowObfuscation = true
antiDebug = true
referenceProxy = true
resourceProtection = true
antiTamper = true
}
excludedPackages = [
'android',
'androidx',
'kotlin',
'kotlinx'
]
verbose = true
}shield {
projectToken = System.getenv('SHIELD_PROJECT_TOKEN')
protections {
stringEncryption = true
constantMutation = true
debugRemoval = true
nameObfuscation = true
controlFlowObfuscation = true
antiDebug = true
referenceProxy = true
resourceProtection = true
antiTamper = true
}
excludedPackages = [
'android',
'androidx',
'kotlin',
'kotlinx'
]
verbose = true
}Kotlin DSL
shield {
projectToken = System.getenv("SHIELD_PROJECT_TOKEN")
protections {
stringEncryption = true
constantMutation = true
debugRemoval = true
nameObfuscation = true
controlFlowObfuscation = true
antiDebug = true
referenceProxy = true
resourceProtection = true
antiTamper = true
}
excludedPackages = listOf(
"android",
"androidx",
"kotlin",
"kotlinx"
)
verbose = true
}shield {
projectToken = System.getenv("SHIELD_PROJECT_TOKEN")
protections {
stringEncryption = true
constantMutation = true
debugRemoval = true
nameObfuscation = true
controlFlowObfuscation = true
antiDebug = true
referenceProxy = true
resourceProtection = true
antiTamper = true
}
excludedPackages = listOf(
"android",
"androidx",
"kotlin",
"kotlinx"
)
verbose = true
}See Gradle DSL Reference for all available options.
AGP Compatibility
Shield automatically detects your Android Gradle Plugin version and uses the appropriate integration:
| AGP Version | Integration Method | Notes |
|---|---|---|
| 8.0+ | Artifacts API | Recommended. Modern API with better performance |
| 7.0–7.4 | Transform API | Legacy API. Functional but deprecated by Google |
| < 7.0 | Not supported | Upgrade your AGP version |
No configuration is required — Shield detects the AGP version and uses the correct integration automatically.
Project Types
| Project Type | Plugin | Supported |
|---|---|---|
| Android Application | com.android.application | Yes |
| Android Library | com.android.library | Yes |
Verify Installation
After configuring Shield, run a build to verify:
./gradlew assembleRelease./gradlew assembleReleaseIf verbose = true, you will see Shield's output in the build log confirming protections were applied.
Related
- Project Token — How to obtain and configure your token
- Gradle DSL Reference — Complete configuration reference
- R8 & ProGuard Compatibility — Using Shield alongside R8