/

Excluded Packages

Shield provides multiple ways to exclude classes, methods, and packages from obfuscation. Exclusions can be global (all protections) or per-protection (only specific protections).


Auto-Excluded Packages

User code only (Gradle plugin)

With the Gradle plugin, Shield only processes your project's own compiled source code by default. Dependency JARs are not obfuscated unless explicitly opted in with includePackages(). The auto-exclusions below are mainly relevant when using the CLI, where all input JARs are treated as program classes.

Shield automatically excludes known library and framework packages. No configuration needed for these:

CategoryPackages
Java SDKjava, javax, sun, jdk
Kotlinkotlin, kotlinx
Androidandroid, androidx, com.android, dalvik
ByteHidecom.bytehide.monitor, com.bytehide.runtime
Serializationcom.fasterxml.jackson, com.google.gson
HTTPokhttp3, com.squareup.okhttp, okio, retrofit2, com.squareup.retrofit2
Googlecom.google.firebase, com.google.gms, com.google.protobuf, com.google.crypto
DIdagger, javax.inject
Reactiveio.reactivex
Cryptoorg.bouncycastle
Loggingorg.slf4j, org.apache.log4j, java.util.logging
Frameworksorg.jetbrains, com.google.common (Guava)

You only need to add exclusions for your own packages that use reflection, serialization, or other mechanisms that require original names.


Including Dependencies

By default, the Gradle plugin only obfuscates your project's source code. To also obfuscate a specific dependency (e.g., an internal company library distributed as a JAR), use includePackages():

Kotlin
shield {
    projectToken = "your-token"
    preset("mobile")
    includePackages("com.mycompany.internal-lib")
}

Without includePackages, dependency JARs are passed through without modification.


Global Exclusion (All Protections)

Exclude packages from all protections using the excludePackages method:

Kotlin DSL

Kotlin
shield {
    excludePackages("com.example.models", "com.example.api")
}

Groovy DSL

Groovy
shield {
    excludePackages "com.example.models", "com.example.api"
}

Per-Variant Exclusions

Kotlin
shield {
    variant("release") {
        projectToken = "your-token"
        excludePackages("com.example.debug")

        protections {
            stringEncryption = true
        }
    }
}

Per-Protection Exclusion

Append :Protection1,Protection2 to a package name to exclude it only from specific protections:

Kotlin
shield {
    excludePackages(
        "com.example.models",                                  // exclude from ALL protections
        "com.example.networking:ControlFlowMatrix",            // exclude only from ControlFlow
        "com.example.legacy:StringEncryption,ConstantMutation" // exclude from two protections
    )
}

This is useful when you want a package to get some protections but not others. For example, skip control flow on UI code for performance, but still encrypt its strings.

Protection Names

NameDescription
StringEncryptionXOR-based string encryption
ControlFlowMatrixControl flow obfuscation with opaque predicates
ConstantMutationInteger/constant mutation
NameObfuscationClass, method, and field renaming
DebugInfoRemovalRemoves source file names and line numbers
AntiDebugDebugger/emulator detection
AntiTamperAPK/JAR integrity validation
ReferenceProxyMethod/field call redirection through proxies (CLI/JSON only)
ResourceProtectionEmbedded resource encryption (CLI/JSON only)

Annotation-Based Exclusion

For fine-grained control at the source code level, use Shield annotations:

Java
import com.bytehide.shield.annotations.Keep;
import com.bytehide.shield.annotations.DoNotObfuscate;
import com.bytehide.shield.annotations.Exclude;

@Keep                  // Exclude from ALL protections
public class UserModel { }

@DoNotObfuscate        // Exclude from renaming only
public class ApiService { }

@Exclude(protections = {"StringEncryption"})  // Exclude from specific protections
public class LogHelper { }

See Annotations for the full annotation guide.


Why Exclude Packages

Shield transforms bytecode: it renames identifiers, encrypts strings, and restructures control flow. This can break code that relies on:

  • Reflection — Frameworks that look up classes or methods by name (Gson, Retrofit, Room)
  • Serialization — Libraries that map JSON keys to field names (Moshi, Jackson)
  • Annotation processing — Code generated by annotation processors (Dagger, Hilt)
  • Native interop — JNI methods that must match specific signatures

Common Exclusions

PackageWhy Exclude
com.example.modelsData classes used by Gson/Retrofit
com.example.apiAPI interfaces used by Retrofit
com.example.ui:ControlFlowMatrixSkip control flow on Compose UI (performance)

Example: Typical Android App

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

        excludePackages(
            "com.myapp.data.models",                   // Used by Gson/Retrofit
            "com.myapp.data.api",                      // Used by Retrofit
            "com.myapp.ui:ControlFlowMatrix"           // Performance
        )

        protections {
            stringEncryption = true
            controlFlowObfuscation = true
            constantMutation = true
            debugRemoval = true
        }
    }
}

Decision Priority

When multiple exclusion mechanisms overlap, Shield evaluates in this order (first match wins):

  1. Method exclusionexcludedMethods / @Keep on method
  2. Class exclusionexcludedClasses / @Keep on class
  3. Global package exclusionexcludePackages (without :)
  4. Per-protection package exclusionexcludePackages (with :Protection)
  5. Auto-detection — Built-in library packages

If none match, the protection is applied.


Previous
Variant Configuration