android / android/android-test
Support minification with better consumer proguard rules
- Dominant language
- Java
- Stars
- 1.2k
- Forks
- 342
- Avg merge
- 11h 29m
- Merged PRs (30d)
- 2
Description
### Description
Currently, androidx.test doesn't bundle in sufficient proguard rules, which makes testing with minification difficult, especially in self-instrumenting tests which otherwise don't suffer from the test apk / app apk retention issues.
Note that AGP 8.3 [recently added support for test minification](https://issuetracker.google.com/issues/37054038#comment17)
In androidx.benchmark we're [looking to add these rules on our own](https://android-review.googlesource.com/c/platform/frameworks/support/+/2989992) for the time being, but it would be preferable and more generally useful to other libraries interested in minification if these could be handled directly by `androidx.test`.
### Steps to Reproduce
Run sample, commenting out the testProguardRules in `build.gradle`
Note that sample includes simple case (ExampleTest) and more complex case (ExampleBenchmark). Benchmark gradle plugin already sets `testBuildType="release"`
### Expected Results
Self-instrumenting `com.android.library` module tests don't require additional proguard rules by default
### Actual Results
Several failures, requiring several workarounds in proguard file (not including those from [b/328649293](https://issuetracker.google.com/issues/328649293), which are an AGP issue):
```
### basic protection against junit/androidx.test reflection, shouldn't affect library/test code
# (fixes `Custom runner class AndroidJUnit4 should have a public constructor with signature AndroidJUnit4(Class testClass)`)
-keepclasseswithmembers class androidx.test.** { *; }
# not needed in this sample, but needed in practice in more complex samples in androidx repo
-keepclasseswithmembers class org.junit.** { *; }
# not needed in this sample, but needed in practice in more complex samples in androidx repo
-keepclasseswithmembers class junit.** { *; }
# (fixes `Missing classes detected while running R8.`)
-dontwarn com.google.errorprone.annotations.MustBeClosed
### keep test classes
# (fixes `Failed loading specified test class 'com.example.benchmark.ExampleTest'`)
-keepclasseswithmembers @org.junit.runner.RunWith class * { *; }
### needed for org.junit.Test annotation to be discoverable by reflection
# (fixes `Invalid test class 'com.example.benchmark.ExampleTest': No test methods found`)
-keepattributes *Annotation*
```
### AndroidX Test and Android OS Versions
* `androidx.test.ext:junit:1.1.5`
* `androidx.test:runner:1.5.2`
* Android OS version: N/A
The above rules could likely be made much more minimal, but in microbenchmark, we know androidx.test/junit/kotlin-test are never on the critical path, so we keep aggressively.
### Link to a public git repo demonstrating the problem:
See attached repro project: [androidxTestR8MicroSample.zip](https://github.com/android/android-test/files/14563896/androidxTestR8MicroSample.zip)
Contributor guide
Assessment
This issue has not been assessed yet.