Overview
Exclusions are configured in therefractor section using glob patterns:
- ✅ Compiled normally
- ❌ Skipped by all obfuscation passes
- ✅ Included in the final binary
Exclusions apply only to project libraries. External dependencies (packages from pub.dev) are never obfuscated, regardless of exclusion rules.
Configuration
Syntax
List<String> (glob patterns)Default:
[] (no exclusions)
Example
Glob Pattern Syntax
Refractor uses glob patterns to match file paths.Basic Patterns
*
Match any characters except
/**
Match any characters including
/?
Match exactly one character
[abc]
Match one character from set
Pattern Examples
Exclude all .g.dart files
Exclude all .g.dart files
lib/models/user.g.dart✓lib/api/response.g.dart✓test/fixtures/data.g.dart✓
lib/models/user.dart✗lib/g.dart✗
Exclude a specific directory
Exclude a specific directory
lib/generated/routes.dart✓lib/generated/api/client.dart✓
lib/routes.dart✗lib/api/generated.dart✗
Exclude multiple extensions
Exclude multiple extensions
lib/user.g.dart✓lib/model.freezed.dart✓lib/routes.gr.dart✓
Exclude specific files
Exclude specific files
lib/main.dart✓lib/config/env.dart✓
lib/app.dart✗lib/config/settings.dart✗
Exclude test files
Exclude test files
test/widget_test.dart✓lib/utils_test.dart✓
Test files are usually not included in production builds, so this is typically unnecessary.
Common Exclusion Patterns
Here are patterns for popular Dart code generation tools:json_serializable
Freezed
Auto Route
Moor/Drift
Complete Example
For a typical Flutter project:How Exclusions Work
Matching Process
Scope Rules
Project libraries include:- Files under the working directory
- Libraries with URIs matching the
pubspec.yamlpackage name
pubspec.yaml has:
- ✅
package:myapp/main.dart - ✅
file:///path/to/project/lib/utils.dart - ❌
package:flutter/widgets.dart(external) - ❌
package:http/http.dart(external)
Pass Interaction
Excluded libraries are skipped by all obfuscation passes:Rename
Classes, methods, fields keep original names
String Encrypt
String literals remain unencrypted
Dead Code
No dead code blocks inserted
Excluded libraries can reference obfuscated symbols from non-excluded libraries. Only the excluded file itself remains unchanged.
Why Exclude Files?
Generated Code
Code generators often rely on reflection, naming conventions, or JSON structure matching:Platform Channels
Flutter platform channels require exact method names:Configuration Files
Files with string patterns that match encryption exclusions:Debugging & Inspection
Exclude files you need to inspect during development:Verification
To verify which files are excluded:-
Enable verbose logging:
-
Run build:
-
Check output:
Troubleshooting
Generated file is still obfuscated
Generated file is still obfuscated
Cause: Pattern doesn’t match the file path.Fix: Use
verbose: true and check logs. Ensure pattern uses ** for subdirectories:Exclusion pattern not working
Exclusion pattern not working
Cause: Invalid glob syntax or typo.Fix: Test your pattern:
External package is excluded
External package is excluded
Cause: You’re trying to exclude a dependency.Fix: External packages are never obfuscated. Exclusions only affect project files.
Excluded file appears in symbol map
Excluded file appears in symbol map
Cause: Another non-excluded file references it.Fix: This is expected. The excluded file’s symbols remain original, but they may appear in the map if referenced by obfuscated code.
Implementation Details
Exclusions are processed inRefractorConfig.toOptions() (/home/daytona/workspace/source/lib/src/config/model/refractor_config.dart:66):
Glob instance and checked during library processing.
Best Practices
Related Pages
refractor.yaml
Complete configuration reference
String Encrypt Pass
Learn about string exclusion patterns