|
| 1 | +# LSParanoid Test Application |
| 2 | + |
| 3 | +Dedicated test application to verify string obfuscation works correctly in release builds with R8/ProGuard minification enabled. |
| 4 | + |
| 5 | +## Purpose |
| 6 | + |
| 7 | +This test app validates that the ProGuard rules in `core/consumer-rules.pro` are correct and that: |
| 8 | +1. Activities with `@Obfuscate` annotation can be launched without crashes |
| 9 | +2. Obfuscated strings can be retrieved via reflection (`ensureChunkLoaded` method) |
| 10 | +3. The app doesn't crash with `NoSuchMethodException` in minified release builds |
| 11 | +4. Chunk loading works correctly for multiple and concurrent string accesses |
| 12 | + |
| 13 | +## ✅ Build Verification (Automated) |
| 14 | + |
| 15 | +The most important verification is that a minified release APK with obfuscation builds successfully: |
| 16 | + |
| 17 | +```bash |
| 18 | +./gradlew :testApp:assembleRelease |
| 19 | +``` |
| 20 | + |
| 21 | +**What this proves:** |
| 22 | +- LSParanoid obfuscation is applied to all `@Obfuscate` annotated classes |
| 23 | +- R8 minification runs without errors |
| 24 | +- ProGuard consumer rules from `core/consumer-rules.pro` are correct |
| 25 | +- The `ensureChunkLoaded` method and deobfuscation infrastructure are preserved |
| 26 | + |
| 27 | +**Output:** `testApp/build/outputs/apk/release/testApp-release-unsigned.apk` (~20KB) |
| 28 | + |
| 29 | +✅ **Status**: Successfully tested - release APK builds without errors |
| 30 | + |
| 31 | +## Running Instrumented Tests |
| 32 | + |
| 33 | +### Prerequisites |
| 34 | + |
| 35 | +- Android SDK installed with API 34+ system images |
| 36 | +- At least 5GB free disk space (for system image downloads) |
| 37 | +- Working emulator or physical device |
| 38 | + |
| 39 | +### Quick Test (Gradle Managed Device - Headless) |
| 40 | + |
| 41 | +Run all tests on a managed emulator (Android 14, API 34): |
| 42 | + |
| 43 | +```bash |
| 44 | +./gradlew :testApp:pixel6api34DebugAndroidTest \ |
| 45 | + -Pandroid.testoptions.manageddevices.emulator.gpu=swiftshader_indirect |
| 46 | +``` |
| 47 | + |
| 48 | +**Note**: First run downloads ~500MB AOSP ATD system image. |
| 49 | + |
| 50 | +### On Physical Device or Connected Emulator |
| 51 | + |
| 52 | +```bash |
| 53 | +# Debug build (no minification, tests obfuscation only) |
| 54 | +./gradlew :testApp:connectedDebugAndroidTest |
| 55 | + |
| 56 | +# Release build (full minification + obfuscation) |
| 57 | +./gradlew :testApp:connectedReleaseAndroidTest |
| 58 | +``` |
| 59 | + |
| 60 | +### With Display (For Debugging) |
| 61 | + |
| 62 | +To see the emulator while tests run: |
| 63 | + |
| 64 | +```bash |
| 65 | +./gradlew :testApp:pixel6api34DebugAndroidTest --enable-display |
| 66 | +``` |
| 67 | + |
| 68 | +## CI/CD Usage |
| 69 | + |
| 70 | +For GitHub Actions or other CI environments: |
| 71 | + |
| 72 | +```bash |
| 73 | +# Build verification (no emulator needed) |
| 74 | +./gradlew :testApp:assembleRelease |
| 75 | + |
| 76 | +# Full instrumented tests (requires emulator) |
| 77 | +./gradlew :testApp:pixel6api34DebugAndroidTest \ |
| 78 | + -Pandroid.testoptions.manageddevices.emulator.gpu=swiftshader_indirect |
| 79 | +``` |
| 80 | + |
| 81 | +## Test Configuration |
| 82 | + |
| 83 | +- **Managed Device**: Pixel 6 API 34 (Android 14) |
| 84 | +- **System Image**: AOSP ATD (Automated Test Device) optimized for headless CI |
| 85 | +- **Build Types**: |
| 86 | + - Debug: Obfuscation enabled, no minification (faster tests) |
| 87 | + - Release: Full minification + obfuscation (production-like) |
| 88 | +- **Test Framework**: AndroidX Test + JUnit4 + Espresso |
| 89 | + |
| 90 | +## What Gets Tested |
| 91 | + |
| 92 | +### ObfuscationTest.java |
| 93 | + |
| 94 | +1. **testApplicationContext**: Verifies basic app initialization with obfuscated code |
| 95 | +2. **testObfuscatedActivityLaunches**: Tests activity with multiple obfuscated string constants |
| 96 | +3. **testObfuscatedUtilityClass**: Tests static utility class with obfuscated strings |
| 97 | +4. **testMultipleObfuscatedStringAccess**: Validates chunk loading with 100+ repeated accesses |
| 98 | +5. **testConcurrentStringAccess**: Tests thread safety with 10 threads × 50 accesses each |
| 99 | + |
| 100 | +## Build Outputs |
| 101 | + |
| 102 | +After running tests, check: |
| 103 | +- **Debug APK**: `testApp/build/outputs/apk/debug/testApp-debug.apk` |
| 104 | +- **Release APK**: `testApp/build/outputs/apk/release/testApp-release-unsigned.apk` |
| 105 | +- **ProGuard mapping**: `testApp/build/outputs/mapping/release/mapping.txt` |
| 106 | +- **Test results**: `testApp/build/reports/androidTests/` |
| 107 | + |
| 108 | +## Troubleshooting |
| 109 | + |
| 110 | +### NoSuchMethodException in Release Build |
| 111 | + |
| 112 | +If you see `NoSuchMethodException: m32.ensureChunkLoaded [int]`: |
| 113 | +- The ProGuard patterns in `core/consumer-rules.pro` don't match generated code |
| 114 | +- Verify the pattern is `**.Deobfuscator` (NOT `**.Deobfuscator$**`) |
| 115 | +- Check consumer rules are applied: examine the mapping file |
| 116 | + |
| 117 | +### Managed Device Won't Start |
| 118 | + |
| 119 | +- Ensure Android SDK includes API 34 system images |
| 120 | +- First run downloads system image (500MB+, several minutes) |
| 121 | +- Requires at least 5GB free disk space |
| 122 | +- Use `--info` flag for detailed output |
| 123 | + |
| 124 | +### R8 Compilation Errors |
| 125 | + |
| 126 | +If R8 fails with missing class warnings: |
| 127 | +- Check `testApp/build/outputs/mapping/debugAndroidTest/missing_rules.txt` |
| 128 | +- Add `-dontwarn` rules to `testApp/proguard-rules.pro` |
| 129 | + |
| 130 | +### Tests Pass on Debug but Fail on Release |
| 131 | + |
| 132 | +This indicates a ProGuard configuration issue: |
| 133 | +- R8 is removing obfuscation infrastructure in release builds |
| 134 | +- Check `core/consumer-rules.pro` is in `META-INF/proguard/` |
| 135 | +- Verify rules match actual generated class structure |
| 136 | + |
| 137 | +## Verifying ProGuard Rules |
| 138 | + |
| 139 | +To see what's kept after minification: |
| 140 | + |
| 141 | +```bash |
| 142 | +./gradlew :testApp:assembleRelease |
| 143 | +grep -i deobfuscator testApp/build/outputs/mapping/release/mapping.txt |
| 144 | +``` |
| 145 | + |
| 146 | +You should see the Deobfuscator class and `ensureChunkLoaded` method preserved (though renamed). |
0 commit comments