/

Gradle Setup

This guide covers the complete Gradle setup for Shield, including repository configuration, plugin application, and runtime dependency installation.


Requirements

RequirementMinimumRecommended
Android Gradle Plugin7.08.0+
Java1117
Kotlin (if used)1.81.9+
Gradle7.48.0+
minSdk21

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

Groovy
// settings.gradle
pluginManagement {
    repositories {
        google()
        mavenCentral()
        gradlePluginPortal()
    }
}

dependencyResolutionManagement {
    repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
    repositories {
        google()
        mavenCentral()
    }
}

Kotlin DSL

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

Groovy
// app/build.gradle
plugins {
    id 'com.android.application'
    id 'org.jetbrains.kotlin.android'
    id 'com.bytehide.shield' version '1.0.0'
}

Kotlin DSL

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

Groovy
dependencies {
    implementation 'com.bytehide:shield-java-runtime:1.0.0'
}

Kotlin DSL

Kotlin
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

Groovy
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

Kotlin
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 VersionIntegration MethodNotes
8.0+Artifacts APIRecommended. Modern API with better performance
7.0–7.4Transform APILegacy API. Functional but deprecated by Google
< 7.0Not supportedUpgrade your AGP version

No configuration is required — Shield detects the AGP version and uses the correct integration automatically.


Project Types

Project TypePluginSupported
Android Applicationcom.android.applicationYes
Android Librarycom.android.libraryYes

Verify Installation

After configuring Shield, run a build to verify:

Bash
./gradlew assembleRelease

If verbose = true, you will see Shield's output in the build log confirming protections were applied.


Previous
Project Token