Jeff Lockhart
05/22/2023, 5:32 AMAdhocComponentWithVariants.addVariantsFromConfiguration()
as documented here. I'm able to do this in a Java module by casting components["java"] as AdhocComponentWithVariants
. But in the Android module, the component cast fails. The component is this anonymous type instead: org.jetbrains.kotlin.gradle.plugin.mpp.AbstractKotlinTarget$buildAdhocComponentsFromKotlinVariants$1$2
. I tested with AGP versions back to 7.0.4 and found the cast succeeds in this version, but with AGP 7.1-8.2 it fails. I'm assuming AGP switched to Kotlin or something changed at that time. Would it make sense for the component to simply implement by delegation AdhocComponentWithVariants by adhocVariant
to provide access to this API as documented by Gradle?Vampire
05/22/2023, 6:56 AMTo utilise these methods, you must make sure that the SoftwareComponent you work with is itself an AdhocComponentWithVariants, which is the case for the components created by the Java plugins (Java, Java Library, Java Platform).
So yeah, it seems AGP is not compatible to this anymore. You would need to ask the AGP developers whether they could support it again or not. And in the meantime I guess you just need to declare an own component like described lower on that page.
Jeff Lockhart
05/22/2023, 2:26 PMVampire
05/22/2023, 2:33 PMVampire
05/22/2023, 2:34 PMJeff Lockhart
05/22/2023, 2:41 PMtapchicoma
05/22/2023, 4:14 PMJeff Lockhart
05/22/2023, 4:23 PMJeff Lockhart
05/22/2023, 4:50 PMAdhocComponentWithVariants
captured variable reference via reflection does seem to work to do exactly what I need.
def adhocField = components.release.class.getDeclaredFields()
.find { it.getType() == AdhocComponentWithVariants }
adhocField.setAccessible(true)
AdhocComponentWithVariants adhocComponent = adhocField.get(components.release)
adhocComponent.addVariantsFromConfiguration(...) {
...
Jeff Lockhart
05/22/2023, 8:18 PMhfhbd
05/23/2023, 6:17 AMafterEvaluate
a lot, and configuring kotlin compile tasks is almost impossible, at least I failed. And docs are rare.tapchicoma
05/23/2023, 6:52 AMafterEvaluate
- better to open issues in Google issuetracker