Assigned
Status Update
Comments
pa...@gmail.com <pa...@gmail.com> #2
We are currently using AGP internal task types to flag memory-intensive tasks to enforce a reduced parallelism at execution time. I've raised this separately (with a lot more detail) as a feature request (
Description
I wrote a plugin that generates a wrapper around string resources, so I had a mockable class while still being able to use string resources in viewModels etc.
The way I did this before was to add a dependency on the process<...>Resources task, find the R.jar file, unzip and use a class visitor to extract the string/plural names. Then use codegen to create the wrapper with this data. Then I had to add my task as a dependency on compile<...>Kotlin.
It's taken me a while to get to grips with the new system, just trying to slot my task to run at the correct time, but I've ended up with something like the following:
project.plugins.withType(AppPlugin::class.java) {
val androidComponents = project.extensions.getByType(AndroidComponentsExtension::class.java)
androidComponents.onVariants { variant ->
variant.sources.java?.let { sources ->
val generateStringsTask = project.tasks.register(
"generate${
GenerateVariantStringsTask::class.java,
) {
it.variantPackageName.set(variant.namespace)
it.outputDir.set(project.layout.buildDirectory.dir("generated/source/stringrepository/${
}
variant.artifacts
.use(generateStringsTask)
.wiredWith(GenerateVariantStringsTask::symbolsFile)
.toListenTo(SingleArtifact.RUNTIME_SYMBOL_LIST)
sources.addGeneratedSourceDirectory(
generateStringsTask,
GenerateVariantStringsTask::outputDir
)
}
}
}
I'll admit, this new way is a hell of a lot easier to get the data I need, The problem is that the amount of exposed artifacts is pretty limited (at least compared to what I've seen for InternalArtifactType).
RUNTIME_SYMBOL_LIST includes transitive dependencies, breaking my generated code as the module's R class can no longer 'see' those transitive resources (with the default APG 8+ non transitive R class setting).
Ideally having a non-transitive version of that artifact (to the local_only_symbol_list file?) would be perfect, but considering my confusing on picking up these new APIs there's a good chance i'm wrong on approach for this.
Any guidance would be very much appreciated.
Thanks