Support minification with better consumer proguard rules
@brettchabot is already working on this.
Since Mar 11, 2024.
Assessment
This issue has not been assessed yet.
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
In androidx.benchmark we're looking to add these rules on our own 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, 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.5androidx.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
- Dominant language
- Java
- Stars
- 1.2k
- Forks
- 342
- Avg merge
- 1d 14h
- Merged PRs (30d)
- 5
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from android/android-test
-
Difficulty 1/5 Under an hour Newbie friendliness 62/100
android/android-test#681 · 2 comments · 1 reaction ·
-
Difficulty 3/5 1-2 days Newbie friendliness 72/100
android/android-test#2507 · 1 comment ·
-
ξεκσνδξδ Open
Difficulty 5/5 Over a week Newbie friendliness 1/100
android/android-test#2499 ·
-
ησξξσ Open
Difficulty 5/5 Over a week Newbie friendliness 1/100
android/android-test#2498 ·
-
Difficulty 4/5 3-5 days Newbie friendliness 38/100
android/android-test#2473 ·
All issues in android/android-test
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
-
Difficulty 1/5 Under an hour Newbie friendliness 88/100
checkstyle/test-configs#263 ·
-
bug
Difficulty 1/5 Under an hour Newbie friendliness 90/100
apache/cloudstack#14222 ·
-
[BUG]茶杯方块在取茶时会引发崩溃 Open
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
-
1.0.0-alpha2 Type/Improvement
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
wso2/dpdp-accelerator#272 ·