/

Excluded Packages

Excluded packages tell Shield which packages to skip during protection. This prevents issues with framework classes, Kotlin runtime internals, and third-party libraries that are not designed to be obfuscated.


Default Exclusions

At minimum, always exclude the Android and Kotlin runtime packages:

Groovy
shield {
    excludedPackages = [
        'android',
        'androidx',
        'kotlin',
        'kotlinx'
    ]
}

These packages contain framework code that must retain its original structure for the Android runtime to function correctly.


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

Excluding a package tells Shield to process it as-is, without applying any transformations.


Common Exclusions

PackageWhy Exclude
androidAndroid framework classes
androidxAndroidX support libraries
kotlinKotlin standard library
kotlinxKotlin extensions (coroutines, serialization)
com.googleGoogle Play Services, Firebase, Gson
com.squareupOkHttp, Retrofit, Moshi
daggerDagger/Hilt dependency injection
com.fasterxmlJackson JSON library
org.slf4jSLF4J logging

Example with Common Libraries

Groovy
shield {
    excludedPackages = [
        'android',
        'androidx',
        'kotlin',
        'kotlinx',
        'com.google',
        'com.squareup',
        'dagger',
        'javax.inject'
    ]
}

Excluding vs Annotations

Package exclusions are broad — they skip entire package trees. For fine-grained control over individual classes or methods, use annotations instead:

ApproachScopeUse Case
excludedPackagesEntire package treeThird-party libraries, framework code
@KeepClass, method, field, constructorIndividual elements that use reflection
@DoNotObfuscateClass, method, field, constructorElements that must keep their name
@Exclude(protections={...})Class, method, field, constructorExclude from specific protections only

Using excludePackages Method

In addition to setting the excludedPackages list, you can use the excludePackages method in variant configurations:

Groovy
shield {
    excludedPackages = ['android', 'androidx', 'kotlin', 'kotlinx']

    all {
        excludePackages('com.google', 'com.squareup')
    }
}

Previous
Variant Configuration