Fixed
Status Update
Comments
ga...@google.com <ga...@google.com> #2
Here is a workaround:
abstract class VersionFileWriterTask extends DefaultTask {
@OutputFile
abstract RegularFileProperty getOutputFile();
@TaskAction
void run() {
getOutputFile().get().asFile.write("foo bar this is created")
}
}
import com.android.build.api.artifact.SingleArtifact
abstract class UpdateArtifactTask extends DefaultTask {
@InputFiles
abstract RegularFileProperty getInitialArtifact()
@InputFile
abstract RegularFileProperty getVersionFile()
@OutputFile
abstract RegularFileProperty getUpdatedArtifact()
@TaskAction
void taskAction() {
// modify AAR by copying all entires, and adding resource to classes.jar entry
getUpdatedArtifact().get().asFile.write("foo bar")
}
}
def writeVersionFile = tasks.register("writeVersionFile", VersionFileWriterTask.class) {
it.getOutputFile().fileValue(new File("build/version.txt"))
}
androidComponents {
onVariants(selector().all(), { variant ->
def aarUpdates = tasks.register("updateAar${variant.name}", UpdateArtifactTask.class) {
it.getVersionFile().set(writeVersionFile.flatMap { t -> t.getOutputFile()})
}
variant.artifacts.use(aarUpdates)
.wiredWithFiles(
{ UpdateArtifactTask t -> t.getInitialArtifact()},
{ UpdateArtifactTask t -> t.getUpdatedArtifact()})
.toTransform(SingleArtifact.AAR.INSTANCE)
})
}
ga...@google.com <ga...@google.com> #3
The issue is in
override fun asFileTree(
fileTreeCreator: () -> ConfigurableFileTree,
): Provider<List<ConfigurableFileTree>> =
directoryProvider.map {
listOf(fileTreeCreator().setDir(directoryProvider).builtBy(directoryProvider))
}
Inner .map
captures fileTreeCreator()
with this
pointing to AGP global objects.
Rewriting it to:
override fun asFileTree(
fileTreeCreator: () -> ConfigurableFileTree,
): Provider<List<ConfigurableFileTree>> {
val fileTre = fileTreeCreator().setDir(directoryProvider).builtBy(directoryProvider)
return directoryProvider.map {
listOf(fileTre)
}
}
which is also lazy, fixes the issue.
ga...@google.com <ga...@google.com> #4
This should be fixed in AGP 8.0.0-beta01
and 8.1.0-alpha01
.
Fixed in change-id: I92dbae7099b0bacea675527d247dd8da77ec326c
.
sa...@google.com <sa...@google.com> #5
Thank you for your patience while our engineering team worked to resolve this issue. A fix for this issue is now available in:
- Android Studio Giraffe Canary 1 (2022.3.1.1)
- Android Gradle Plugin 8.1.0
We encourage you to try the latest update.
If you notice further issues or have questions, please file a new bug report.
Thank you for taking the time to submit feedback — we really appreciate it!
Description
AGP: 8.0.0-alpha10
Using the snippet below:
and running
./gradlew :library:assembleDebug --configuration-cache
fails withAdding to
variant.sources.java
instead ofvariant.sources.resources
fixes the issue.