Commit d88cedb
authored
Support for Test and AndroidTest variants (AGP9) (#1914)
**Summary**
This PR adds support for the JdkImageWorkaround for Test and AndroidTest
variants in AGP 9 versions.
**Context**
When building a simple project (AGP 9.0.0-alpha13) with different JDK
vendors and minor versions, we can observe the typical `JdkImage` issue:
(Microsoft 17.0.10+7-LTS vs Oracle 17+35-LTS-2724)
<img width="1216" height="240" alt="Screenshot 2025-11-06 at 7 14 15 PM"
src="https://github.com/user-attachments/assets/1d0f98a2-0ee8-495f-bcc3-3967ec8cf203"
/>
https://ge.solutions-team.gradle.com/c/d2hemzuddld7e/olokfpw22jduw/task-inputs?task-text=compileDebugJavaWithJavac
After applying our plugin, these differences disappear:
<img width="1214" height="237" alt="Screenshot 2025-11-06 at 7 19 31 PM"
src="https://github.com/user-attachments/assets/3a598982-860d-4d21-a16d-9548f14fde4b"
/>
https://ge.solutions-team.gradle.com/c/zcwdbixu4oqay/yytjxrgh7dtwg/task-inputs?task-text=compileDebugJavaWithJavac
However, the main JavaCompile task of the build variant is not the only
one affected, both Test and AndroidTest variants also include
JavaCompile tasks that are not currently configured by the plugin. For
instance in the next screenshot we have a project that have applied the
Android Cache Fix Plugin and the workaround fixed the differences in the
main JavaCompile vaiant but not in Test and Android Test variants:
<img width="745" height="338" alt="Screenshot 2025-11-06 at 7 22 23 PM"
src="https://github.com/user-attachments/assets/6d40d14d-9f00-44f9-a316-5d1a69059833"
/>
https://ge.solutions-team.gradle.com/c/zcwdbixu4oqay/yytjxrgh7dtwg/task-inputs?task-text=compileDebugJavaWithJavac
**Root Cause**
The new API introduced in AGP 9.0.0-alpha06 allows extending the
JavaCompile task of the main variant, but not the ones for Test or
AndroidTest variants.
In the current version of the Android Cache Fix Plugin (for AGP < 9), we
provide support for the test variant using:
`android.unitTestVariants.all(configureVariant)`
However, this is deprecated and notice that we were not applying the
workaround to the AndroidTest variant.
**Fix**
This PR introduces support for both Test and AndroidTest variants using
the new `nestedComponents` API.
After applying this configuration, the issue disappears for both build
variants (using plugin on this commit deployed locally):
<img width="1014" height="230" alt="Screenshot 2025-11-06 at 7 27 11 PM"
src="https://github.com/user-attachments/assets/19e613c2-750f-45dc-b039-14d09869c179"
/>
https://ge.solutions-team.gradle.com/c/bqcqtwslzi3qi/rahbyjqxwfszm/task-inputs?task-text=compileDebugJavaWithJavac1 parent 8e3227a commit d88cedb
1 file changed
Lines changed: 5 additions & 0 deletions
Lines changed: 5 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
72 | 72 | | |
73 | 73 | | |
74 | 74 | | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
75 | 80 | | |
76 | 81 | | |
77 | 82 | | |
| |||
0 commit comments