Status Update
Comments
ra...@google.com <ra...@google.com>
ga...@google.com <ga...@google.com> #2
Hung, can you please take a look?
hu...@google.com <hu...@google.com> #4
Adding a bit more details on this error Cannot query the value of this property because it has no value available
.
Root cause
This could happen when a task is configured to consume artifact Foo
but the artifact is not produced.
Gradle has different behaviors when a task consumes a non-existent
artifact set up via ConfigurableFileCollection
(adding @Optional
on the ConfigurableFileCollection
doesn't make a difference):
ConfigurableFileCollection.from(null)
=> OKConfigurableFileCollection.from(Callable { null })
=> OKConfigurableFileCollection.from(task.project.provider { null })
=> Fails with the following message:
Could not determine the dependencies of task '<task>'.
> Cannot query the value of this property because it has no value available.
We could argue that this is a Gradle bug because the behaviors are not consistent. However, we could also argue that this is not a Gradle bug because providing null
will lead to undefined behavior.
Identifying the Problematic Task Input
The first step in fixing this issue is to find out the task input where this issue occurs, but Gradle doesn't provide that info in the error message. So I had to do the following:
- Build Gradle from source, and run the build with the gradle binary built from source instead of
./gradlew
. Then put a breakpoint in the Gradle source code where the error is thrown. Once the breakpoint is hit, look around and see if we can gather any info. Gradle normally stores names of non-file properties; if it is a file property, as in this bug, we might not find anything useful. In this case, I had to try step 2. - Incrementally remove properties from the task (or mark them as
@Internal
) and rebuild the project until we can track down the problematic property.
Fix
There are a few options:
- [Recommended] Consume the artifact under the same condition under which it is produced.
val artifactFoo: Provider<RegularFile> = getArtifactFoo()
task.configurableFileCollection.from(
artifactFoo.takeIf { conditionThatArtifactFooIsProduced() }
}
- Check if the artifact is produced before consuming it.
val artifactFoo: Provider<RegularFile> = getArtifactFoo()
task.configurableFileCollection.from(Callable {
// The `Provider.isPresent` check needs to happen lazily when all
// producers/consumers have been finalized, so we do this inside a Callable.
artifactFoo.takeIf { it.isPresent }
}
- Don't use
ConfigurableFileCollection
(@Optional ListProperty<RegularFile>
also doesn't work), use@Optional RegularFileProperty
for justartifactFoo
instead. (And if there are more artifacts than justartifactFoo
, create separate inputs and combine them later in the task action.)
(In the above fix, we used option 2 because with option 1, for this particular bug, the condition is not easily identified.)
an...@google.com <an...@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 Jellyfish | 2023.3.1 Canary 5
- Android Gradle Plugin 8.4.0-alpha05
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
Build fails when R8 is enabled on a library module and
android.library.defaults.buildfeatures.androidresources
is set to false.Steps to reproduce:
mylibrary
android.library.defaults.buildfeatures.androidresources=false
to gradle.properties./gradlew :mylibrary:minifyReleaseWithR8
Build will fail with the following error:
Reproducable on Android Gradle Plugin versions 8.2.1, 8.3.0-beta01 and 8.4.0-alpha03.
System information: